TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am compiling a latex document, and when I have errors, I get nice messages like

l.1041 \end{frame}

which tells me that there is an error somewhere before line 1041. So far, so good. I can use my text editor and quickly find line 1041.

But sometimes I have a latex document (say, main.tex) that includes something like


at the beginning of the file. Now if latex tells me there is an error on line 1041, it is referring to the source code consisting of main.tex with my_headers.tex inserted into it. So if I edit the actual file main.tex, line 1041 doesn't correspond to the error location. The location I want is 1041 minus the number of lines in my_headers.tex.

So, I can manually calculate it, or make a script, but it seems like there must be a simple option to tell latex to ignore the input/include files when calculating line numbers.

Any ideas?

share|improve this question
Add the command line option -file-line-error to the call of the typesetting engine. How you do it depends on the way you use for launching the typesetting. However, the line number always refer to the current file being read in. – egreg Mar 13 '12 at 14:30
I think that option is on by default (I use pdflatex), and turning it on makes no difference. – Stephen Mar 13 '12 at 14:33
Problem is now solved. It turns out there never was any problem: latex subtracts the numbers automatically, the way that I wanted! I just didn't notice. – Stephen Mar 13 '12 at 14:34
up vote 4 down vote accepted

The number shown in the error message always refer to the line number in the file currently being read in, so there's no offset to compute.

Therefore, if a message such as

l.1041 \end{frame}

appears, it refers to the line number in the last file appearing in the log after an open parentheses (, in your case, probably


will be in the log some lines before the error message. If you launch the typesetting engine with the -file-line-error option, you'll get more informative messages, for example

./my_headers.tex:13: Undefined control sequence
l.13 \wronglytypedcommand

The call should thus be

pdflatex -file-line-error <other options> main

where <other options> may contain the usual options such as -synctex=1. How to add this option depends on the way the typesetting is launched from the front-end or editor.

share|improve this answer
Not sure why this is not the default in TeXWorks, although does appear to be already set up in TeXShop. – Peter Grill Mar 13 '12 at 15:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.