# [OS X TeX] Off Topic: changing command behavior (legacy issue)

Ross Moore ross at maths.mq.edu.au
Wed Sep 1 23:57:45 CEST 2004

Hi Francesco,

On 02/09/2004, at 5:54 AM, Francesco Costanzo wrote:

> Hi There:
>

> *WHAT I WANT*
> I would like to modify the behavior of \mycommand so that the
> following two forms result in the same outcome:
>
> form 1: \mycommand[option]{FirstArgument}{SecondArgument}
>
> form 2: \mycommand[option]{FirstArgument}{\label{SecondArgument}}
>
> In other words, if SecondArgument' is a string then behave as usual;
> \label{SecondArgument}' then use as is (as opposed to doing
> \label{\label{SecondArgument}}).

OK; that's not hard to achieve.
You'll need at least 2 macro definitions or bindings.
e.g. something like:

\let\reallatexlabel\label
\newcommand{\mycommand}[3][]{%
... do whatever needs to be done with #1, #2 ...
\bgroup \def\label##1{##1}%  make \label a no-op
\reallatexlabel{#3}%
\egroup }%

which performs the action of LaTeX's \label command,
even though the actual command '\label' is temporarily a no-op.

OR

\newcommand{\mycommand}[3][]{...
... do whatever needs to be done with #1, #2 ...
\bgroup \def\label##1{##1}%  make \label a no-op
\expandafter\reallatexlabel\expandafter{#3}%
\egroup }%

which now forces the temporary no-op definition of \label to be
expanded into its argument before acting with  \reallatexlabel ,
if the 1st token of #3 is \label. When that 1st token is just
a single letter, then it expands into itself.

>
> In case you are wondering as why I would want to do something like
> this, let me just say that the problem concerns a book in two volumes
> managed by various authors and some of them wish to use one form and
> the command while others wish to use the other one (not to mention the
> fact that there are about 1000 pages already written which I'd rather
> not modify).

Sure.
Being able to cope with this kind of thing is one of the huge strengths
of a programmable system like (La)TeX.

Hope this helps,

Ross

>
> --
> Francesco Costanzo
> Associate Professor
>
> Engineering  Science and  Mechanics  Department
> The Pennsylvania State University
> 212 Earth and Engineering Sciences Bldg.
> University Park, PA 16802-1401
> USA
>
> Phone:   (814)863-2030
> Fax:     (814)863-7967
> mailto:costanzo at engr.psu.edu
> http://www.esm.psu.edu/HTMLs/Faculty/FCostanzo.html
>
> --------------------- Info ---------------------
> Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
>           & FAQ: http://latex.yauh.de/faq/
> TeX FAQ: http://www.tex.ac.uk/faq
> List Post: <mailto:MacOSX-TeX at email.esm.psu.edu>
>
>
>
------------------------------------------------------------------------
Ross Moore                                         ross at maths.mq.edu.au
Mathematics Department                             office: E7A-419
Macquarie University                               tel: +61 +2 9850 8955
Sydney, Australia                                  fax: +61 +2 9850 8114
------------------------------------------------------------------------

--------------------- Info ---------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
& FAQ: http://latex.yauh.de/faq/
TeX FAQ: http://www.tex.ac.uk/faq
List Post: <mailto:MacOSX-TeX at email.esm.psu.edu>