induwara.lk
Real XeTeX engine · nothing to install

Online LaTeX Editor and Compiler with Live Preview

Write LaTeX on the left and watch the PDF build on the right. This is a real XeLaTeX compiler running on the server, not a browser approximation, so what you see is what you would get from a full TeX installation. No account, no install, and your document is never stored.

Compiles in about a second ~210 packages ready Nothing saved on the server
my-first-latex-document.tex59 lines · 1,740 chars
Preview

The compiled PDF appears here. Press Ctrl + Enter to build.

ReadyCtrl/⌘ + Enter compiles · Tab indents · autosaved in this browser only

How it works

When a compile fires, the text in the editor is posted to this site's compile endpoint and written into a throwaway directory inside a sandbox. Tectonic 0.17.0 runs XeLaTeX over it, xdvipdfmx turns the result into a PDF, and that PDF comes back in the response and is displayed from an in-memory blob URL in your browser. A warm one- or two-page document usually finishes in well under a second. The working directory is removed when the run ends — in a finally block, so it happens on the failure and timeout paths too, not just the happy one.

The engine matters more than most online editors admit. Tectonic drives the XeTeX engine, which reads UTF-8 directly and can load OpenType fonts through fontspec — so you do not need \usepackage[utf8]{inputenc}, and accented characters, dashes and symbols pasted straight from a word processor typeset correctly. It also reruns TeX until the .auxfile stops changing and runs BibTeX when a bibliography needs it, so the usual “compile it twice for the cross-references, three times with citations” ritual is handled for you. Numbers, references and a table of contents are right on the first build.

