# New character in section title

With a lot of help from this site I have made some code for a new character ʾ (transcribed Arabic Hamza) consisting of a raised, small rotated c. This character needed special kerning for italic font for which I used some code from this question. After I added this I ran intro problems. The whole thing works fine for normal text, but when the character is put in a section command it gives errors. When I run the MWE below on sharelatex.com it gives Extra }, or forgotten \endgroup. When this character is in a section title in my larger project it gives TeX capacity exceeded, sorry [input stack size=50 00].

How can I make this work for section titles as well?

Thanks.

\documentclass{book}

\usepackage{fontspec}

% test for italicness
\makeatletter
\newcommand*{\IfItElse}{%
\ifx\f@shape\my@test@it
\expandafter\@firstoftwo
\else
\protect\expandafter\@secondoftwo
\fi
}
\newcommand*{\my@test@it}{it}
\makeatother

% New character HAMZA
\catcodeʾ=\active
\defʾ{\IfItElse{\kern.12em}{\kern.0em}%
\textsuperscript{\protect\raisebox{1.1ex}{\rotatebox{180}{c}}}%
\IfItElse{\kern-.1em}{\kern-.05em}%
{}}

\begin{document}

\tableofcontents

\textit{Liqāʾ al-yawn}

\section{\textit{Liqāʾ al-yawn}}


\end{document}

• \protected\def'{...} if you plan to use it in a section title. – egreg Oct 23 '14 at 7:47

Commands such as \rotatebox are fragile, meaning that they are not safe for usage in moving arguments (sectional titles or captions).

The simplest workaround is to use

\protected\def'{%
\IfItElse{\kern.12em}{\kern.0em}%
\textsuperscript{\protect\raisebox{1.1ex}{\rotatebox{180}{c}}}%
\IfItElse{\kern-.1em}{\kern-.05em}%
{}%
}


so that TeX won't try expanding '` when writing to auxiliary files.

• You're going to end up in the acknowledgement section in my dissertation at this rate. – Andreas Oct 23 '14 at 8:48
• I'd prefer a beer when I'm around Sweden! My best wishes for your dissertation. – egreg Oct 23 '14 at 8:50