17

I would like to obtain the following:

  • the title of a section occurs in the text as Math symbols $\boldsymbol{\sum, \int}$,

  • in the table of contents it is Math symbols $\sum, \int$ (without bold),

  • in bookmarks it is Math symbols sum, integral.

I can obtain what I want in bookmarks and either of two (bold or standard) in both: TOC and text with \texorpdfstring. I can also use \section[This will go to bookmarks and TOC.]{This will appear in the content.}. But I don't know how to make it all work at the same time.

19

Two suggestions:

  • Use the "long title" -- the stuff inside curly braces -- to typeset the material in the way you want it to appear in the sectioning header itself; in particular, use \bm (or an equivalent macro) to create bold math symbols.

  • Use the \texorpdfstring macro (provided by the hyperref package) inside the "short title" -- the stuff inside square brackets -- to instruct LaTeX what to show (a) in the table of contents (e.g., ordinary, non-bold math symbols) and (b) in the pdf bookmarks (e.g., no math symbols at all).

Note that the following screenshot shows only the ToC entry (resulting from the first argument of \texorpdfstring) and the header line (the "long title"), but not the pdf bookmark (which results from the second argument of \texorpdfstring):

enter image description here

\documentclass{article}  
\usepackage{bm} % for bold math
\usepackage[colorlinks=true]{hyperref}%%%%%%
\begin{document}  
\tableofcontents
\section[\texorpdfstring{Math symbols $\sum, \int$}%
                        {Math symbols sum, integral}]% % choose text-only material here
        {Math symbols $\bm{\sum, \int}$}  % note use of \bm ("bold math")
\end{document}
11

Both symbols \sum and \int are also available in Unicode and are supported with Unicode bookmarks. Example of Mico extended accordingly:

\documentclass{article}
\usepackage{bm} % for bold math
\usepackage[
  colorlinks=true,
  pdfencoding=auto, % or unicode
  psdextra,
]{hyperref}[2012/08/13]
\usepackage{bookmark}% recommended
\begin{document}
\tableofcontents
\section[\texorpdfstring{Math symbols $\sum, \int$}%
                        {Math symbols \sum, \int}]%
        {Math symbols $\bm{\sum, \int}$}  % note use of \bm ("bold math")
\end{document}

Result AR9/Linux

  • Good to know that \sum and \int are available as macros for bookmarking purposes if a unicode-aware font is used. (I had treated them in my answer as generic stand-ins for whatever the OP really wants to typeset rather than as the actual symbols that might occur in a sectioning header...) – Mico May 25 '14 at 15:59
  • @Mico: Only the PDF viewer needs a Unicode font for the bookmarks. This Unicode encoding for bookmarks is not related to the TeX encodings (for font or input). – Heiko Oberdiek May 25 '14 at 16:12
  • Thanks Heiko! That's good to know that I can use Unicode in bookmarks. @Mico: your assumption that my needs are more general than just the two exemplary symbols I mentioned in the question was correct. – user863458 May 26 '14 at 20:18
  • Where can I find a list of such macros for pdf bookmarking? Thanks. – Matemáticos Chibchas Sep 29 '17 at 14:54
  • @MatemáticosChibchas See TDS:tex/latex/hyperref/puenc.def for macros supported in Unicode bookmarks. The macros supported by option psdextra are listed in file TDS:tex/latex/hyperref/psdextra.def. – Heiko Oberdiek Sep 29 '17 at 16:48
4

I like Heiko Oberdiek's solution. The question remains what one can do if one wants to add Unicode characters that don't have predefined commands like \int and \sum.

One option is to \usepackage[utf8]{inputenc} and \hypersetup{pdfencoding=unicode} (if it is not already set as an option to hyperref), and to include literal UTF-8 encoded characters in the source file.

This works fine, but personally I don't like using non-ASCII encodings in source files. One reason is that my preferred text editor does not always have the fonts to display every Unicode character. Another is that I like to be able to copy and paste source code into places (like here) where Unicode may or may not show up correctly at the other end.

Here is another option, using TeX's ^^ input syntax to "armor" the Unicode as ASCII. This requires first determining the byte-per-byte UTF-8 encoding of each character. They can then be written like this:

\documentclass{article}

\usepackage[pdfencoding=unicode]{hyperref}
\usepackage[utf8]{inputenc}

\usepackage{amsfonts}

\begin{document}

\section{The group \texorpdfstring
                   {$U_n(\mathbb{D}[\omega])$}
                   {U^^e2^^82^^99(^^e2^^85^^85[^^cf^^89])}}

\end{document}

example output
(source: mathstat.dal.ca)

  • Thanks! Good to know, even if I use non-ASCII in sources all the time, as my native language has a bigger alphabet. – user863458 Aug 8 '14 at 8:55
2

To supplement Peter Selinger's answer, you don't need TeX hexa notation for writing Unicode characters, you can also use command

\unichar{"1D4C1}

to obtain Unicode characters whether in the 16-bit plane or in higher planes. The command above produces a script ell letter 𝓁 (what you would expect from the \ell TeX command). So there is really no need to calculate UTF-8 bytes, just find the Unicode codepoints you need and use the \unichar command above to insert them (one character at a time) inside the second argument of a \texorpdfstring command. Peter's example would then be

\section{The group \texorpdfstring
               {$U_n(\mathbb{D}[\omega])$}
               {U\unichar{"2099}(\unichar{"1D53B}[\unichar{"1D714}])}}

Beware: the subscript n character "2099 may not be widely available… it, for once, does not display on my Mac; in fact it has been defined in Unicode version 6, in 2010. Furthermore there is a mistake in Peter's code: he uses a straight Greek omega letter, while the italic omega mathematical symbol also exists in Unicode (codepoint "1D714).

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.