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

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.


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.