I would like to remove the math mode in a text that is not defined directly, but in a macro. Here is my code:
\documentclass{book}
\begingroup
\lccode`\~=`$
\lowercase{\endgroup
\def~#1~{\ignorespaces}%
}
\def\removemath{%
\begingroup
\catcode`$=\active
\removemathX
}
\def\removemathX#1{%
#1
\endgroup
}
\edef\nomath#1{
\removemath{#1}
}
\begin{document}
\chapter{XXXXXX}
\newcommand\aaaa{AAA$^{1}$, BBB$^{2}$, CCC$^{3}$, DDD$^{4}$}
\removemath{AAA$^{1}$, BBB$^{2}$, CCC$^{3}$, DDD$^{4}$}
\removemath{\aaaa}
\nomath{\aaaa}
\end{document}
In this example, the first removemath
works, but the second removemath
and nomath
does not work.
I am not sure why. Is it an expansion problem? Maybe something else?
Can someone suggest a solution?
\aaaa
have already been tokenised so catcode changes have no effect. However it isn't clear why you are using catcode changes, you copuld use a delimited argument on a normal catcode$
. – David Carlisle Jan 25 '19 at 22:15