Latest news 2020-07-03: SmashWords sale (ends 31st July 2020): 50% off crime/SF novel The Private Enemy and 100% off (free!) I’ve Heard the Mermaid Sing.

Bug Tracker

ID:45 🔗
Status:Closed (Fixed)
Category:mfirstuc
Version:v1.06
Submitted by:Jan
Date:2013-11-04 05:26:03
Summary:\xcapitalisewords doesn't work in document structure headings

Report

\xcapitalisewords cannot be used inside the structuring commands, such as \subsection or \chapter, because a lot of errors are produced.

MWE

\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

Comment from Jan
Date: 2013-11-04 07:22:51 CST

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.

Comment from Jan
Date: 2013-11-04 09:42:15 CST

Thanks a lot. This works like a charm.

Comment from Jan
Date: 2013-11-05 02:54:57 CST

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):

(hyperref) removing `\capitalisewords' on input line 1.
The result is that I only get lowercase letters in the meta data and bookmarks of the pdf. Can this be solved anyhow?

Comment from Nicola Talbot
Date: 2013-11-04 09:09 BST

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.)

Comment from Jan
Date: 2013-11-05 03:32:17 CST

Ok, thanks.

Add comment or return to search results.

Watch This Report

If you would like to be notified whenever updates are made to this report, please fill in your email address in the box below and click on "Notify Me of Changes" button. (Please ensure the address is valid.) Your details won't be passed on to third parties in line with this site's Privacy Policy.

If you supply your name, it will be used in the email greeting, which provides a more personal message, otherwise you'll just get a generic greeting. If you have previously supplied your name when signing up for notifications, you don't need to resupply it unless you want to change it.

If you have previously subscribed to notifications for this report, you can unsubscribe by clicking on the "Stop Notification" button.

The "Confirm Bug ID" field helps to protect against spambots. Please enter the bug ID (which you can find at the top of this page).

(Optional.)
E mail:
Confirm E mail:
Confirm Bug ID:

To unsubscribe from all notifications use the notifications page.

Comment

You can append a comment to the report using the form below. Comments are checked first before being added. Any spam or offensive content will be removed first according to this site's Terms of Website Use. Please bear in mind that I develop and maintain free software in my spare time. If you want commerical level support then you can hire a TeX consultant.

The "Confirm Bug ID" field helps to protect against spambots. Please enter the bug ID (which you can find at the top of this page).

(Optional. If provided, it will be shown with the comment.)
Confirm Bug ID:

You can use the following markup:

[pre]Displayed verbatim[/pre]
[tt]monospace text[/tt]
[em]emphasized text[/em]
[b]bold text[/b]
[url]web address[/url]

Ordered list:
[ol]
[li]first item[/li]
[li]second item[/li]
[/ol]

Unordered list:
[ul]
[li]first item[/li]
[li]second item[/li]
[/ul]

Click on the Preview button to preview the message.

Return to search results.