As you probably know by now, \DeclareRobustCommand{\cs}{...}
defines two commands: essentially it does
\def\cs{\protect\cs•}
\def\cs•{...}
where I denote with •
a space in the command's name (which is ordinarily not possible). When LaTeX finds this in normal typesetting, \protect
is equivalent to \relax
, so the expansion of \cs•
does that's requested. When LaTeX is writing into auxiliary files, \protect
is \noexpand
, so the effect is of writing the string \cs
followed by a space (when the auxiliary file will be input, that space will not be considered part of the name, but that's irrelevant).
So, in order to check a robust command, you have to look at the expansion of \cs•
, but you must know in advance whether the command is robust.
The situation is further complicated by the fact that the expansion of \1
after \DeclareRobustCommand\1{...}
is
\x@protect\1\protect\1•
(again • denotest a space in the name).
In the packages xpatch
and regexpatch
I do a check on the various possibilities of the replacement text with the macro \xpatch_main:NN
(xpatch
) or \xpatch_main_check:N
(regexpatch). You can see that the list is quite long.
If you know that the command has been defined with \DeclareRobustCommand
then
\def\CheckRobustCommand#1{%
\expandafter\CheckCommand\csname\expandafter\@gobble\string#1\space\endcsname
}% (AM)
to be used just like \CheckCommand
might be what you want.
A simple-minded version that only checks whether the "command with a trailing space" is defined can be
\makeatletter
\def\CheckRobustCommand#1{%
\expandafter\CheckCommand\csname\expandafter\@gobble\string#1\space\endcsname
}% (AM)
\def\xCheckCommand#1{%
\ifcsname\expandafter\@gobble\string#1\space\endcsname
\expandafter\CheckRobustCommand
\else
\expandafter\CheckCommand
\fi
}
\makeatother
The command \xCheckCommand
can be used for commands defined by both \newcommand
and \DeclareRobustCommand
. (AM)
xpatch
orregexpatch
to see something related to this problem.