Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In XeLaTeX I've defined the following command:

\newcommand*{\PoETeX}{P\kern -.15em\raisebox{-0.21em}{O}\kern -.05em E\TeX}

as a simple (non-robust) way to create a silly logo styled after \LaTeX.

It works fine until I try to insert it into the table of contents with something like:

\addcontentsline{toc}{section}{\PoETeX}

at which point I get the following from xelatex:

! Argument of \reserved@a has an extra }. \par l.11 \addcontentsline{toc}{section}{\PoETeX}

The problem seems to be caused by\raisebox — taking out raisebox, or using \addcontentsline* gets rid of the error.

A minimal example can be found below:

\documentclass[a4paper,11pt]{article}

\begin{document}
\thispagestyle{empty}

\newcommand*{\PoETeX}{P\kern -.15em\raisebox{-0.21em}{O}\kern -.05em E\TeX}

\addcontentsline{toc}{section}{\PoETeX}
\section*{\PoETeX}

\begin{verse}

There once was a poem called \PoETeX\\
That's name sounded somewhat /pəˈθɛtɛk/.\\
\hspace*{2em}It was really quite sad,\\
\hspace*{2em}to see pronunciation so bad,\\
And to read such a terrible /ˈlɪme(ə)rɛk/!

\end{verse}
\end{document}
share|improve this question

2 Answers 2

up vote 9 down vote accepted

If you plan to often use \PoETeX in moving arguments, it's better to use

\DeclareRobustCommand*{\PoETeX}{%
  P\kern -.15em\raisebox{-0.21em}{O}\kern -.05em E\TeX}

so you won't have to put \protect before the command in many places.

Roughly speaking, defining a command with \DeclareRobustCommand is like having \protect before it whenever it's needed. Don't take the habit of defining all commands like this: use the technique only where it proves necessary.


Alternative definition:

\protected\def\PoETeX{%
  P\kern -.15em\raisebox{-0.21em}{O}\kern -.05em E\TeX}

This is actually more efficient than \DeclareRobustCommand, but has the disadvantage of using low level commands.

share|improve this answer
    
Yah, I'd rather not use any TeX commands like \def. \PoETeX is actually being passed in as an argument to an environment which is then creating the ToC entry in my actual document. What's the standard practice; should I always create robust commands if I want to pass in a command for the argument, or should I do something like \protect #2 in the package where it inserts the ToC entry? (Should I check for robustness as the package maintainer, or should the user define robust commands if they want to pass then to my environment?) –  Sam Whited Jun 16 '12 at 20:10
1  
@SamWhited If you don't have precise control on what is passed to \addcontentsline, then it's better to use \DeclareRobustCommand for commands whose expansion is fragile (for instance it contains \raisebox); however, most commands are robust, so this matters only in a few cases, probably. Using \protect#2 would not help, because \protect acts only on one token, so if #2 is Here's \PoETex the trick wouldn't work. –  egreg Jun 16 '12 at 20:20
    
Sounds good; I'll leave it up to the users to make sure their commands are robust (As you said, it's kind of an edge case anyways and not likely to happen often in practice). –  Sam Whited Jun 16 '12 at 20:23
    
Another quick usage question (though this might deserve its own full tex.se question). If the \PoETeX command is defined in a file like the one I posted (but without the document preamble, etc.), and \input-ed into another file which contains the ToC how can I get it to stop complaining that \PoETeX is undefined on the second build (when the ToC is included in the doc)? –  Sam Whited Jun 16 '12 at 21:52
1  
@SamWhited You must ensure that commands are defined before using them. Never define a command in a file that's \input after \documentclass if it appears in section titles or captions. There's no way to make it defined when the table of contents is typeset, if \input is after \tableofcontents. Oh, well, one may record the definition in the .aux file, but I wouldn't recommend it. –  egreg Jun 16 '12 at 22:14

You need to protect the fragile command \PoETeX:

 \addcontentsline{toc}{section}{\protect\PoETeX}
share|improve this answer
    
Oh, right... moving argument and all that. Thanks for the help! –  Sam Whited Jun 16 '12 at 20:02
    
@SamWhited exactly. –  Gonzalo Medina Jun 16 '12 at 20:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.