# How to easily determine the full name of the latex file when a build error occurs?

I have recursive makefiles that I run to build my large tree which has many 100's of latex files (I use latex for everything). These makefiles travel the tree and build pdf's and generate HTML files using htlatex.

The problem I have is when there is an error, it is always very hard for me to find which file actually caused this error.

For some reason, Latex does not show the file name, only the error and the line number.

This is something I always found very strange. How hard is it to give the file name as well?

For example, here is an error I have now:

(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsa.fd)
(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd)
! Missing \endcsname inserted.
\protect
l.88 \end{tabularx}


So now I try to find the file name by scrolling up the terminal. But there is so much output generated, many times it takes me long minutes searching up and down the buffer just to find the latex command in order to find which file was being compiled when the error occurred.

Is there an option to either just tell latex/pdflatex to only show the actual command used and not all other logging it does to make it easy to see the command, or better, is there a way to tell it to show the file name in addition to the line number?

using texliver 2012 debian based.

-
Call pdflatex --file-line-error <filename> – egreg May 26 '13 at 8:46
@egreg Thanks, that helps, but just a little. is there a way to have it tell me the FULL path name of the file? I have 100's of index.tex files for example, and many file names that are the same but in different places in the tree, (it is a very large tree) and an error in index.tex:88 does not help me too much to find which index.tex it is. Thanks for your hint, I found this command line options here linuxcommand.org/man_pages/pdflatex1.html but do not see another option now to show the full path. But will keep looking – Nasser May 26 '13 at 8:56
The full path is only recorded when the input file is opened. I don't think there's a way to show it at each error message, without changing the sources. This might be a feature request for TeX Live. – egreg May 26 '13 at 9:08
You can do it yourself: see tug.org/mailman/listinfo/tex-live – egreg May 26 '13 at 9:12
If I have a file myfile.tex in the directory C:\mydir my full command line is pdflatex --file-line-error --output-directory="C:/mydir" myfile.tex. Note that if I don't specify .tex it doesn't work. – karlkoeller May 26 '13 at 10:48

You can load the package currfile via \usepackage{currfile} in your documents and start LaTeX with the argument -interaction=errorstopmode as in pdflatex -interaction=errorstopmode thesis.tex.

When the error occurs, press I (an uppercase "i" as in "Insert") and insert the following:

\PackageWarning{Build error in File}{\currfilepath}


This results in an output like

Package Build error in File Warning: /home/myuser/theproblematicfile.pgf on input line 1.


You can also use input redirection to automate this:

echo -e "I\n\\PackageWarning{Build error in File}{\\\currfilepath}" | pdflatex -interaction=errorstopmode thesis.tex


I am not sure why there are three backslashes needed before currfilepath (I was expecting two backslashes) in my shell, but otherwise it does not work here.

Please note, that this is not the recommended way to use the macro PackageWarning. Maybe some who knows error output better than me can improve this answer accordingly (and remove this paragraph).

Update As egreg points out and I haven't written that explicitly, yet: This is a workaround, please create and track the feature request as recommended. This is something everyone can have a benefit.

-
It's a hack and of course can't be made "automatic". Also not all errors will obey it (it depends on the severity of the error and several other circumstances). However, as things stand, I don't think there's much better to do. – egreg May 27 '13 at 20:46
@egreg Yeah, it's a hack. But as every good hack, it can be made an even greater hack. You can patch the needed macros to produce an error instead of a warning for example. You could use a tool like 'tee' to get LaTeX's output and live-parse it in your programming language of choice (I would not recommend TeX btw. :-)) and insert different input depending on the error message. If I would recommend that? No, but if you have time and fun doing something like that, it at least is an option (although improving some other LaTeX things might be a better investment if the above two criteria are met). – Patrick Häcker May 27 '13 at 20:58