# How do I reuse a command name?

I like to give my commands names that correspond to their meaning rather than symbols they produce. For example, I would like to use the symbol `\amalg` to denote binary coproducts and `\coprod` to denote coproducts indexed by arbitrary sets, but I would like to call them `\coprod` and `\bigcoprod` respectively. If I try to write

``````\newcommand{\bigcoprod}{\coprod}
\renewcommand{\coprod}{\amalg}
``````

then the first line interprets `\coprod` as already redefined by the second line and in the effect both `\bigcoprod` and `\coprod` produce the same symbol `\amalg`.

How can I give a new meaning to `\coprod`, but in the same time retain access to its original meaning in order to rename it to `\bigcoprod`?

-
You are probably looking for `\let\bigcoprod\coprod`. – Ulrike Fischer Nov 21 '12 at 14:24
– Qrrbrbirlbel Nov 21 '12 at 14:34
Thank you, this works. Could you point me to some straightforward explanation of the difference between `\let` and `\newcommand`? – Karol Szumiło Nov 22 '12 at 8:22
Heiko Oberdiek additonally wrote the package `letltxmacro`. Cite of documentation abstract: “TeX’s `\let` assignment does not work for LaTeX macros with optional arguments or for macros that are defined as robust macros by `\DeclareRobustCommand`. This package defines `\LetLtxMacro` that also takes care of the involved internal macros.” – Speravir Dec 3 '12 at 0:16

This is a well known "chicken and egg" problem. If you do

``````\newcommand{\bigcoprod}{\coprod}
\renewcommand{\coprod}{\amalg}
``````

then calling `\coprod` will be good, while calling `\bigcoprod` would produce `\amalg` again. The fact is that macros defined with `\newcommand` are simply substituted by their replacement text:

``````\bigcoprod -> \coprod -> \amalg
``````

Finally, `\amalg` is not a macro, but an instruction to print a certain mathematical symbol.

What you need is to "freeze" the meaning of `\coprod`:

``````\let\bigcoprod\coprod
``````

is what you're looking for: the meaning of `\bigcoprod` is now the same as the meaning `\coprod` has at the moment `\let` is executed. If later `\coprod` is assigned a new meaning, `\bigcoprod` will not change. So the correct way to proceed is

``````\newcommand{\bigcoprod}{}
\let\bigcoprod\coprod
\renewcommand{\coprod}{\amalg}
``````

The first line is a safety measure against the possibility that some package loaded earlier defines `\bigcoprod`. If this happens, you'll know it when the provisional `\newcommand` is executed. The second line will immediately change the meaning of `\bigcoprod` to what's desired. Indeed, `\let` doesn't check whether the command has already a meaning. Something like `\let\box\square` would be disastrous, if one doesn't take the precaution of testing whether `\box` is defined (it is, and it's a very important internal command of TeX that mustn't be redefined).

There are some risks in using `\let`, however, in case the command to be "frozen" has a special definition, namely it was introduced to LaTeX by means of `\DeclareRobustCommand` or variations thereof, or it has been defined via `\newcommand` with an optional argument.

The `letltxmacro` package comes to the rescue and its macro `\LetLtxMacro` should be used whenever one has the slightest doubt about the command to be "frozen". The syntax is just the same:

``````\usepackage{letltxmacro}
\newcommand{\bigcoprod}{}
\LetLtxMacro\bigcoprod\coprod
\renewcommand{\coprod}{\amalg}
``````

In this particular case the package is not really needed: "simple" math symbols can always be treated with `\let`. In other cases `\LetLtxMacro` can be a life saver.

-
I didn't check this question for a while so I didn't notice your answer, but that's exactly the kind of explanation I needed. Thanks! – Karol Szumiło Dec 12 '12 at 7:33