# Add offset to line number (in error message) when using input files

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

\input{../my_headers}


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?

-
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

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

(./my_headers.tex


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.

-
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