Silencing Warnings and Errors in LaTeX
Sections
Silencing Warnings and Errors in LaTeX#
Statement of need#
Occasionally, LaTeX
throws warnings and errors that I don’t want to do anything about.
In this sense, those warnings are redundant.
In LaTeX
, the silence
package can be used to suppress unwanted output or error messages that can otherwise disrupt the formatting and appearance of a document. This helps streamline the LaTeX
workflow by reducing the amount of extraneous information displayed during the document compilation process.
The silence
Package#
The silence
package offers the following macros
to help suppress various warnings and errors:
Command |
Description |
Usage |
---|---|---|
|
Suppresses warnings in logs |
|
|
Suppresses warnings the brutal way |
|
|
Suppresses error messages in logs |
|
|
Suppresses error messages the brutal way |
|
Even cruder
Using the starred versions\usepackage{silence}
\WarningsOff*
\ErrorsOff*
suppresses all warnings and errors.
Example A: Ignoring style (.sty
) errors in Beamer#
I use the beamer metropolis
theme quite a bit, but I get the following error when compiling on my desktop TeXstudio:
! Package beamerfontthememetropolis Error: Patching section title failed.
See the beamerfontthememetropolis package documentation for explanation.
I have no intention of dealing with the error (not interested in dealing with pdflatex
vs. xelatex
vs. lualatex
(??), etc.).
My beamer slides still compile. An error I’m aware of but don’t intend to deal with is just noise.
So silencing the error is useful.
The crude way of using silence
is to filter error messages related to beamerfontthememetropolis
\usepackage{silence}
\ErrorsOff[beamerfontthememetropolis]
Example B: Float too large for page#
Another example is getting an error about floats being too large for the page. The warning I get is something like:
Float too large for page by 17.91571pt on input line 22.
Again, not intending to tinker with formatting.
The silence
package also handles a more exquisite way of turning off warnings using the following syntax for a specific package and a type of warning.
\usepackage{silence}
\WarningFilter{<package>}{<message>}
So the following turns off the Float too large warning for page
warning originating from the latex
package.
\usepackage{silence}
\WarningFilter{latex}{Float too large for page}
Example C: Margin paragraph moved#
I tested out the Tufte-LaTeX class for producing notes. It allows notes to appear on the margins. But I get a warning if too many notes are defined close together in the same page. In which case LaTeX moves the notes accordingly to space them out gives the warning:
LaTeX Warning: Marginpar on page 3 moved.
LaTeX Warning: Marginpar on page 22 moved.
...
Again, no intention of dealing with it. Adding the following in the preamble turns the warnings off.
\usepackage{silence}
\WarningFilter{latex}{Marginpar on page}
Gotcha with load order#
The silence package is called as with any other package.
\usepackage[<options>]{silence}
As with any other package, it is only effective after it has been called.
So compiling error messages and warnings thrown before silence
is loaded will not be filtered.
Place the silence
loading at the top of the preamble to capture all messages.