Around 210 packages are pre-cached, covering the AMS maths stack, geometry, fancyhdr, titlesec, booktabs, tabularx, longtable, enumitem, hyperref, graphicx, TikZ, pgfplots, listings, siunitx and more. The sandbox has no network access, which is deliberate: a package that is not cached cannot be fetched mid-compile, so instead of a request that hangs while something downloads in the background, you get an immediate File `x.sty' not found that tells you exactly what is missing. Seven document classes are available — article, extarticle, report, book, letter, beamer and moderncv.

Isolation is what makes running arbitrary LaTeX safe. Each compile happens with the network unshared, the environment cleared, a read-only filesystem, and hard limits on CPU, memory and wall-clock time. \write18 — LaTeX's ability to run shell commands — is switched off, which is why mintedand other shell-escape packages cannot work here. Nothing about your document is persisted: no database row, no file left behind, no analytics on the content, and the response carries a no-store header. The autosave that survives a refresh is your browser's own local storage, on your device, and the Clear button in the editor removes it.

What this compiler can and cannot do

  • The engine is XeLaTeX (XeTeX), driven by Tectonic 0.17.0 and written out by xdvipdfmx. UTF-8 input works without \usepackage[utf8]{inputenc}.
  • The sandbox has no network. Only packages already in the local cache load — an unknown package is an immediate, clear failure rather than a silent download.
  • Shell-escape (\write18) is disabled, so minted, pygmentize-based highlighting and on-the-fly image conversion cannot run. Use listings instead.
  • You submit one .tex file. There is no way to upload an image or a .bib, but filecontents can embed a .bib and TikZ can draw figures from source.
  • A run is stopped after 30 seconds of wall clock or 15 seconds of CPU, and is capped at 1024 MB of memory.
  • Documents are capped at 200,000 characters and 30 compiles per 5 minutes per address.
  • Nothing is stored. The source lives in the request, the working directory is deleted when the run ends, and the PDF is returned in the response and never written anywhere else.
  • fontspec resolves fonts by file name, not family name — \setmainfont{Times New Roman} fails because the sandbox has no system font directory to search. Latin Modern comes with the engine, and Liberation Serif and Liberation Sans (metric-compatible with Times New Roman and Arial) ride along with every compile in fonts/.

Supported packages and document classes

Every name below was verified by compiling a document that loads it with the network switched off. If a package you need is missing, there is usually a cached one that does the same job.

Maths

The AMS stack plus the usual extras.

amsmathamssymbamsfontsamsthmmathtoolssiunitxunicode-math

Layout and page setup

Margins, headings, headers, spacing, columns.

geometryfancyhdrtitlesecsetspaceparskipmulticolparacolchangepagelastpagelscapeafterpage

Tables

Rules, spanning cells, page breaks and full-width layouts.

booktabsarraytabularxlongtablemultirowmakecellcolortblthreeparttablearydshlnrotating

Graphics and drawing

TikZ and pgfplots draw from source, so nothing needs uploading.

graphicxtikzpgfpgfplotsxcolortcolorboxfloatwrapfigsubcaptioncaption

Lists, text and references

Spacing control, links, cross-references, quotation handling.

enumitemhyperrefcleverefurlcsquotesulemsoulmicrotyperagged2ehyphenat

Code, algorithms and bibliography

listings needs no external highlighter. BibTeX runs; biblatex/biber cannot.

listingsverbatimalgorithmalgpseudocodenatbiblipsumblindtext

Fonts and encoding

XeTeX reads UTF-8 directly; fontspec loads OpenType faces by filename.

fontspecfontenctextcomplmodernlatotgpagellafontawesome5academiconseurosym

Document classes

article
Reports, papers, assignments, letters. The default choice.
extarticle
article with 8pt, 9pt, 14pt, 17pt and 20pt sizes available.
report
Longer work that needs \chapter — dissertations, project reports.
book
Two-sided layout with front matter, main matter and back matter.
letter
The classic letter class with \opening, \closing and \signature.
beamer
Presentation slides. \begin{frame} per slide; themes such as Madrid work.
moderncv
The moderncv CV class, banking style with the blue colour theme.

Anything else — memoir, scrartcl, journal-specific classes — fails with “File not found”, because the class file is not in the cache and cannot be downloaded during a compile.

LaTeX quick reference

The commands people actually reach for, each with a snippet you can drop straight into the editor above. “Insert in editor” places it at your cursor; if you have not clicked into the editor yet, it lands just before \end{document}.

Document structure

Every LaTeX file is a preamble (class, packages, settings) followed by the document body. Nothing outside \begin{document}…\end{document} is printed.

Smallest document that compiles

\documentclass{article}
\begin{document}
Hello, world.
\end{document}

If a document fails, cut it back to this and add lines until it breaks again — it isolates the culprit in about a minute.

A working preamble

\documentclass[11pt,a4paper]{article}

\usepackage[margin=2.5cm]{geometry}  % page margins
\usepackage{amsmath,amssymb}         % maths
\usepackage{graphicx}                % \includegraphics, \scalebox
\usepackage{booktabs}                % proper table rules
\usepackage{enumitem}                % list spacing control
\usepackage{hyperref}                % clickable links and references

Load hyperref last — it patches other packages' internals, so it has to see them first. cleveref is the one exception that goes after it.

Title block and table of contents

% In the preamble:
\title{Comparative Study of Sorting Algorithms}
\author{A. Perera \\ University of Colombo}
\date{\today}

% Just after the document begins:
\maketitle
\tableofcontents
\newpage

\maketitle prints nothing unless \title is set. \date{} (empty braces) removes the date entirely; leaving \date out altogether prints today's date.

Headings

\section{Top level}
\subsection{Second level}
\subsubsection{Third level}
\paragraph{Run-in heading} Text starts on the same line.

\section*{Unnumbered}   % starred = no number, not in the contents

article stops at \subsubsection. Use report or book if you need \chapter.

Breaks and blank space

First paragraph.

Second paragraph — a blank line is what starts one.

Force a line break: \\
Force a page break: \newpage
Vertical gap: \vspace{1cm}
Horizontal gap: \hspace{2em}

Two blank lines are the same as one; LaTeX collapses them. Never use \\ to make paragraph spacing.

Text formatting

Font switches are commands that take the text as an argument. XeTeX means UTF-8 input just works — you can paste accented characters straight in.

Bold, italic, monospace

\textbf{bold}  \textit{italic}  \emph{emphasis}
\texttt{monospace}  \textsc{Small Caps}  \underline{underlined}
\textbf{\textit{bold italic}}

Prefer \emph over \textit: it flips to upright inside already-italic text, which is what emphasis is supposed to do.

Font sizes

{\tiny tiny} {\small small} {\normalsize normal}
{\large large} {\Large Large} {\LARGE LARGE} {\huge huge}

These are switches, not commands with arguments — wrap them in braces or everything after them changes size.

Characters LaTeX reserves

\% \$ \& \# \_ \{ \}
\textbackslash        % a literal backslash — NOT \\
\textasciitilde{} \textasciicircum{}

% $ & # _ { } ~ ^ \ all mean something to LaTeX. An unescaped % silently comments out the rest of the line — the single most common cause of 'my text vanished'.

Quotation marks and dashes

``double quoted'' and `single quoted'
hyphen - , en-dash -- (ranges: 10--15), em-dash --- (an aside)
Ellipsis: \ldots

