0

Lecture Note.tex:1898: Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):(hyperref) removing \hbox' on input line 1898. Lecture Note.tex:1898: Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):(hyperref) removing\z@' on input line 1898. Lecture Note.tex:1898: Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):(hyperref) removing\hss' on input line 1898.`

What is this error message meaning? It does not make critical error, but makes an warning on latex

1
  • 4
    Welcome to TeX.SE. Please tell us what’s going on in lines 1895 to 1890 of LectureNote.tex. Please also tell us with which options you loaded hyperref.
    – Mico
    Oct 31, 2019 at 6:08

1 Answer 1

2

Each of these messages tells that code line 1898 of "Lecture Note.tex" contains some code whose expansion and processing by the TeX-engine/by the LaTeX-compiler yields that in a place, where a PDF-string is expected, a token is found which does not fit into a PDF-string. Each of these messages also tells you that the token in question was removed from what is to be the PDF-string in question.

A PDF-string is a string/a sequence of characters which is to be "understood"/interpreted/processed/rendered by the PDF-viewing program when displaying the .pdf-file (which beforehand was created by means of the TeX-engine/by means of the LaTeX-compiler).

PDF standards say that PDF-strings (strings of type "text string type") can be encoded either in an encoding whose name is PDFDocEncoding or can be encoded in Unicode (UTF-16BE = UTF-16 Big Endian).

The hyperref package converts things that are to be PDF-strings from the TeX-engine's internal character encoding to PDFDocEncoding or UTF-16BE automatically.

The phrase "PDFDocEncoding" in the warning indicates that (due to not using hyperref's package option unicode) the hyperref package currently is set up to encode PDF-strings in PDFDocEncoding. (If hyperref is loaded with the option unicode, then PDF-strings will be encoded in UTF-16BE.)

TeX-code which is to form the textual phrase of a bookmark in the .pdf-file should (after expansion) yield a sequence of character tokens which

  1. can be converted from the TeX-engine's internal character encoding to the encoding chosen for PDF-strings.
  2. forms something that can be understood/interpreted/processed/rendered by the PDF-viewing program (e.g. Adobe Acrobat) for displaying the bookmark-phrase in a separate area of the window where the .pdf-file in question is displayed.

If in the stage where the TeX-engine/the LaTeX-compiler is running and processing the .tex-sourcecode for producing the .pdf-file a set of tokens which is to form the textual phrase of such a bookmark contains, e.g., the non-expandable primitive token \hbox, then that is a problem because

  • on the one hand the TeX control sequence token \hbox is not a character which can be converted from the TeX-engine's internal character-encoding to the encoding chosen for PDF-strings.
  • on the other hand taking \hbox literally and converting the literal sequence would deliver the character-sequence \, h, b, o, x as a part of the PDF-string while when viewing the .pdf-file one doesn't want to see the letter-sequence h, b, o, x as a part of the bookmark's textual phrase (, which would be the case because the PDF-viewing-program does—unlike the LaTeX-compiler—not take the sequence \, h, b, o, x for a control-sequence but takes \ for the directive to "escape" the following character and thus displays the h and also the sequence b, o, x literally).

When using hyperref while creating .pdf-files, then (beneath other things) bookmarks are created automatically. Hereby the textual phrases of the bookmarks are obtained from the arguments of sectioning-commands like \chapter or \section. If these arguments (after expansion) contain (non-character-)tokens whose conversion from the TeX-engine's internal character encoding to the encoding chosen for PDF-strings causes problems and whose literal representation will, when occuring in a textual phrase of a bookmark, not be "understood"/interpreted/processed/rendered by a PDF-viewing program, but (erroneously) will be displayed literally, then you get warning messages like the ones encountered by you.

That's why the hyperref package brings along the \texorpdfstring-mechanism:

hyperref's macro \texorpdfstring{⟨TeX string⟩}{⟨PDF string⟩} processes two arguments:

The first argument denotes a set of tokens to be used in situations where things only need to be "understood"/interpreted/processed by the TeX-engine/by the LaTeX-compiler.
The second argument denotes a set of tokens to be used in situations where things will be converted to the encoding chosen for PDF-Strings (PDFDocEncoding/UTF-16BE) as things (after creating the .pdf-file) need to be "understood"/interpreted/processed/rendered by the PDF-viewing-program.

Thus you can, e.g., do something like:

\documentclass{article}
\usepackage{hyperref}
\begin{document}
\tableofcontents
\section{%
  A section about 
  \protect\texorpdfstring{\hbox{\protect\texttt{typewriter}}}{typewriter} 
  %\hbox{\protect\texttt{typewriter}} %<-This way you get a warning which
                     %  informs about the removal of the token  \hbox
                     %  from the PDF-string which LaTeX/hyperref is about
                     %  to create/prepare for the bookmark because with
                     %  the phrase "\hbox{...}"
                     %  - for one thing the token  \hbox  is not a
                     %    character which can be converted to the encoding
                     %    chosen for PDF-strings
                     %  - for another thing having the phrase "hbox"
                     %    literally in the text of the bookmark seems
                     %    undesired.
                     %  "\texttt" would cause similar problems but the
                     %  author of hyperref already took that into account
                     %  and "\texttt" is removed silently by hyperref
                     %  while examining things that are to be transformed
                     %  into PDF-strings.)
  font%
}%
Some text.
\end{document}

A PDF-viewing program might display the .pdf-file resulting from compiling the example above like this:

enter image description here

Due to \texorpdfstring's first argument the phrase "typewriter" will be put into a \hbox and will be written in typewriter-font within the text of the document.
Due to \texorpdfstring's second argument you just have the plain phrase "typewriter" within the bookmarks, without control-sequences like \hbox or \texttt which are not "understood" (and therefore would be displayed literally) by the PDF-viewing-program which processes bookmark-phrases for displaying bookmarks.

More information about \texorpdfstring and about PDF-strings (and warnings in case things are not suitable for PDF-strings) can be found in section 4.1.2 Replacement Macros of the manual of the hyperref package and in section 6 Dealing with Pdf strings of the commented source code of the hyperref package.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .