Search:   Help

Navigation

Groups

LyX documentation

Edit

Shared groups

Links

TheLetTrick

Categories: Tips
<< | Page list | >>

Redefining a Command While Keeping the Old One

It is very common for people to want to redefine a LaTeX command while keeping the old one around, perhaps because they want to use the old one in the definition of the new one. Thus, for example, you might want to redefine the \footnote command so that it printed something in the margin, but you still want it to make a footnote, too. It turns out that this is very easy to do with the raw TeX command:

\let\oldfoot\footnote

Now \oldfoot is whatever macro \footnote was at the time this command was given. So now you can say:

\renewcommand\footnote[1]{\newstuff\oldfoot{#1}}

Note that this is different from:

\newcommand\oldfoot{\footnote}

That will not do what you want, because \oldfoot will simply be replaced by \footnote, and then you have a circular definition.

Steve Litt also points out:- What they forget is this, which is often very necessary because every environment has its own "end" environment:

\let\endoldfoot\endfootnote

Without that, an environment whose "end" part actually does something will either do the wrong thing or fail. It's rare, but I've seen it happen.

Also, the hint above works well if you want the new functionality to come before the original, after the original, or both. Where if fails is if you want to insert something in the middle of the original.

Tips

Edit - History - Print - Recent Changes - All Recent Changes - Search
Page last modified on 2010-06-07 17:53 UTC