If LaTeX runs into code it doesn’t understand it will stop typesetting and will give information about the error. It can also output warnings.

Errors

If TeXworks encounters an error it will show a message in the console and wait. Such a message looks like

! Undefined control sequence.
l.6 \authr

It starts with an exclamation mark and a description of the error (Undefined control sequence), followed by the line number (6) and the command where the error occured (\authr). Watch out: the line number that is displayed doesn’t have to be the location where the error in your code was made. For example, if you forget a } then LaTeX will probably find out at the end of a paragraph. When an error is encountered you can stop typesetting and fix it. Alternatively, there are ways to surpress errors, but we recommend that you always fix your errors. If you don’t do this, it is possible that the errors stack up and the output is not as desired.

We will now discuss some errors that occur very often.

Too many }’s

! Too many }'s.
l.6 \date December 2004}

There is a } without a matching {. In this case we forgot { after \date.

Undefined control sequence

! Undefined control sequence.
l.6 \dtae
{December 2004}

An unknown command was used, here \dtae, which should have been \date.

Missing $ inserted

! Missing $ inserted.
<inserted text>
$
l.6 \alpha

A math command was used in text mode, in this case \alpha.

Runaway argument

Runaway argument?
{December 2004 \maketitle
! Paragraph ended before \date was complete.
<to be read again>
\par
l.8

In this example we forgot the } belonging to the \date command.

Missing package

! LaTeX Error: File `babl.sty' not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)
Enter file name:

Here we misspelled babel. It could also happen that the name is correct but the package is not installed yet. Packages can be installed with the TeX Live Utility if you’re using TeX Live. You can also put the .sty file of the package (download it from CTAN) in the folder of your .tex file.

\begin{itemize} ended by \end{document}.

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

LaTeX found a \begin{itemize} without an \end{itemize}. This is a typical example of a mistake which is discovered very late (the mistake somewhere around line 20 is discovered at line 127).

Package babel Error: You haven’t loaded the language dutch yet.

! Package babel Error: You haven't loaded the language dutch yet.
See the babel package documentation for explanation.
Type H <return> for immediate help.
...
l.3 \select@language{dutch}

This happens when one changes the language in the babel package. The solution is to delete the .aux file. In TeXworks this can be done by File -> Remove Aux Files. (If you get an error about permissions when doing this, you have to make sure to work in one of your own folders and not in a temporary folder. Moving your .tex file will solve your problem.)

Warnings

Sometimes LaTeX gives warnings. For example if you use \maketitle but never inserted an author it will display:

LaTeX Warning: No \author given.

LaTeX won’t stop typesetting after a warning. To see a list of warnings in TeXworks go to Window -> Show Console Output.

Overfull hbox

Overfull \hbox (10.00104pt too wide) in paragraph at lines 6--7

This warning indicates that a word does not fit on a line correctly. This happens when LaTeX doesn’t know how to break a word or because there is a long line in math mode in a sentence. It can be solved by adding \- to words, as discussed previously. If nothing works you can add \\ to break a line manually but this only should be done when the entire text is finished. The converse of an overfull box is an underfull box.

Solving errors

We conclude with a few general tips on how to solve errors.

Find the problem by commenting out text temporarily

Often you don’t know what exactly causes the error. To discover the cause it can be useful to turn off parts of your code using %. In TeXworks you can also click Format -> Comment. If the code runs afterwards, the mistake has to be in the part which you commented out.

Delete auxillary files

Sometimes an error is caused by auxillary files. If you cannot explain an error, try deleting these files. In TeXworks this can be done with File -> Remove Aux Files.

Typeset regularly

It is considered a good habit to typeset your document after typing a few new sentences. If you typeset after 100 lines it can be hard to trace back your errors. Once you get more familiar with writing .tex documents you can reduce this, e.g. typeset only once a paragraph is finished.


Exercise

Fix all mistakes in the Dutch article below.

\documentclass[a4paper]{article}
\usepackage[dutch]{babel}
\begin{document}
\sectoin*{Oneindig veel priemgetallen, door Alex van den Brandhof}

Je kunt op heel veel manieren bewijzen dat er oneindig veel
priemgetallen bestaan. Filip Saidak, wiskundige van de universiteit van
North Carolina in Greensboro (VS), publiceerde onlangs in de American
Mathematical Monthly een nieuw, verrassend eenvoudig bewijs.

Een \emph{priemgetal} is een getal met precies twee delers. Het
kleinste priemgetal is 2 en de rij gaat zo verder: \$3, 5, 7, 11, 13,
17, \ldots Dat er nooit een eind aan deze rij komt, werd al 300 jaar
voor Christus bewezen door de Griek Euclides. Hoewel het niet bekend is
of Euclides de eerste is geweest die dit kon bewijzen, wordt de stelling
dat er oneindig veel priemgetallen bestaan aan hem toegekend. Euclides
is beroemd vanwege zijn dertiendelige boek De Elementen, waarin hij een
logische opbouw van de wiskunde, met name de meetkunde, geeft.

\subsection*{Bouwstenen}
De priemgetallen worden wel beschouwd als de bouwstenen van de gehele
getallen. Elk positief geheel getal is \' of priem, \'of het is te
schrijven als een product van priemgetallen. Zo is 8 gelijk aan \$2\cdot 2 \cdot 2,
 9 is gelijk aan \$3 \cdot 3$ en 10 is gelijk aan 2
\cdot 5$. Zo'n product van priemgetallen (de priemfactoren) heet wel
de \emph{priemfactorontbinding van het betreffende getal. Omdat het
getal 1 per definitie geen priemgetal is, is de priemfactorontbinding
van een geheel getal groter dan 1 uniek.

\subsection*(Een nieuw bewijs}
Filip Saidak, een Slowaaks wiskundige die tegenwoordig werkzaam is op de
universiteit van North Carolina in Greensboro, publiceerde in de
American Mathematical Monthly van december 2006 een nieuw bewijs van de
stelling dat er oneindig veel priemgetallen bestaan. Saidaks bewijs
luidt als volgt.

Stel $n$ is een geheel getal groter dan 1. De getallen $n$ en $n +
1$ verschillen slechts 1 en hebben dus geen gemeenschappelijke
priemfactoren. Dat betekent dat het getal $N_2 = n(n + 1)$$ ten
minste twee verschillende priemfactoren heeft. Voor de getallen \$N_2\$
en $N_2 + 1$ geldt hetzelfde: zij verschillen slechts 1 en moeten dus
ten minste twee verschillende priemfactoren hebben. Het getal $N_3 =
N_2( N_2 + 1) = n(n + 1)[ n(n + 1) + 1}$ heeft dus minimaal drie
verschillende priemfactoren.

Dit proces kan eindeloos worden voortgezet: het getal $N_k$ heeft ten
minste $k$ priemfactoren. Omdat dit voor elk positief geheel getal
$k$ geldt, kan de rij priemgetallen nooit ophouden.
\end{document}

Remember

  • What does an error consist of?
  • What to do with an error?
  • Where can you find warnings?