Bug Tracker 
| ID | 45🔗 |
|---|---|
| Date: | 2013-11-04 05:26:03 |
| Status | Closed (Fixed) |
| Category | mfirstuc |
| Version | v1.06 |
| Summary | \xcapitalisewords doesn't work in document structure headings |
Sign in to subscribe to notifications about this report.
Description
\xcapitalisewords cannot be used inside the structuring commands, such as \subsection or \chapter, because a lot of errors are produced.
MWE
Download (405B)
\documentclass{scrbook}
\usepackage{xspace}
\usepackage{mfirstuc}
\newcommand{\MyCommandbase}{text to capitalise}
\newcommand{\MyCommand}{\xcapitalisewords{\MyCommandbase}\xspace}
\begin{document}
\chapter{First Chapter}
\MyCommand.
\section{\MyCommand}
\section{Test}
\MyCommand.
\subsection{\MyCommand}
\subsection{Test}
\MyCommand.
\chapter{\MyCommand}
\chapter{Test}
\MyCommand.
\end{document}Evaluation
\xcapitalisewords (and \capitalisewords, which underlies it) is a fragile command and therefore needs protecting in a moving argument:
\newcommand{\MyCommand}{\protect\xcapitalisewords{\MyCommandbase}\xspace}
I will make \capitalisewords robust in the next version.
Update (2013-11-04) 13:54 BST:
When the next version is released this will no longer be an issue, but in the interim you can make \capitalisewords robust via etoolbox's \robustify command:
\documentclass{scrbook}
\usepackage{hyperref}
\usepackage{xspace}
\usepackage{mfirstuc}
\usepackage{etoolbox}
\robustify\capitalisewords
\newcommand{\MyCommandbase}{text to capitalise}
\newcommand{\MyCommand}{\xcapitalisewords{\MyCommandbase}\xspace}
\begin{document}
\chapter{First Chapter}
\MyCommand.
\section{\MyCommand}
\section{Test}
\MyCommand.
\subsection{\MyCommand}
\subsection{Test}
\MyCommand.
\chapter{\MyCommand}
\chapter{Test}
\MyCommand.
\end{document}
Comments
5 comments.
Date: 2013-11-05 08:54:57
Sorry, but I have one addition to this issue. The problem above originates in the collaboration with the hyperref package. Now I recognized that I get the following warnings each time I use my defined command in headings:
Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):The result is that I only get lowercase letters in the meta data and bookmarks of the pdf. Can this be solved anyhow?
(hyperref) removing `\capitalisewords' on input line 1.
Date: 2013-11-04 09:09:00
The command is too complicated to expand to a simple PDF string, so it gets ignored by the PDF bookmarks (which is what's generating the warning message). See, for example, Token not allowed in PDFDocEncoded string, Hyperref - Token not allowed and Hyperref warning - Token Not Allowed in PDF String for a discussion on the topic. You can suppress the warning with:
\pdfstringdefDisableCommands{\def\capitalisewords#1{#1}}
but the PDF bookmark will still appear in lower case. (Note that even a basic \chapter{\uppercase{s}ample} will cause the same problem, so the issue can't be solved.)Add Comment
Page permalink: https://www.dickimaw-books.com/bugtracker.php?key=45

Date: 2013-11-04 13:22:51
Ok, this minimal working example works if you add
\protect. But, it's not working if you add the hyperref package to the preamble:\usepackage[pdftex]{hyperref}This is the case in my document and that's why \protect doesn't work either for me.