# Get math to show up in PDF bookmarks

Many math symbols get messed up in the PDF bookmarks.

Example:

\documentclass{article}
\usepackage{amssymb}

\makeatletter
\usepackage{bookmark}
\makeatother

\begin{document}

\section{Is in $\in$, Set minus $\backslash$, Positive integers $\mathbb{Z}^{+}$}

Hello.
\end{document}


Output PDF:

$\in$ becomes a blank space, $\backslash$ becomes "026E30F, and $\mathbb{Z}^{+}$ becomes Z+.

What I can do in Adobe Acrobat is to manually change the PDF bookmark, where I put in unicode math characters instead, like so:

Is in ∈, Set minus \, Positive integers ℤ⁺

But I was wondering if I could do this in the tex file itself. I know for example that there is the possibility of entering an alternative "short title" for the title of a section/subsection/etc., so that this "short title" (instead of the actual title) shows up in the table of contents.

Is there a similar possibility for the PDF bookmark?

The math engine and different fonts are not possible in bookmarks. They are plain simple strings, but at least, they can be given in Unicode. The latter can be enabled by option unicode (or pdfencoding=auto) in hyperref that is used by package bookmark for converting the bookmark strings.

Option psdextra adds support for many symbols, especially math symbols.

\pdfstringdefDisableCommands can be used to redefine commands for bookmarks. The example uses it to add support for \backslash by replacing it by the supported \textbackslash.

\texorpdfstring can be used to specify a bookmark replacement string:

• \mathbb{Z} is replaced by U+2124 (DOUBLE-STRUCK CAPITAL Z) and
• the superscript + is replaced by U+207A (SUPERSCRIPT PLUS SIGN).

Full example:

\documentclass{article}
\usepackage{amssymb}

\usepackage[unicode,psdextra]{hyperref}
\usepackage{bookmark}
\pdfstringdefDisableCommands{\let\backslash\textbackslash}

\begin{document}

\section{%
Is in $\in$,
Set minus $\backslash$,
Positive integers \texorpdfstring{$\mathbb{Z}^{+}$}{\unichar{"2124}\unichar{"207A}}%
}

Hello.
\end{document}


The dollar signs for switching to and from math are automatically filtered out. If the warnings are of concern, then \texorpdfstring helps, e.g. \texorpdfstring{$\in$}{\in}.

• My Dear Heiko Oberdiek, I can't use the Unicode for mathcal{C}-(\unichar{"1D49E}) or the Unicode for mathcal{C}-(\unichar{"1D4D2}), so I replaced the Unicode for mathfrak{C}-(\unichar{"212D}), what was the problem with the Unicodes of length 5? Apr 18 '18 at 16:32
• @Famke Just tested \unichar{"1D49E}. Works with pdflatex and AR. But the set of displayed characters depends on the PDF viewer. Restrict to simple characters for greater compatibility of PDF viewers. Anyway, math should be avoided in section titles in general for better style. Apr 18 '18 at 16:45