# silence package leads to an error if the hyperref's pdftitle option contains a blackboard bold math letter

If the hyperref's pdftitle option contains a blackboard bold math letter, the silence package leads to the error (compilation silently stops after (./test.out) and a Ctrl+C is needed):

! Interruption. \sl@StoreMessage ...oveGobbletwo #1\sl@Terminator \@gobbletwo \sl@Terminator... l.11 \hypersetup{pdftitle=$\mathbb{A}$

MCE pointing out the trouble:

\documentclass{article}
\usepackage{silence}
\usepackage{amsfonts}
\usepackage{hyperref}
\begin{document}
\hypersetup{pdftitle=$\mathbb{Z}$}
\end{document}


Do you know why and how make all of this compatible?

• Why do you try to set the pdftitle to something that doesn't even make it to the PDF? – TeXnician Sep 19 '18 at 15:17
• The $\mathbb{Z}$ will not survive all the way through hyperref's cleaning mechanism and only the Z will be inserted in the pdf title. If you can change to XeTeX or LuaTeX then you can use just ℤ. And apparently the silence package leads to an infinite loop, then you need Ctrl+C to exit it. – Phelype Oleinik Sep 19 '18 at 15:24

The behaviour you see is due to a collection of unfortunate bad interactions between silence, hyperref, and \mathbb.

First, let us know that \mathbb is not expandable, so

\documentclass{article}
\usepackage{amsfonts}
\begin{document}
\edef\tempa{$\mathbb{Z}$}
\end{document}


throws an error. If you add \usepackage{silence} or even \usepackage[safe]{silence}, it chokes with the code above (I don't think it should, but...). But you are using a primitive \edef with a non expandable command, so the outcome is really low level, and I think it's out of the scope of a silence package to cope with this.

Yes, but what does pdftitle has to do with \edef?

pdftitle eventually uses \pdfstringdef to turn the TeX command into a valid pdf string and issue a warning like

Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):
(hyperref)                removing math shift' on input line 5.


when an invalid token is found. Somewhere in the way \pdfstringdef does something along the lines of

\xdef\@pdftitle{#1}


where #1 is the $\mathbb{Z}$, and we already saw that this doesn't work even without hyperref or silence, so we can't expect it to work now.

hyperref, however, is clever enough to make unexpandable things expandable handing it to \xdef, so if you do

\documentclass{article}
\usepackage{amsfonts}
\usepackage{hyperref}
\begin{document}
\hypersetup{pdftitle=$\mathbb{Z}$}
\end{document}


you get a pdf with title Z and two warnings:

Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):
(hyperref)                removing math shift' on input line 5.

Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):
(hyperref)                removing math shift' on input line 5.


because of the $ that are unexpandable as well. If you try to add silence though, it chokes as before leading to the behaviour you found. If you want to keep this setup, then you can load silence with the safe option or issue \SafeMode before the \hypersetup. You can call \BoldMode later on to return to normal. This will, however, result in a pdf titled mathbb allowed only in math modeZ and three extra warnings similar to the ones above. \mathbb cannnot be used in text mode, and the pdf title is, in essence, text. ### The actual answer You can, however, get the ℤ in the pdf title without the need to resort to math-mode. According to out local pdf expert you can directly use ℤ as long as you load hyperref with the right options: \documentclass{article} \usepackage{amsfonts} \usepackage[ pdfencoding=auto,% or unicode psdextra, ]{hyperref} \begin{document} \hypersetup{pdftitle=ℤ} \end{document}  or, the obscure way, with \documentclass{article} \usepackage{amsfonts} \usepackage{hyperref} \begin{document} \hypersetup{pdftitle={\376\377\041\044}} \end{document}  with or without the error-obfuscating silence package. • Wow! Very nice. And I incidentally discovered the hyperref's psdextra option (which isn't documented AFAICS). – Denis Bitouzé Sep 19 '18 at 18:00 • @DenisBitouzé Indeed, there's no mention of it in the documentation. Basically it loads psdextra.def which contains a handful of redefinitions that are executed in \pdfstringdef. But I just checked and the answer above apparently works without this option... I don't think it's necessary actually. The definitions in psdextra.def are mostly in the form \let\<command>\text<command>... – Phelype Oleinik Sep 19 '18 at 18:13 • @DenisBitouzé it is documented in the hyperref README, I already have an open ticket on the issue that for some reason lots of hyperref is only documented in the readme and not in the manual. – David Carlisle Sep 20 '18 at 8:13 This comes from \mathbb expansion inside famous \pdfstringdef. The following works for me. \documentclass{article} \usepackage{silence} \usepackage{amsfonts} \usepackage{hyperref} \makeatletter \pdfstringdefDisableCommands{\let\@latex@error\@gobbletwo} \makeatother \begin{document} \hypersetup{pdftitle=$\mathbb{Z}\$}
\end{document}


The explanation is that hyperref does \let \GenericError \@gobblefour for pdfstringdef. But silence package redefines \@latex@error, which originally used this \GenericError. Now it doesn't hence the expansion of \mathbb (which causes execution of \@latex@error because not in math mode) causes havoc.

By doing

\pdfstringdefDisableCommands{\let\@latex@error\@gobbletwo}


one works around this problem.

• Nice caving expedition! Maybe I should not rely on silence package anymore, as it seems to not be maintained. – Denis Bitouzé Sep 19 '18 at 18:02
• silence is incompatible with hyperref in the sense that hyperref takes special measures to control LaTeX errors raised from expanding macros, but silence breaks this mechanism. My workaround is a bit brutal, and there might be some better way to address the problem (i.e. to handle the new \@latex@error unknown to hyperref which is defined by silence`) – user4686 Sep 19 '18 at 19:20