# [texhax] removing any macros from a string argument

Dieter Meinert DMeinert at RosenInspection.net
Tue Mar 23 17:33:34 CET 2004

-----BEGIN PGP SIGNED MESSAGE-----

Hi all,
I have a special problem I can't get managed:
I have a unique identifier (user-defined) in my documents,
which may or
may not include other macros (preferred \_, but anything
may be possible).
Now I need to remove all macros from this string in order
to use it as a
save label-generator.
I just don't find a way to remove all the macros from the
string.

% Example:

\newcommand{\identifier}[1]{
\newcommand{\myID}{#1}
\renewcommand{\identifier}{\myID}
}

\begin{document}
\identifier{abc\_def\macro{}ghi}
This is Document \myID, uniquely known as \identifier.

\begin{figure}
\caption{\label{\identifier:F1} my first image}
\includegraphics{firstImage.jpg}
\end{figure}
\end{document}

%end Example

Obviously this does not work, latex produces lots of error
messages
concerning the macros in the label. So I need to redefine
the label
that it looks like "abcdefghk", i.e. remove all macro names
from the string.

How do I have to redefine \identifier in the first place to
get this
result?

I already tried splitting the argument like
\process{\myID}
\long\def\process#1\@proc #1@@@
\long\def\@proc#1#2#3@@@{\def\myNewID{#1#3}
\renewcommand{\identifier}{\myNewID}

and similar constructs with defined #2, but each test
stopped at the
definition of the macros which is expanded somewhere in the
process.

Did anyone solve this problem ? (if it's in the FAQ it
completely
escaped my search, sorry)

tia
Dieter Meinert

++++++ Do not support SPAM ++++++ use only plaintext for
email ++++++

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.3 for non-commercial use <http://www.pgp.com>