[Tex/LaTex] How to suppress specific warnings generated by pdflatex

pdftexwarnings

A lot of the times I get warnings like "hbox overfull" when a specific part of my document is meant to be extra wide on purpose –> so I am purposefully violating the default width threshold. Or to put it another way I am interested in suppressing any warning that the author "willfully disregards".

In the above example, I purposefully violate some threshold… so IMO the generated warning should be suppressed. Anytime I purposefully break some suggestion I would like to suppress the warning. How do you suppress specific warnings generated by pdflatex?

So for example how would you suppress one specific "hbox overfull" or one specific "paragraph has no preceding subsection" warning?

(For the specific case of "hbox overfull" warning I saw that one solution is to change the default threshold for the entire document but I don't want to change the default threshold. I think the default threshold is good… I am only breaking the rule once… all the other times I want a warning to be generated so I can fix it.)


The reason I ask is because when I work I would like to have zero warnings. That way when a warning is generated it is the only warning and I can fix it right away asap… as opposed to having 5 warnings… and then when I get another warning I don't notice till later when I am already past the part that generated the warning.

Best Answer

here my solution (exemplified by my concrete problem with hyperref) inspired by cyberSingularity's comment. it looks like it can be adapted for many cases. (i know of texorpdfstring, this is not the point here.)

in the preamble (apparently silence must be included before hyperref) i have

\usepackage{silence}
\WarningFilter[pdftoc]{hyperref}{Token not allowed in a PDF string}
...
\usepackage{hyperref}

then in the document my infringing captions look like

\ActivateWarningFilters[pdftoc]
\subsection{pdf toc cannot display $f_n$}
\DeactivateWarningFilters[pdftoc]
Related Question