# latex compile error level

Thinking of classical programming languages, many compilers support error levels. Error levels let one specify the severity at which the compile process halts. This is very handy. Once a project comes to an end, I typically enable a very pedantic error level, such that I can make sure that what I contribute is really free of all errors.

I am wondering is there something similar for Latex? To give an example, I would find it desirable if there was a flag that halts compilation on undefined references, rather than having to forge my entire document for ???.

Note

I ended up using the accepted answer. Since references aren't present on the first run, I added a \pedantic flag to my Makefile.

$(FILE)_pedantic.pdf: *.tex pdflatex -synctex=1 -shell-escape "\def\pedantic{0} \input{$(FILE).tex}"
pdflatex -synctex=1 -shell-escape "\def\pedantic{0} \input{$(FILE).tex}" bibtex$(FILE)
makeglossaries $(FILE) pdflatex -synctex=1 -shell-escape "\def\pedantic{0} \input{$(FILE).tex}"
pdflatex -synctex=1 -shell-escape "\def\pedantic{1} \input{\$(FILE).tex}"


My root.tex file then sets

\if\pedantic1
\MakeWarningsErrors
\fi


as suggested by the author of the accepted answer.

• LaTeX has error messages (where compilation can hang), warnings, and a log file that summarises how many errors, warnings, unresolved references you have. – Johannes_B Nov 18 '19 at 17:02
• That is absolutely correct, but after all, doesn't address the question (my bad if i was unclear). I am wondering whether there is a specific option that will halt compilation on a specific "warning level". – Flo Ryan Nov 18 '19 at 21:07

A simple solution to this problem is to redefine LaTeX's \GenericWarning macro with the more severe \GenericError:

\documentclass{article}

\newcommand\MakeWarningsErrors{%
\renewcommand\GenericWarning[2]{%
\GenericError{##1}{##2}{}{}%
}%
}

\begin{document}
See section \ref{foo} ...

\MakeWarningsErrors
... and section \ref{bar}.
\end{document}


LaTeX will then report the first warning as normal but stop compilation on the second one:

LaTeX Warning: Reference foo' on page 1 undefined on input line 11.

! LaTeX Warning: Reference bar' on page 1 undefined.

Type  H <return>  for immediate help.

• This did it! Thanks! – Flo Ryan Nov 18 '19 at 21:48
• It might be worth pointing out that compilation will actually stop only if the job is being run interactively. Most compilations run from scripts will use batch mode. Also, references will always be unresolved on the initial run, so a check for unresolved references isn't really helpful until after BibTeX (or equivalent) has been run. Obviously the OP is aware of this, but new LaTeX users might not be. – barbara beeton Nov 19 '19 at 16:38
• This is true. I added a suggestion to my initial question. – Flo Ryan Nov 20 '19 at 11:17