Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Possible Duplicate:
Can I redefine a command to contain itself?

How can I redefine the same macro that uses the original macro?

\newcommand{\macro}{zzz}
\renewcommand{\macro}{xyz\macro}

(this results in an endless loop)

calling \macro should print xyzzzz. (I want to redefine some symbols)

share|improve this question

marked as duplicate by diabonas, Thorsten, lockstep, Peter Grill, Roelof Spijker Apr 10 '12 at 16:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

up vote 6 down vote accepted

Assuming that the macros don't have optional parameters you can use:

\newcommand{\macro}{zzz}
\let\OldMacro\macro
\renewcommand{\macro}{xyz\OldMacro}

If you wish to redefine a macro that has optional parameters, you have to use \LetLtxMacro from the letltxmacro package . A detailed description of \LetLtxMacro can be found at this question at closed square root symbol.

The MWE below yields:

enter image description here

\documentclass{article}

\newcommand{\macro}{zzz}
\let\OldMacro\macro
\renewcommand{\macro}{xyz\OldMacro}

\begin{document}
\verb|\OldMacro:| \OldMacro

\verb|\macro:| \macro
\end{document}
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.