[Tex/LaTex] An equivalent of -file-line-error for warnings

errors

The -file-line-error command line flag for tex, latex, etc., is very effective. When you have a large project with plenty of files, the error message indicates very clearly not only the line number, but also the name of the file in which it occurred.

Unfortunately, this flag does nothing for warnings. What's the most effective way to find the name of the file in which under- or over- full warnings occur? Ideally, this could be done without resorting to an IDE.

The answers provided to the following questions are neat and related:

Clarification

The problem becomes difficult when you have several levels of nesting and large log files (mine range between 5,000 and 30,000 lines, with lots of mostly useless information.)

A file open in indicated in the log by (filename, while a file close is
indicated by ). Now, suppose you have a main file which inputs section files, each of which inputs several subsection files, each of which inputs tables and figures.

Suppose that you see an overfull message in line 17,432 in your log file, which says that the error occurred at input line 182. You have two options:

  • search for line 182 in all files that make your project
  • do a backward search in your log file, carefully balancing open and close parenthesis until you find which of the input files was active at line 17,432
    of the log file.

Here is an actual excerpt from my .log file. Note that there are many open and close parenthesis in it which are not related to file inclusion. Also observe that input line numbers are missing from the last message in this excerpt.

21983 LaTeX Font Info:    Font shape `T1/ptm/bx/n' in size  not available
21984 (Font)              Font shape `T1/ptm/b/n' tried instead on input line 21.
21985 
21986 Overfull \hbox (9.91599pt too wide) in paragraph at lines 14--22
21987 \T1/ptm/m/n/10 (\T1/ptm/b/n/10 N\T1/ptm/m/n/10 umber of \T1/ptm/b/n/10 I\T1/ptm
21988 /m/n/10 nstance \T1/ptm/b/n/10 V\T1/ptm/m/n/10 ariables), \T1/ptm/b/n/10 MTE  \
21989 T1/ptm/m/n/10 (\T1/ptm/b/n/10 M\T1/ptm/m/n/10 u\T1/ptm/b/n/10 t\T1/ptm/m/n/10 a
21990 bility (\T1/ptm/b/n/10 E\T1/ptm/m/n/10 xplicit)),
21991  []
21992 
21993 
21994 Underfull \vbox (badness 10000) has occurred while \output is active []

Best Answer

What's the most effective way to find the name of the file in which under- or over- full warnings occur?

Search the .log file for the string erfull (either in text editor or command-line tool). This will give you all the overfull and underfull box warnings. The warnings will tell you which lines in the source file the error came from, and the log file will also indicate which PDF page the error occurred on.

As you read through the log file you can see each inputted subfile as it is opened. The warnings that occur after each filename pertain to the line numbers in that file.


I have concocted a example to demonstrate this, which I hope will not be too confusing. The file below is structured like so:

  • Main file includes section.tex

    • section.tex inputs table1.tex
    • section.tex inputs subsection.tex

      • subsection.tex inputs table2.tex

Both of the table files create egregious box overflows.

The first erfull warning in the main .log file is this:

  (./section.tex (./table1.tex)
Overfull \hbox (3524.03448pt too wide in paragraph at lines 12-11

Looking at the generated subfiles section.tex and table1.tex, we can see that the overfull tabular environment in table1.tex starts on line 12 of table1.tex. This is the source of the 12 at the beginning of the page range in the warning.

table1 is input into section.tex, on line 11 of section.tex. This is the source of the 11 in the warning page range.

So the log message may be translated as follows:

I opened the file section.tex. Then I input the file table1.tex. When I input the file, I found an overfull \hbox somewhere between line 12 of table1.tex and line 11 of section.tex.

So to answer your question, how to find the name of the file in which the under- or overfull box occurs, it is in the file most recently referenced in the log file before the warning.


Here is the example:

\documentclass{article}
\usepackage[nopar]{lipsum}
\usepackage{filecontents}

%***************************************
\begin{filecontents}{table1.tex}






\begin{tabular}{llll}
a & b & c & \lipsum[1]\\
\end{tabular}
\end{filecontents}

%***************************************
\begin{filecontents}{table2.tex}


\begin{minipage}{1in}
\lipsum[1]
\end{minipage}
\end{filecontents}

%***************************************
\begin{filecontents}{subsection}






\subsection{Minipage}




\input{table2}
\end{filecontents}

%***************************************
\begin{filecontents}{section.tex}

\section{Confusion}
a
b

\input{table1}

d
e
f

\clearpage
\input{subsection}

\end{filecontents}

%***************************************
\begin{document}

\tableofcontents

\include{section}

\end{document}
Related Question