Latest news 2021-09-06: new blog post "Legacy Documents and TeX Live Docker Images".

# Bug Tracker

ID 45🔗 2013-11-04 05:26:03 Closed (Fixed) mfirstuc v1.06 \xcapitalisewords doesn't work in document structure headings

## Description

\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}


🔗Comment from Jan
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.

Name (optional):

Are you human? Please confirm the bug report ID (which can be found at the top of this page) or login if you have an account.

Comment:

You can use the following markup:

Block:

[pre]Displayed verbatim[/pre]
[quote]block quote[/quote]

In line:

[tt]code[/tt]
[file]file/package/class name[/file]
[em]emphasized text[/em]
[b]bold text[/b]
[url]web address[/url] [sup]superscript[/sup]
[sub]subscript[/sub]

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

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

You can use the Preview button to review your message formatting before submitting.

🔗Comment from Jan
Date: 2013-11-04 15:42:15

Thanks a lot. This works like a charm.

Name (optional):

Are you human? Please confirm the bug report ID (which can be found at the top of this page) or login if you have an account.

Comment:

You can use the following markup:

Block:

[pre]Displayed verbatim[/pre]
[quote]block quote[/quote]

In line:

[tt]code[/tt]
[file]file/package/class name[/file]
[em]emphasized text[/em]
[b]bold text[/b]
[url]web address[/url] [sup]superscript[/sup]
[sub]subscript[/sub]

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

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

You can use the Preview button to review your message formatting before submitting.

🔗Comment from Jan
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):

(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?

Name (optional):

Are you human? Please confirm the bug report ID (which can be found at the top of this page) or login if you have an account.

Comment:

You can use the following markup:

Block:

[pre]Displayed verbatim[/pre]
[quote]block quote[/quote]

In line:

[tt]code[/tt]
[file]file/package/class name[/file]
[em]emphasized text[/em]
[b]bold text[/b]
[url]web address[/url] [sup]superscript[/sup]
[sub]subscript[/sub]

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

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

You can use the Preview button to review your message formatting before submitting.

🔗Comment from Nicola Talbot 🦜
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.)

Name (optional):

Are you human? Please confirm the bug report ID (which can be found at the top of this page) or login if you have an account.

Comment:

You can use the following markup:

Block:

[pre]Displayed verbatim[/pre]
[quote]block quote[/quote]

In line:

[tt]code[/tt]
[file]file/package/class name[/file]
[em]emphasized text[/em]
[b]bold text[/b]
[url]web address[/url] [sup]superscript[/sup]
[sub]subscript[/sub]

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

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

You can use the Preview button to review your message formatting before submitting.

🔗Comment from Jan
Date: 2013-11-05 09:32:17

Ok, thanks.

Name (optional):

Are you human? Please confirm the bug report ID (which can be found at the top of this page) or login if you have an account.

Comment:

You can use the following markup:

Block:

[pre]Displayed verbatim[/pre]
[quote]block quote[/quote]

In line:

[tt]code[/tt]
[file]file/package/class name[/file]
[em]emphasized text[/em]
[b]bold text[/b]
[url]web address[/url] [sup]superscript[/sup]
[sub]subscript[/sub]

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

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

You can use the Preview button to review your message formatting before submitting.

Name (optional):

Are you human? Please confirm the bug report ID (which can be found at the top of this page) or login if you have an account.

Comment:

You can use the following markup:

Block:

[pre]Displayed verbatim[/pre]
[quote]block quote[/quote]

In line:

[tt]code[/tt]
[file]file/package/class name[/file]
[em]emphasized text[/em]
[b]bold text[/b]
[url]web address[/url] [sup]superscript[/sup]
[sub]subscript[/sub]

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

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

You can use the Preview button to review your message formatting before submitting.