Text Formattinghyperref | Expanding Arguments and PDFLaTeX

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
cbkschroeder
Posts: 55
Joined: Sun Nov 09, 2008 7:48 pm

hyperref | Expanding Arguments and PDFLaTeX

Post by cbkschroeder »

Hello,

Thanks for reading my question.

I've made a command called "\codefilename"; the argument is always set to lower case, uses a specific font, and cannot be hyphenated. The command works great in the body of text, however, when I use it in a section title, hyperref reminds me that it can't deal with certain things when it puts the argument into the pdf bookmark list. Hyperref then simply rejects what it can't deal with. One thing hyperref can't deal with is the \lowercase command.

I've provided a mwe as follows:

Code: Select all

\documentclass{article}

\usepackage{hyperref}

\newcommand{\codefilename}[1]{\mbox{\texttt{\lowercase{#1}}}}

\begin{document}
\section{\codefilename{Name.C}}
\end{document}
This produces the file
mwe.pdf
(20.34 KiB) Downloaded 245 times
In the log file, I see:
Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):
(hyperref) removing `\lowercase' on input line 8.
Is there any way I can get pdfLaTeX to expand the lowercase command before it makes an entry into the pdf bookmarks so that everything that ends up in the bookmarks is lowercase, too?

Thanks,

Christian

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

hyperref | Expanding Arguments and PDFLaTeX

Post by localghost »

Search the hyperref manual for the \texorpdfstring command.


Thorsten
cbkschroeder
Posts: 55
Joined: Sun Nov 09, 2008 7:48 pm

hyperref | Expanding Arguments and PDFLaTeX

Post by cbkschroeder »

Hi Thorsten,

As always, thanks very much for your reply.

My apologies; I should have mentioned that I had explored \texorpdfstring already. Perhaps I have missed the obvious, but I'm not sure how using that macro allows me to address all my concerns. I assume you were thinking that I should employ the macro in a manner such as:

Code: Select all

\newcommand{\codefilename}[1]{\texorpdfstring{\mbox{\texttt{\lowercase{#1}}}}{\lowercase{#1}}}
Doing that, however, really doesn't solve my problem because I still can't get the \lowercase macro expanded first. Not only do I want all of the text in the argument to be in lowercase in the body of my text, I also want the PDF bookmark entry to be in lowercase. If you had another idea in mind as to how to use \texorpdfstring, I'd love to know!

Thank you very much for your time,

Christian
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

hyperref | Expanding Arguments and PDFLaTeX

Post by localghost »

I don't think that you need the \lowercase primitive at all. Neither in the first nor in the second argument of \textorpdfstring. Remember that the second argument creates the actual bookmark. There are only a few selected macros which are accepted for this.

Code: Select all

\newcommand{\codefilename}[1]{\texorpdfstring{\mbox{\texttt{#1}}}{#1}}
cbkschroeder
Posts: 55
Joined: Sun Nov 09, 2008 7:48 pm

Re: hyperref | Expanding Arguments and PDFLaTeX

Post by cbkschroeder »

Ahhh, but I do need the \lowercase! The reason for this is that there are many, many invocations of \codefilename in my document, and many could have accidentally-added uppercase characters. For the sake of uniformity, I'd like the \codefilename macro to ensure that each code file name comes out only in lowercase.

I could, of course, search each and every invocation of \codefilename to make sure every character in the argument is lowercase, but that defeats the point of making \codefilename.

Thanks again,

Christian
Post Reply