Straight " quotes typeset as two right-hand marks. Use two backticks to open and two apostrophes to close.

Changing the font

\usepackage{fontspec}

% Fonts resolve by FILE NAME here, not by family name — the sandbox
% has no system font directory for \setmainfont{Times New Roman} to search.

% Latin Modern, shipped with the engine:
\setmainfont{lmroman10-regular.otf}[
  BoldFont       = lmroman10-bold.otf,
  ItalicFont     = lmroman10-italic.otf,
  BoldItalicFont = lmroman10-bolditalic.otf]

% Liberation Sans, which rides along with every compile in fonts/:
\setsansfont{LiberationSans}[
  Path        = fonts/,
  Extension   = .ttf,
  UprightFont = *-Regular, BoldFont = *-Bold, ItalicFont = *-Italic]

Liberation Sans and Liberation Serif are metric-compatible with Arial and Times New Roman, so a document set in them prints at the same length as one set in the Microsoft originals.

Alignment and quotations

\begin{center}   Centred    \end{center}
\begin{flushleft} Left       \end{flushleft}
\begin{flushright}Right      \end{flushright}

\begin{quote}
A short indented quotation.
\end{quote}

Lists

Three built-in list environments, all nestable up to four deep. enumitem gives you the spacing and label control the defaults lack.

Bulleted and numbered

\begin{itemize}
  \item First point
  \item Second point
\end{itemize}

\begin{enumerate}
  \item Step one
  \item Step two
\end{enumerate}

Description list

\begin{description}
  \item[TeX] Knuth's typesetting engine, 1978.
  \item[LaTeX] Lamport's macro layer on top of it, 1984.
\end{description}

The bracketed text is the bold term. This is the right environment for glossaries and API parameter lists.

Nesting

\begin{enumerate}
  \item Outer
  \begin{itemize}
    \item Inner bullet
    \item Another
  \end{itemize}
  \item Back to outer
\end{enumerate}

Numbering and bullet shapes change automatically per level — don't set them by hand.

Tighter lists and custom labels (enumitem)

\usepackage{enumitem}

\begin{itemize}[noitemsep, topsep=0pt, leftmargin=*]
  \item No extra space between items
\end{itemize}

\begin{enumerate}[label=(\alph*)]
  \item becomes (a)
  \item becomes (b)
\end{enumerate}

label=(\alph*) / (\roman*) / (\Alph*) covers almost every numbering scheme a report asks for.

Mathematics

Maths is why most people reach for LaTeX. Load amsmath and amssymb; nearly every example below needs one of them.

Inline vs display

Inline maths sits in the sentence: $a^2 + b^2 = c^2$.

Unnumbered display:
\[ a^2 + b^2 = c^2 \]

Numbered display:
\begin{equation}
  a^2 + b^2 = c^2
\end{equation}

Use \[ … \] rather than $$ … $$. The double-dollar form is plain TeX and gets vertical spacing wrong under LaTeX.

Fractions, roots, sub- and superscripts

$x^2$  $x_i$  $x_{i+1}^{2n}$
$\frac{a}{b}$  $\tfrac{1}{2}$  $\dfrac{a}{b}$
$\sqrt{x}$  $\sqrt[3]{x}$
$\sum_{i=1}^{n} i = \frac{n(n+1)}{2}$
$\int_{0}^{\infty} e^{-x}\,\mathrm{d}x = 1$
$\lim_{n \to \infty} \frac{1}{n} = 0$

Braces group more than one character: x^2n is x²n, x^{2n} is x²ⁿ.

Multi-line derivations

\begin{align}
  (a+b)^2 &= (a+b)(a+b) \\
          &= a^2 + 2ab + b^2
\end{align}

\begin{align*}   % starred = no equation numbers
  f(x) &= 3x + 1
\end{align*}

The & marks the alignment column — put it just before the = on every line.

