TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If you compile the following document with hyperref using XeLaTeX you will see that the encoding of the text commands is changed by thehyperref package to "PU" encoding. Why is this necessary?

\setmainfont{Linux Libertine O}



Are there any "gotchas" to watch?

share|improve this question
up vote 6 down vote accepted

If you don't load hyperref, then you'd get

macro:->\T1-cmd \textasciitilde \T1\textasciitilde

although the default encoding is EU1 (or EU2 with LuaLaTeX).

With hyperref you get

macro:->\PU-cmd \textasciitilde \PU\textasciitilde

because puenc.def has been loaded later. The macro \PU-cmd looks for two arguments and does

    \expandafter\ifx\csname ?\string#1\endcsname\relax
      \expandafter\def\csname ?\string#1\endcsname{\TextSymbolUnavailable#1}
      \csname ?\string#1\endcsname

The arguments are \textasciitilde and \PU\textasciitilde (which is one token).

In normal typesetting, \ifx\protect\typeset@protect is true, so \@inmathwarn\textasciitilde is expanded, but it does

\ifmmode \@latex@warning {Command \protect #1 invalid in math mode}\fi

so nothing happens unless we're in math mode. Then LaTeX checks whether


(one token) is defined which it is: \cf@encoding is expanded to the current output encoding. If it weren't, in the usual sense that \EU1\textasciitilde is equivalent to \relax or undefined, LaTeX would look for \?\textasciitilde (a default text command) and, if a definition for it is missing, an error message would be defined for further usage \EU1\textasciitilde would be globally made equivalent to \?\textasciitilde.

Finally, \EU1\textasciitilde is expanded.

In case the first conditional is false (that is, we're writing to files or in other special places), just \noexpand\textasciitilde would remain in the input stream.

You see that PU never intervenes, unless \cf@encoding is PU, which happens when hyperref is doing its work of writing the bookmarks.

share|improve this answer
So in a nutshell hyperref always uses its own encoding (PU) for bookmarks? – Yiannis Lazarides Aug 31 '14 at 17:52
Yes, PU or PD1, depending on the engine or options to hyperref (with the unicode option PU is forced also for pdflatex). Also hyperlinks use the internal hyperref encoding, I guess. – egreg Aug 31 '14 at 17:57
Yes, PD1 (PDFDocEncoding) or PU (Unicode/UTF16-BE). Bookmarks are written as simple strings into the PDF file without access to the font machinery of TeX. – Heiko Oberdiek Aug 31 '14 at 17:58
@HeikoOberdiek Gents thanks I am accepting the answer. – Yiannis Lazarides Aug 31 '14 at 18:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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