7.3. Error Messages from Latex¶
Latex is a wonderful typesetting program, however beginners often find it difficult because when something goes wrong, it takes some practice to learn how to read the error message. Once you get some practice, you’ll quickly learn that most errors from from misspelling Latex commands or forgetting a $ sign or { somewhere.
You can follow along with the discussion of latex error messages by downloading this file: fixme.tex.
Run
pdflatex fixme.tex
and you will get the errors described here.
7.3.1. An Example of a Latex Error¶
When you run pdflatex it outputs lots of stuff as it processes your document. Also long as it keeps going, you’re probably in good shape.
If all goes well, you will get something like the following lines at the end of the processing output, indicating that you have a readable PDF document. It might still have mistakes, but at least they are not fatal to pdflatex.
Output written on second.pdf (8 pages, 153968 bytes).
Transcript written on second.log.
7.3.2. Errors¶
When it encounters an error that it can’t understand, it will print out something like this, then stop with a ?, waiting for input from you as to what to do.
Runaway argument?
{article)
! Paragraph ended before \@fileswith@ptions was complete.
<to be read again>
\par
l.9
?
What has pdflatex told you?
The first line is Latex’s guess at what’s wrong:
Runaway argument?
In this case, it thinks the problem is a “runaway argument”.
This usually means that you forgot the matching brace ” )” or ] or } at the end of some option. Arguments are things that go into functions or commands, as in: “the arguments to the function f(x,y,z) are x, y, and z.
This is followed by the offending line of text or latex code, in this case at line 9: In Emacs, the line number should be shown in the mode-line, the little info bar at the bottom of your emacs window.
Runaway argument?
{article)
Yup. It’s a runaway argument. Do you see it?
The opening { does not have a matching } closing it—it has a ) instead.
Next comes some stuff about why it got an error which even I, after many years of using Latex, often don’t really understand!
Runaway argument?
{article)
! Paragraph ended before \@fileswith@ptions was complete.
<to be read again>
\par
l.9
?
Then the most important part of the error message, the line number of the offense :
Runaway argument?
{article)
! Paragraph ended before \@fileswith@ptions was complete.
<to be read again>
\par
l.9
?
Even if you don’t understand what the problem is, you can begin to look at this line ( l.9 or line. 9) in your file.
Finally, at the end of the error message is the lonely ?. This is pdflatex waiting for you to tell it what to do. You can see what the possible responses are by typing a ? followed by RETURN at the ? prompt:
??
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.
?
Let’s go through these:
- There’s one command that’s not listed here: hit X then RETURN. This will simply Exit pdflatex and give you back your prompt.
- If you just hit RETURN without any letter, pdflatex will ignore this error and proceed to the next one. Sometimes this is useful if you have an error that you know you can skip until later. Note however, that sometimes the current error will cause errors to occur in things that are not wrong. This could happen for example if you mess up a begin{itemize}. If so, any subsequent item will cause an error.
- Hit S or R (upper or lower case, followed by RETURN). This will be as if you kept hitting RETURN at each error.
- Hit Q. This will do the same as the above, except it won’t produce any output.
- Type H. This will give you some more information about the error. For example in this case, typing H gives you the following
? h
I suspect you've forgotten a `}', causing me to apply this
control sequence to too much text. How can we recover?
My plan is to forget the whole thing and hope for the best.
?
This actually is pretty useful information.
At this point, I usually edit my file and see if I can fix the error. Below, I remind you how to do this
You can edit your latex file in emacs (remember: use the ” emacs &” command to detach emacs. That way you can run pdflatex at the shell prompt).
To jump to l.9 (line 9), type
M-x goto-line
Remember that in emacs, M-x means ” ESC-x ” followed by typing out the text ” goto-line ” in the minibuffer, the last line at the bottom of the emacs window.
Emacs will then prompt you for the line number. Type the number 9 and hit enter.
Emacs will jump to line 9.
Emacs Tip
The goto-line command is very useful, but it’s a hassle to have to hit M-x and type “goto-line” each time. What I do is define a simple key sequence and bind that the goto-line command. You do this by putting the following line in your .emacs file. Open your .emacs file (in your home directory), and put this at the following text at the end:
(define-key global-map “C-xC-l” ‘goto-line)
Save your .emacs file. The next time you open a file in emacs you can simply type C-x C-l, CTRL-x CTRL-l (ell), and emacs will ask you for the line number. Much easier!
Ok, back to your Latex file. Now just fix the problem—in this case, make the braces match.
Often when you are learning, you need to look back at one of your examples, like the source files first.tex or second.tex to remember the correct syntax. In fact, most of us learned Latex by copying sections of working files.
The issue in this file was a “Runaway Argument”, because there was no matching end }.
So just fix that, save the file, and recompile (run pdflatex on) the file.
\documentclass[12pt]{article } <--------
This will take you to the next error message, or perhaps to the happy result of a readable PDF file.
7.3.3. Other Common Latex Errors¶
Here are some other common errors that you might encounter.
- Missing $ inserted This is a very common error once you start to have many equations
or mathematical environments. You left out a $ or [ or ] somewhere when you were writing text that needs to be in math mode. It can also occur when you use a math command, such as a sub or superscript: x_i or y^2 outside of a math environment.
Extra alignment tab has been changed to cr. You have too many or not enough &’s in a row of a table or array or eqnarray.
LaTeX Error: begin{ something} on input line line number ended by end{document}. You’ve left out the end{ whatever}. Perhaps you’re building a table or an eqnarray that has a bunch of lines and you’ve forgotten the end statement.
LaTeX Warning: Reference ... undefined on ...
LaTeX Warning: There were undefined references. You have `references in your document`_, and something is wrong. Usually this happens because you have used to a ref but didn’t define the label that goes with it, or have a typo in your ref. You need to compile again so LaTeX will be able to get the references right. NOTE:
These errors are not fatal and will not usually stop pdflatex. However, your document will have something like ”...in equation ( ??) we see...”.
Paragraph ended before end was complete. You are probably missing an } at the end of an end{ something} statement.
Undefined control sequence. You’ve tried to use a command that doesn’t exist. Usually this is the result of a typo. Go to the line number mentioned in the error and look at all your commands. You’ll probably find something like rfac where you wanted frac.
When I try to compile, it starts, but then just hangs. Nothing happens, and I can’t do anything. Then when I try to save the file, it won’t let me save it with the same name.** You probably have tried to use a package that you haven’t installed. For example, if you try usepackage{fancyhdr} but haven’t `installed the package`_, then you’ll hang pdflatex so badly that you should just kill the xterm window (or, if you know how, kill the latex process you’ve started). **
Something like:
! Undefined control sequence.
l.668 \includegraphics
[width=8cm]{s8.png}
Even though you have spelled the latex command \includegraphics
correctly, pdflatex still balks here. That's because you forgot to
tell latex that you want to **\usepackage{graphicx}** Notice too, that
in showing you the undefined control sequence error, pdflatex skips a
line right after the word that it doesn't recognize. In this case
that's **includegraphics**.
- When referencing figures or equations, the page numbers or equation numbers don’t come out right. Remember that when using references, you need to run pdflatex twice in order to get the references right.
Now it’s your turn
7.4. Homework¶
Download the following file: fixme.tex.
This file has a number of errors, which are shown at the end of this page.
Your job is to correct the errors in this file so that you get a readable PDF document.
This is Homework 8
Note, that there are non-fatal errors, i.e. there are still a couple problems with the document even once pdflatex exits successfully. Can you spot and fix them?
What I do is iterate the following steps:
Open a terminal and pdflatex the fixme.tex file. If there are errors, open the file in emacs by typing emacs fixme.tex & so that you have an emacs window and your xterm prompt. Now,
- In emacs, jump to the line where the error is by with goto-line (did you make the C-x C-l key sequence in your .emacs file?)
- Fix the problem.
- Save the file.
- Run pdflatex on the file at the terminal prompt
- If there is a new error, return to step 1.
- Iterate these steps until pdflatex ends successfully.
The completely fixed fixme file is here: fixed.pdf.
A list of the errors that pdflatex will generate is shown below.
Latex Error Messages from fixme.tex
Runaway argument?
{article)
! Paragraph ended before \@fileswith@ptions was complete.
\par
l.9
........................................................................
! LaTeX Error: \begin{abstract} on input line 14 ended by \end{abs}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H for immediate help.
...
l.17 \end{abs}
........................................................................
! Undefined control sequence.
l.41 \ssection
{Math Errors}
........................................................................
! Missing $ inserted.
$
l.48 ...For example, using a sub or superscript x_
i or y^2 without
........................................................................
! Missing $ inserted.
$
l.53
........................................................................
! Missing $ inserted.
$
l.56 the $\backslash
$. This makes it an inline math mode switch.
........................................................................
! Undefined control sequence.
l.64 \integrate
_{0}^{\infinity} \frac{dx}{1 + x^2} = \rfac{\pi}{2}
........................................................................
! Undefined control sequence.
l.64 \int_{0}^{\infinity
} \frac{dx}{1 + x^2} = \rfac{\pi}{2}
........................................................................
! Undefined control sequence.
l.64 \int_{0}^{\infty} \frac{dx}{1 + x^2} = \rfac
{\pi}{2}
........................................................................
LaTeX Warning: Reference `eq:pot' on page 2 undefined on input line 76.
........................................................................
! Extra alignment tab has been changed to \cr.
\endtemplate
l.118 2 & 42 & 2 & &
35 \\
........................................................................
The table doesn't look right.
........................................................................