Common symbols

$\alpha \beta \gamma \delta \theta \lambda \mu \pi \sigma \phi \omega$
$\Gamma \Delta \Theta \Lambda \Sigma \Phi \Omega$
$\leq \geq \neq \approx \equiv \sim \propto \pm \times \div \cdot$
$\in \notin \subset \subseteq \cup \cap \emptyset \forall \exists$
$\to \Rightarrow \Leftrightarrow \mapsto \infty \partial \nabla$

Every one of these is maths-mode only, which is why they are wrapped in dollars here. Outside maths mode you get 'Missing $ inserted'.

Matrices and cases

\[
\begin{pmatrix} a & b \\ c & d \end{pmatrix}
\quad
\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}
\]

\[
f(x) =
\begin{cases}
  x^2  & \text{if } x \geq 0 \\
  -x^2 & \text{otherwise}
\end{cases}
\]

pmatrix = round brackets, bmatrix = square, vmatrix = determinant bars. \text{} is how you put words inside maths.

Maths fonts and operators

$\mathbb{R}$ $\mathbb{N}$   % blackboard bold (amssymb)
$\mathcal{L}$              % calligraphic
$\mathbf{v}$ $\mathrm{d}x$ % upright bold / upright roman
$\sin x$ $\log n$ $\max_i$ % predefined operators, upright and spaced
$\operatorname{argmax}_x$  % your own operator (amsmath)

Tables

tabular builds the grid; table wraps it in a float so it can carry a caption and be referenced. They are two separate jobs and you usually want both.

Basic tabular

\begin{tabular}{l c r}
  Left & Centre & Right \\
  a    & b      & c     \\
\end{tabular}

One letter per column: l, c, r for alignment, p{4cm} for a wrapping paragraph column, | for a vertical rule.

Publication-quality rules (booktabs)

\usepackage{booktabs}

\begin{tabular}{lrr}
  \toprule
  Item     & Qty & Price \\
  \midrule
  Notebook &   2 &   850 \\
  Pen      &  10 &    60 \\
  \bottomrule
\end{tabular}

booktabs deliberately offers no vertical rules — journals reject them. Three horizontal rules is the house style of nearly every publisher.

Table float with caption and label

\begin{table}[h]
  \centering
  \begin{tabular}{lr}
    \toprule
    Metric & Value \\
    \midrule
    Precision & 0.91 \\
    Recall    & 0.87 \\
    \bottomrule
  \end{tabular}
  \caption{Model performance on the held-out set.}
  \label{tab:perf}
\end{table}

Results are in Table~\ref{tab:perf}.

\caption must come inside the float, and \label must come after \caption or the reference points at the wrong number.

Merged cells and full-width tables

\usepackage{multirow}
\usepackage{tabularx}

\begin{tabular}{lcc}
  \multicolumn{3}{c}{Spans three columns} \\
  \multirow{2}{*}{Spans two rows} & a & b \\
                                  & c & d \\
\end{tabular}

\begin{tabularx}{\textwidth}{lX}
  Term & X stretches to fill the line width \\
\end{tabularx}

Tables that break across pages

\usepackage{longtable}

\begin{longtable}{lr}
  \toprule
  Name & Score \\
  \midrule
  \endhead
  Row & 1 \\
  % … hundreds of rows …
  \bottomrule
\end{longtable}

A normal tabular inside a table float cannot break across pages — it will overflow silently. longtable is the fix, and it is not a float.

Figures and drawings

You cannot upload an image file to this playground, so \includegraphics has nothing to point at. Draw with TikZ instead — it is compiled from your source, needs no upload, and scales perfectly.

A figure drawn with TikZ

\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning, shapes.geometric}

\begin{figure}[h]
  \centering
  \begin{tikzpicture}[node distance=2.5cm]
    \node[draw, rounded corners] (client) {Client};
    \node[draw, rounded corners, right=of client] (api) {API};
    \node[draw, cylinder, shape aspect=0.3, right=of api] (db) {DB};
    \draw[-Stealth] (client) -- (api);
    \draw[-Stealth] (api) -- (db);
  \end{tikzpicture}
  \caption{Request path.}
  \label{fig:arch}
\end{figure}

TikZ compiles a little slowly on a first run because it loads a large macro set; later compiles in the same session are quick.

