1

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:

enter image description here

$\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 ℤ⁺

enter image description here

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?

7

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}.

Result (Adobe Reader):

Bookmark in Adobe Reader

4
  • Is there any way to show the fractions with a horizontal fractional line in the bookmark? I do not mean the diagonal/oblique fractional line! tex.stackexchange.com/questions/427032/… Apr 18 '18 at 11:38
  • 1
    @Famke Bookmarks are simple text strings, not suited for complicate math formulas. Apr 18 '18 at 16:17
  • 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
  • 1
    @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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy