I tried to define a macro myself, which outputs different strings according to the input variable (like select-case statements in other programming languages).
The problem:
If I use the code in headings, captions, etc., I get error messages and no pdf, unless I put a \protect before the macro (see example below).
I'd like to avoid that - can I redefine the macro to make it "robust" also in such environments?
Example file
\documentclass[11pt, a4paper]{scrbook}
\usepackage{color}
\usepackage{xstring}
\newcommand{\ed}[1]{% source: http://tex.stackexchange.com/q/64131/4009, needs package xstring
\textcolor{magenta}{
\,\bfseries\itshape\IfStrEqCase{#1}{{1}{A}
{8}{B}
{5}{C}
{3}{D}
{7}{E}
{11}{F}
{14}{G}
{16}{H}
{19}{J}}
[??]
}}
\listfiles
\begin{document}
1 \ed{1}
2 \ed{2}
3 \ed{3}
4 \ed{4}
test
\section{in headings it does not work like \ed{11}, at leat in the main document}
\end{document}
\DeclareRobustCommandperhaps? ;-) – Mar 16 '15 at 16:11\newcommandvs.\DeclareRobustCommand. – Mar 16 '15 at 16:16