A plotted function (pgfplots)

\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{tikzpicture}
  \begin{axis}[xlabel=$x$, ylabel=$y$, grid=major, width=9cm, height=6cm]
    \addplot[thick, domain=-3:3, samples=100] {x^2};
    \addlegendentry{$y = x^2$}
  \end{axis}
\end{tikzpicture}

pgfplots draws from a formula or from inline coordinates, so a chart needs no data file.

Including an image (works on your own machine)

\usepackage{graphicx}

\begin{figure}[h]
  \centering
  \includegraphics[width=0.8\textwidth]{diagram.png}
  \caption{An image loaded from a file next to the .tex.}
\end{figure}

The one snippet on this page that cannot run here — the sandbox has no diagram.png to find, so it stops with "File `diagram.png' not found". Copy it, download your .tex, and it works on any local TeX install.

Two figures side by side (subcaption)

\usepackage{subcaption}

\begin{figure}[h]
  \centering
  \begin{subfigure}{0.45\textwidth}
    \centering\rule{3cm}{2cm}
    \caption{Left}
  \end{subfigure}
  \hfill
  \begin{subfigure}{0.45\textwidth}
    \centering\rule{3cm}{2cm}
    \caption{Right}
  \end{subfigure}
  \caption{Two panels, numbered (a) and (b).}
\end{figure}

\rule{w}{h} draws a solid black box — handy as a stand-in while you lay a page out.

Cross-references, links and footnotes

Never type a figure or section number by hand. Label it, reference it, and every number stays correct when you reorder the document.

Label and reference

\section{Method}\label{sec:method}
As described in Section~\ref{sec:method} on page~\pageref{sec:method}.

\begin{equation}\label{eq:loss}
  L = \tfrac{1}{n}\sum_i (y_i - \hat{y}_i)^2
\end{equation}
Equation~\eqref{eq:loss} is minimised.

The ~ is a non-breaking space, so "Section" and its number never split across a line. \eqref adds the brackets for you.

Why references show as ??

% First pass writes the numbers to the .aux file,
% second pass reads them back. Tectonic reruns automatically,
% so ?? here means the label is missing or misspelt —
% not that you need another compile.
\label{fig:results}   % definition
\ref{fig:results}     % use — must match exactly, case sensitive

Hyperlinks

\usepackage{hyperref}

