Discussion:
Hyperref: pdftitle does not allow underscores?
(too old to reply)
Michael Shell
2017-06-21 10:19:39 UTC
Permalink
Raw Message
Does anyone know if the PDF spec permits the use of underscores in the
pdftitle string? Underscores do seem to be OK for PDF bookmarks.

Consider the example:


\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[pdftitle={Testing the Under\_score PDF Title},
bookmarks=true]{hyperref}
\begin{document}
\author{Michael Shell}
\title{Testing the Under\_score PDF Title}
\maketitle
How can we use the underscore in PDF titles?

\section{Under\_score Section}
However, it does seem to work OK in PDF bookmarks.

\end{document}



when compiled by pdflatex, I get the warning:

Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):
(hyperref) removing `\T1\textunderscore' on input line 4374.


which is triggered by the pdftitle, but not \section, underscore.

And the resulting PDF file shows the underscore was indeed omitted
from the pdftitle:
[mshell]: pdfinfo under_test.pdf
Title: Testing the Underscore PDF Title
Subject:
.
.

I even tried the ^^5f trick to no avail.

However, the underscore for the pdfbookmark for

\section{Under\_score Section}

seems to work just fine.

What are the constraints here for the PDF title, subject, etc.
strings?


Thanks in advance,

Mike Shell
MadYuv
2017-06-21 12:42:46 UTC
Permalink
Raw Message
Post by Michael Shell
Does anyone know if the PDF spec permits the use of underscores in the
pdftitle string? Underscores do seem to be OK for PDF bookmarks.
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[pdftitle={Testing the Under\_score PDF Title},
bookmarks=true]{hyperref}
\begin{document}
\author{Michael Shell}
\title{Testing the Under\_score PDF Title}
\maketitle
How can we use the underscore in PDF titles?
\section{Under\_score Section}
However, it does seem to work OK in PDF bookmarks.
\end{document}
(hyperref) removing `\T1\textunderscore' on input line 4374.
which is triggered by the pdftitle, but not \section, underscore.
And the resulting PDF file shows the underscore was indeed omitted
[mshell]: pdfinfo under_test.pdf
Title: Testing the Underscore PDF Title
.
.
I even tried the ^^5f trick to no avail.
However, the underscore for the pdfbookmark for
\section{Under\_score Section}
seems to work just fine.
What are the constraints here for the PDF title, subject, etc.
strings?
Thanks in advance,
Mike Shell
\texorpdfstring tag helps you to meet your requirement, see sample coding below:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[bookmarks=true]{hyperref}
\hypersetup{pdftitle={\texorpdfstring{Test the Under\_score PDF
Title}{Test the Under\textunderscore score PDF}}}
\begin{document}
\author{Michael Shell}
\title{Testing the Under{\textunderscore}score PDF Title}
\maketitle
How can we use the underscore in PDF titles?

\section{Under\_score Section}
However, it does seem to work OK in PDF bookmarks.

\end{document}
Michael Shell
2017-06-21 15:19:16 UTC
Permalink
Raw Message
On Wed, 21 Jun 2017 05:42:46 -0700 (PDT)
Post by MadYuv
\texorpdfstring tag helps you to meet your requirement,
\hypersetup{pdftitle={\texorpdfstring{Test the Under\_score PDF
Title}{Test the Under\textunderscore score PDF}}}
MadYuv,

You did give me a solution, but \texorpdfstring, which I already was
aware of, is not the key. In fact, there is no need for \texorpdfstring
within pdftitle=, because, "hey, there that's always a pdfstring". LOL.

And, surprisingly, the key isn't \textunderscore either because that
one too will fail if used in place of \_ in my original example.

So, how in the world does your example manage to work?!

Well, it is your use of \hypersetup that is the key!

If I do:

\usepackage[pdftitle={Testing the Under\_score PDF Title},
bookmarks=true]{hyperref}

The problem happens, but if I instead use:

\usepackage[bookmarks=true]{hyperref}
\hypersetup{pdftitle={Testing the Under\_score PDF Title}}

then all is well.

Is this a bug in hyperref, or is it a limitation of allowing latex to
acquire the optional argument to \usepackage rather than hyperref.sty
for the argument of \hypersetup ?

BTW, does anyone know Heiko Oberdiek's current email address? I know
he used to use the ruf.uni- freiburg.de domain and now I think he
is at googlemail.com (I won't show the account name prior to the @
to avoid SPAM for him), but I haven't heard back from him at
googlemail ... yet. Is there another address he is using these days?
(If so, please don't post it in clear text here as he probably
does not want his email address out in the open.)


Cheers and thanks in any case!

Mike
Ulrike Fischer
2017-06-21 15:39:23 UTC
Permalink
Raw Message
Post by Michael Shell
BTW, does anyone know Heiko Oberdiek's current email address?
The googlemail adress is correct, but sometimes you have to wait for
answers. If you want to report a bug use better the github page:

https://github.com/ho-tex/hyperref
--
Ulrike Fischer
http://www.troubleshooting-tex.de/
Ulrike Fischer
2017-06-21 15:32:11 UTC
Permalink
Raw Message
Post by Michael Shell
Does anyone know if the PDF spec permits the use of underscores in the
pdftitle string? Underscores do seem to be OK for PDF bookmarks.
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[pdftitle={Testing the Under\_score PDF Title},
bookmarks=true]{hyperref}
\begin{document}
\author{Michael Shell}
\title{Testing the Under\_score PDF Title}
\maketitle
How can we use the underscore in PDF titles?
\section{Under\_score Section}
However, it does seem to work OK in PDF bookmarks.
\end{document}
(hyperref) removing `\T1\textunderscore' on input line 4374.
What are the constraints here for the PDF title, subject, etc.
strings?
The constraints are more in the option system of \usepackage. One
shouldn't overstretch its capabilities to implement a keyval system.

If you set the pdftitle in hypersetup it works fine:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[bookmarks=true]{hyperref}
\hypersetup{pdftitle={Testing the Under\_score PDF Title}}
\begin{document}
\author{Michael Shell}
\title{Testing the Under\_score PDF Title}
\maketitle
How can we use the underscore in PDF titles?

\section{Under\_score Section}
However, it does seem to work OK in PDF bookmarks.

\end{document}
--
Ulrike Fischer
http://www.troubleshooting-tex.de/
Loading...