Last modified on 14 June 2011, at 23:26

TeX/let

SynopsisEdit

\let <new-command-name> <original-command-name>

DescriptionEdit

\let allows you to copy the content of a command into a new command.

Unlike making a macro that calls the original command, \let allows you to subsequently modify the old command while still retaining its functionality under the new command. It is often used to change the behaviour of an existing command (but not replace it entirely). In such cases \renewcommand may fail, and \let may be required.

ExamplesEdit

If one wanted to change the behaviour of a command \foo wherever it was called, such that \bar were executed first, the following may seem appropriate.

\renewcommand{\foo}{\bar\foo}

This, however, will create a recursive loop where calling \foo will repeatedly call itself until the computer's memory is exhausted.

In order to change the behaviour of \foo to include some other behaviour, the \let command is used:

\let\originalfoo\foo
\renewcommand{\foo}{\bar\originalfoo}

The first line copies the contents of the \foo command into the new command \originalfoo. The second line modifies the \foo command to execute \bar followed by the original contents of the \foo command (which are now stored in \originalfoo).