\href{https://induwara.lk}{clickable text}
\url{https://induwara.lk/tools}
\texttt{[email protected]}  % \href{mailto:[email protected]}{...} to make it clickable

\hypersetup{colorlinks=true, linkcolor=blue, urlcolor=blue}

Without \hypersetup, hyperref boxes links in coloured rules that look wrong in print. colorlinks=true is what almost everyone wants.

Footnotes and margin notes

Ordinary text.\footnote{The note appears at the bottom of the page.}

\footnotetext[3]{Manually numbered note.}

Citations and bibliography

This playground compiles one file, so there is no separate .bib to upload — but filecontents lets you embed one, and BibTeX then runs exactly as it would locally. biblatex does not work here; BibTeX does.

Manual bibliography (no BibTeX needed)

Knuth introduced literate programming~\cite{knuth1984}.

\begin{thebibliography}{9}
  \bibitem{knuth1984}
  D.~E. Knuth, ``Literate Programming'',
  \emph{The Computer Journal}, vol.~27, pp.~97--111, 1984.
\end{thebibliography}

The {9} is just the widest label you expect — it sets the indent, nothing else.

Real BibTeX in a single file (filecontents)

\documentclass[11pt,a4paper]{article}
\begin{filecontents}{refs.bib}
@article{knuth1984,
  author  = {Donald E. Knuth},
  title   = {Literate Programming},
  journal = {The Computer Journal},
  year    = {1984},
  volume  = {27},
  pages   = {97--111}
}
\end{filecontents}
\begin{document}
Knuth says so~\cite{knuth1984}.
\bibliographystyle{plain}
\bibliography{refs}
\end{document}

filecontents writes the .bib into the working directory before the run, so BibTeX finds it. Verified working here — styles plain, unsrt, abbrv, alpha, apalike, ieeetr, acm, siam and plainnat are all cached.

Author-year citations (natbib)

\usepackage{natbib}
\bibliographystyle{plainnat}

\citet{knuth1984} argued …      % Knuth (1984) argued
… as argued \citep{knuth1984}.  % … (Knuth, 1984).

Use BibTeX, not biblatex. biblatex needs style files that are not in the cache and a biber run that cannot happen here, so it fails outright — \bibliographystyle plus \bibliography is the combination that works.

Code listings

Two options: verbatim for a plain block, listings for syntax highlighting. minted cannot work here — it shells out to Pygments and shell-escape is disabled.

Plain verbatim

\begin{verbatim}
def add(a, b):
    return a + b
\end{verbatim}

Inline: \verb|no escaping needed inside|

Everything inside is printed exactly, backslashes and all — so this is also the escape hatch when you need to show LaTeX source.

Highlighted listing (listings)

\usepackage{listings}
\usepackage{xcolor}

\lstset{
  basicstyle=\ttfamily\small,
  keywordstyle=\color{blue!70!black},
  commentstyle=\color{gray},
  stringstyle=\color{green!45!black},
  numbers=left, numberstyle=\tiny, frame=single,
  breaklines=true, showstringspaces=false
}

\begin{lstlisting}[language=Python, caption={Adding two numbers}]
def add(a, b):
    """Return the sum."""
    return a + b
\end{lstlisting}

listings knows Python, C, C++, Java, SQL, HTML, Bash and dozens more out of the box — no external highlighter involved.

Page layout

Margins, headers, line spacing and columns. Set these once in the preamble rather than nudging individual pages.

Margins and paper (geometry)

\usepackage[a4paper, margin=2.5cm]{geometry}

% or per-edge:
\usepackage[a4paper, top=3cm, bottom=2.5cm, left=3cm, right=2cm]{geometry}

% landscape:
\usepackage[a4paper, landscape, margin=2cm]{geometry}

Headers and footers (fancyhdr)

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[L]{Project Report}
\fancyhead[R]{\leftmark}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0.4pt}

Line spacing and paragraph style

\usepackage{setspace}
\onehalfspacing        % or \doublespacing

\usepackage{parskip}   % blank line between paragraphs, no first-line indent
\setlength{\parindent}{0pt}   % the manual equivalent

Most universities ask for 1.5 spacing; setspace is the supported way to get it without breaking footnote and caption spacing.

Two columns

% Whole document — add the option to the class:
%   \documentclass[twocolumn]{article}

% Or just part of it:
\usepackage{multicol}
\begin{multicols}{2}
  Text flows down the first column and up the second.
\end{multicols}

Worked examples

Three complete documents, each verified against this compiler. Press “Open in editor” to load one in place of what is currently there.

1 · A university assignment cover page and first section

The layout most Sri Lankan university submissions ask for: a title block, a declaration, an automatic table of contents and a numbered first section.

\documentclass[12pt,a4paper]{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage{setspace}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{hyperref}
\hypersetup{colorlinks=true, linkcolor=black, urlcolor=blue}
\onehalfspacing

\title{\Large Comparative Study of Sorting Algorithms}
\author{A. Perera \\ Index No. 21001234 \\ University of Colombo School of Computing}
\date{\today}

\begin{document}
\maketitle
\thispagestyle{empty}

\begin{center}
  \textit{Submitted in partial fulfilment of the requirements for SCS2201.}
\end{center}

\newpage
\tableofcontents
\newpage

\section{Introduction}
This report compares three comparison sorts on the same input distribution.
The asymptotic cost of merge sort is $O(n \log n)$ in every case, while quick
sort degrades to $O(n^2)$ on already-sorted input.

\section{Results}
\begin{table}[h]
  \centering
  \begin{tabular}{lrr}
    \toprule
    Algorithm  & $n = 10^4$ (ms) & $n = 10^5$ (ms) \\
    \midrule
    Merge sort &            12.4 &           148.9 \\
    Quick sort &             9.1 &           121.3 \\
    Heap sort  &            15.7 &           192.6 \\
    \bottomrule
  \end{tabular}
  \caption{Mean runtime over 20 runs.}
  \label{tab:runtime}
\end{table}

Table~\ref{tab:runtime} shows quick sort ahead on random input.

\end{document}

Worth noting: \thispagestyle{empty} removes the page number from the cover only. \onehalfspacing satisfies the 1.5-spacing rule most handbooks impose without you touching \baselineskip.

2 · A maths problem set with aligned working

Numbered problems, a multi-line derivation that lines up on the equals signs, a piecewise definition and a matrix — the four things a maths sheet almost always needs.

\documentclass[11pt,a4paper]{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{enumitem}

\newtheorem{theorem}{Theorem}

\begin{document}

\section*{Problem Set 3}

\begin{enumerate}[leftmargin=*]

\item Expand $(a+b)^2$ from first principles.
\begin{align*}
  (a+b)^2 &= (a+b)(a+b) \\
          &= a^2 + ab + ba + b^2 \\
          &= a^2 + 2ab + b^2
\end{align*}

\item Define the ramp function.
\[
r(x) =
\begin{cases}
  x & \text{if } x \geq 0, \\
  0 & \text{otherwise.}
\end{cases}
\]

\item Show that the identity matrix is its own inverse.
\[
  I = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix},
  \qquad I \cdot I = I.
\]

\end{enumerate}

\begin{theorem}[Gauss]
  For every $n \in \mathbb{N}$, $\displaystyle\sum_{i=1}^{n} i = \frac{n(n+1)}{2}$.
\end{theorem}

\begin{proof}
  Pair the first and last terms: each of the $n/2$ pairs sums to $n+1$.
\end{proof}

\end{document}

Worth noting: align* aligns on the & and prints no equation numbers, which is what you want for working. \displaystyle forces full-size sums inside a paragraph.

3 · A one-page cover letter

Plain article class, no letter class needed — the layout is easier to control and it prints identically everywhere.

\documentclass[11pt,a4paper]{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage{parskip}
\usepackage{hyperref}
\hypersetup{colorlinks=true, urlcolor=blue}
\pagestyle{empty}

\begin{document}

{\Large\textbf{A. Perera}}\\
Ratnapura, Sri Lanka \\
\href{mailto:[email protected]}{[email protected]} $\cdot$ +94 77 000 0000

\vspace{1.5em}
\today

\vspace{1.5em}
Hiring Team \\
Example Technologies (Pvt) Ltd \\
Colombo 03

\vspace{1.5em}
Dear Hiring Team,

I am applying for the Junior Software Engineer role advertised on 24 July. I
finished my BSc in Computer Science at the University of Colombo this year and
spent the last six months building and maintaining a Next.js application that
now serves around 40{,}000 requests a day.

Three things I would bring on day one:

\begin{itemize}
  \item Production TypeScript and PostgreSQL, not just coursework.
  \item Experience owning a deployment end to end, including the on-call side.
  \item Written English good enough to keep your documentation honest.
\end{itemize}

I would welcome the chance to talk. My CV is attached.

\vspace{1.5em}
Yours sincerely, \\[2em]
A. Perera

\end{document}

Worth noting: 40{,}000 keeps the thousands separator from being typeset as punctuation with a space after it. \\[2em] adds signature space in a single break.

Common LaTeX errors and what they mean

TeX's error messages were written for people who wrote TeX. Here is what each one is actually telling you, and the fix.

! Undefined control sequence.

TeX met a command it has never been told about. Nine times out of ten it is a typo (\textbfx, \bein) or a command that belongs to a package you have not loaded — \toprule needs booktabs, \includegraphics needs graphicx, \mathbb needs amssymb.

Fix: Read the line number in the log, then check two things in order: the spelling, and whether the command's package is in your preamble.

Breaks
\documentclass{article}
\begin{document}
$\mathbb{R}$ is the reals.   % \mathbb comes from amssymb
\end{document}
Works
\documentclass{article}
\usepackage{amssymb}
\begin{document}
$\mathbb{R}$ is the reals.
\end{document}

! Missing $ inserted.

A maths-only character appeared in ordinary text. _ and ^ are the usual suspects — an underscore in a filename or variable name is read as a subscript request, and subscripts only exist in maths mode.

Fix: Escape it (\_) if you want the character printed, or wrap the expression in $ … $ if you meant maths.

Breaks
The file user_data.csv has 3 columns.
Works
The file user\_data.csv has 3 columns.
% or, if it is code: \texttt{user\_data.csv}

! LaTeX Error: File `xyz.sty' not found.

The package is not in this compiler's cache. The sandbox has no network, so nothing can be downloaded mid-compile — an unknown package is a hard stop rather than a pause.

Fix: Check the supported-package list on this page. If a package is missing, there is usually a cached one that does the same job (tabularx for tabu, booktabs for hand-drawn rules, listings for minted).

! LaTeX Error: File `diagram.png' not found.

\includegraphics is pointing at an image that does not exist in the compile directory. In this playground it never can: you submit one .tex file and nothing else.

Fix: Draw the figure with TikZ or pgfplots so it lives in the source, or download the .tex and compile it locally next to your image.

Runaway argument? / ! Paragraph ended before \… was complete.

A command's argument was never closed, so TeX kept swallowing text looking for the closing brace and hit a blank line first. Usually a missing } — occasionally a stray blank line inside a command that does not allow one.

Fix: Go to the reported line and count braces. Most editors, including this one, will show you the mismatch if you place the cursor next to a brace.

Breaks
\textbf{This bold run is never closed

and the next paragraph starts here.
Works
\textbf{This bold run is closed}

and the next paragraph starts here.

! LaTeX Error: \begin{itemize} on input line 12 ended by \end{document}.

An environment was opened and never closed. LaTeX only notices at the very end of the file, which is why the reported line is \end{document} rather than the real culprit — the useful number is the 'on input line' one.

Fix: Every \begin{x} needs a matching \end{x}, and they must nest, not overlap. This editor writes the \end for you when you press Enter after a \begin line.

! LaTeX Error: Missing \begin{document}.

Printable text appeared in the preamble — before \begin{document}. Often a stray character, or a whole document pasted in above the class declaration.

Fix: The preamble may only contain \documentclass, \usepackage, definitions and settings. Anything you want printed goes after \begin{document}.

! LaTeX Error: Something's wrong--perhaps a missing \item.

Text appeared inside a list environment before the first \item. Every line inside itemize, enumerate or description has to belong to an item.

Fix: Add the missing \item, or move the introductory sentence above \begin{itemize}.

Breaks
\begin{itemize}
Here are the reasons:
  \item First
\end{itemize}
Works
Here are the reasons:
\begin{itemize}
  \item First
\end{itemize}

! Extra alignment tab has been changed to \cr.

A table row has more & separators than the column specification allows. \begin{tabular}{lr} declares two columns, so each row may contain exactly one &.

Fix: Count the letters in the column spec, count the & in the offending row, and make them agree — or use \multicolumn to deliberately span.

Breaks
\begin{tabular}{lr}
  A & B & C \\
\end{tabular}
Works
\begin{tabular}{lrr}
  A & B & C \\
\end{tabular}

! Misplaced alignment tab character &.

An & appeared outside a table or align environment. In ordinary text & is a reserved character, not an ampersand.

Fix: Write \& to print a literal ampersand.

Overfull \hbox (12.3pt too wide) in paragraph at lines 40--42

A warning, not an error — the PDF is still produced. Something could not be broken to fit the text width: a long URL, a wide table, or a code line.

Fix: For URLs, load hyperref (it breaks them) or \usepackage{url}. For tables, switch to tabularx. For code, set breaklines=true in \lstset. Ignoring it is fine if nothing visibly runs into the margin.

The document took too long to compile and was stopped.

The run hit the 30-second wall clock or the 15-second CPU budget. Almost always an unterminated environment or a macro that expands into itself, so TeX loops instead of finishing.

Fix: Look for a missing \end{...} first. If the document is genuinely large — hundreds of pages, or a TikZ picture with thousands of paths — split it and compile the parts.

Editor shortcuts

Ctrl / ⌘ + Enter
Compile now
Ctrl / ⌘ + S
Save to this browser and compile
Tab / Shift + Tab
Indent or outdent (two spaces, works on a selection)
Ctrl / ⌘ + B
Wrap the selection in \textbf{ }
Ctrl / ⌘ + I
Wrap the selection in \emph{ }
Enter after \begin{x}
Writes the matching \end{x} for you

Frequently asked questions

Related tools

By Induwara Ashinsana Last updated: 2026-07-30

Compiler: Tectonic 0.17.0 driving XeTeX, sandboxed with no network access. Package availability, document classes and every snippet on this page were verified against that compiler on 2026-07-30. Limits: 200,000 characters per document, 30 compiles every 5 minutes, and 30 seconds per run.

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.