getapps.cafe
← Back to the Blog
local-firstnative-appslattelatexstudentstroubleshooting

Your First LaTeX Document Shouldn't Start With an Error Log

A first LaTeX error usually arrives as "! Undefined control sequence." and a line number that points somewhere else. How to read a TeX error, why it lands after your mistake, and four habits that keep the log short.

Your First LaTeX Document Shouldn't Start With an Error Log

You copy a few lines from a tutorial, paste them into your editor, change exactly one word, and compile. The result is a log file that runs to 82 lines.

Somewhere around line 46, it says ! Undefined control sequence. and then prints a line that seems to be cut in half. You did exactly what the instructions asked, but this log reads like it was written for somebody else. TeX is old, careful software that reports honestly what it saw, and the log is actually readable once you know where to look. Most of it is telling you something specific.

Where TeX stopped reading

When TeX hits something it does not recognize, it drops an error.

! Undefined control sequence.
l.3 Hello, \textbd
                  {world}! The area of a circle is $\pi r^2$.

The line starting with an exclamation mark tells you what went wrong, and the l.3 means this happened on input line 3. That context is split in two. Because the top line ends exactly where TeX stopped reading, which in this case was right after \textbd, the lower line is the input it had not read yet. The culprit is the last thing on the top line: \textbd, a typo for \textbf.

If you run this normally in a terminal, TeX stops and waits with a question mark, where typing ? lists the choices.

Type <return> to proceed, S to scroll future error messages,
R to run without stopping, Q to run quietly,
I to insert something, E to edit your file,
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
H for help, X to quit.

In our test, typing H printed a help paragraph explaining the control sequence was never defined and suggesting a misspelling, while typing X quit with no pages of output. Pressing Return carried on and a one-page PDF was still written, just without the bold. If you compile your document using the -interaction=nonstopmode flag, TeX runs without stopping at the prompt, sending errors straight to the log. You can also pass the -file-line-error option, which turns the exact same error into one line: ./01_typo.tex:3: Undefined control sequence.

The parts of a TeX error message: what went wrong, the input line number, where TeX stopped reading, and the prompt waiting for you

Looking above the line

TeX reports an error where it noticed the problem, rather than where you made it, because it reads forward and only complains when something stops making sense.

An unclosed $ opened on line 3 is reported on line 4, which happens to be a blank line, with a message saying ! Missing $ inserted. and a PDF is still written. A table row on line 7 missing its \\ is reported on line 8. If you type \textbf{important. on line 4 with no closing brace, there is no line number at all. TeX read to the end of the file looking for it. The Runaway argument? line shows where the argument began ({important.), giving you the clue to follow before it performs an emergency stop and writes no PDF. The -file-line-error option gives no line for it either.

Then there is the missing package. You type \mathbb. Perfectly spelled. You get the exact same ! Undefined control sequence. error on line 3, with the top line ending at \mathbb, but the fix actually belongs in the preamble. The tutorial had a \usepackage line that you didn't copy, and the message never says the word package. When the reported line looks fine, look above it.

Three mistakes and where TeX reported them: an unclosed dollar sign on line 3 reported on line 4, a missing double backslash on line 7 reported on line 8, a missing brace on line 4 reported at the end of the file

One typo and four errors

A single mistake can produce many errors. You write \begin{documnet} on line 2, swapping a pair of letters.

./h.tex:2: LaTeX Error: Environment documnet undefined.
./h.tex:3: LaTeX Error: Missing \begin{document}.
./h.tex:5: LaTeX Error: Missing \begin{document}.
./h.tex:7: LaTeX Error: Missing \begin{document}.

TeX then stopped with an emergency stop and no PDF. Only the first error names the real mistake, while the rest are just TeX tripping over the consequences. Fix the first error, recompile, and read the log again from the top. A missing \end{equation} produces three errors, and the first two are reported on line 5 without mentioning the equation at all.

Keeping the log short

  1. Compile small and often. A new error can only be in the few lines you just wrote, which isolates the problem before it grows. The typo on line 3 is much easier to track down when line 3 is the only thing that changed since your last good run.
  2. Fix only the first error. Ignore the rest, then compile again. The later errors are often just consequences of the first, exactly like the documnet example showing four errors generated by one swapped pair of letters.
  3. Close what you open as you open it. Type the } right after the {, place the closing $ right after the opening one, and write the \end{...} right after the \begin{...} before you write inside. The unclosed brace after \textbf sent TeX to the end of the file looking for it, leaving you with no line number and a runaway argument to find.
  4. Copy a template whole. That includes the preamble. A snippet copied without the tutorial's \usepackage lines produces exactly the \mathbb error described earlier, sending you looking for a typo that does not exist.

Taking the reading off you

An editor can take some of this reading off you, without changing how TeX works. LatteX puts errors, warnings and unsupported commands on their LaTeX line and in a Problems list, where clicking a row moves the cursor straight to that line. A button next to the editor steps to the next problem.

It runs a balance check on your LaTeX with real line numbers. For the missing brace from the earlier example, it marks line 4 with '{' has no matching '}', which is the line where the brace opened. The preview re-renders about 250 ms after you stop typing, and the last good render stays on screen while you fix the mistake, so a half-typed line doesn't blank the page. Clicking in the preview puts the cursor on the line that produced that text. Commands still being typed, like \su on the way to \sum, are not flagged while you are typing them.

What an editor misses

The typo \textbd is marked on its own line, but with the message \textbd is not supported yet - the preview skips it. The text inside its braces still shows in the preview. That is the same message LatteX gives for a real LaTeX command it doesn't know, and for a shortcut a template defines with \newcommand. A beginner pasting a template from the web can hit that too. It tells you where, but not always why.

LatteX is not a TeX engine. It does not load packages or custom classes, it doesn't do \newcommand or TikZ, and not every LaTeX document will render in it. The flip side of not loading packages is it won't warn you that a real LaTeX run would need a \usepackage line. With \mathbb and no package, it shows no problem at all. If the file is going to a journal or a course that compiles with TeX, compile it there too. Its balance check is a heuristic, meaning that for an unclosed $ it can land on a later line, just like TeX. It runs on Mac and Windows, and you do not need a TeX install to run it.

The first error log

The first error log is where a lot of people quit, and it really doesn't have to be. Reading one is a skill you pick up.

The app is on the getapps.cafe menu, and the membership has a 7-day free trial. A card is required, but it is not charged during the trial.