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.