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

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.

🔗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.
Replying to Comment #27:

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.

Replying to Comment #28:

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?
Replying to Comment #29:

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.)
Replying to Comment #30:

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.

Replying to Comment #31:

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.


Add Comment

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.

Page permalink: https://www.dickimaw-books.com/bugtracker.php?key=45