# Removing commands from input to command

I'm trying to create my own command to highlight some changes. I want the command to update a counter, add a line in the contents table and do some changes in the text.

So far, I got:

\DeclareRobustCommand{\CoorAdd}[1]{%
\refstepcounter{change}%
\textcolor{blue}{#1}%
\textcolor{blue}{\substring{#1}{1}{20}}~% substring macro to cut the text to the first 20 characters
}
\ignorespaces}


which works great as long as there is no commands in the input. If I write \CoorAdd{ in figure \Cref{fig.fig}}, it generates a bunch of errors such as:

Argument of \@crefstar has an extra }. [...s.}}{1}{20}}\nobreakspace {}}{10}{change.34}]
Paragraph ended before \@crefstar was complete. [...s.}}{1}{20}}\nobreakspace {}}{10}{change.34}]
Undefined control sequence. [...s.}}{1}{20}}\nobreakspace {}}{10}{change.34}]
Undefined control sequence. [...s.}}{1}{20}}\nobreakspace {}}{10}{change.34}]
Undefined control sequence. [...s.}}{1}{20}}\nobreakspace


My question is: Is there a way to remove the commands from the input? Or maybe to de-command by removing the \ or similar. I don't mind to have some extra garbage text around.

## --- EDIT ---

I realised the problem is related to the command \substring', which does not accept commands in the input string. Anyway, I'm not using it anymore.

Therefore, I'm closing this question.

Thank all for your help and sorry for the bothering.

Solution : Remove the command \substring

• Try \detokenize. – Hood Chatham Mar 27 at 20:14
• Also, you should add a minimal working example. What are the packages you've loaded? Presumably cleveref and whatever packages provide \substring and \removeabs. The textcolor commands are probably unrelated to the problem -- have you tried removing them? What happens if you remove everything and just say \addcontentsline{tod}{subsection}{#1}? Does it still break? – Hood Chatham Mar 27 at 20:17
• Hi @HoodChatham thank for your comment. You made me consider the problem was with substring as indeed when I remove it, the command works perfectly. – Germán Martínez Mar 27 at 20:31
• What does happen when you put \protect in front of \Cref ?I.e., \CoorAdd{ in figure \protect\Cref{fig.fig}}` – Ulrich Diez Mar 28 at 1:52