[Tex/LaTex] Add offset to line number (in error message) when using input files

errorsinput

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?

Best Answer

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.

Related Question