I'm interested in defining a macro to deprecate other macros. The system on which we are working goes through a lot of refactorings and is used by more than a couple people, so we want to be able to mark a command as deprecated before it is removed from the macros file entirely. Specifically, I'd like to generalize

\renewcommand{\foo}{\warn{Deprecated command used}\fooDeprecated}

or, for that matter, anything else that will work as a simple LaTeX proxy macro (in the design pattern sense of the word "proxy"). Unfortunately, I can't seem to figure out where to stick the \expandafter magic to make this work. That is,

    \let\csname #1Deprecated\endcsname\csname #1\endcsname%
    \renewcommand{\csname #1\endcsname}{\warn{Deprecated command used}\csname #1Deprecated\endcsname}%

clearly doesn't work. Is there a better way to do this? If not, how do I figure out how to expand these things?


  • Excellent, thanks. :) I didn't realize that this functionality was already provided. – Zach May 29 '13 at 14:19

The package amsmath does something like you want for the primitive \over and its siblings.

Define two helper commands:

  % #1 is the deprecated command
  % #2 is the new command to use
  % Issue a message at first usage
    Deprecated command \@backslashchar#1;\MessageBreak
    \protect#2\space should be used instead\MessageBreak
  % globally redefine "\#1" to "\deprecate@#1"
                         \csname deprecated@#1\endcsname
  % issue the old command

  \expandafter\let\csname deprecated@#1\expandafter\endcsname\csname#1\endcsname

Then you can give a list of the deprecated commands along with the new ones:


(notice that the deprecated command should be used "by name" in the first argument).

In the document, the first usage of \foo will type on the terminal and in the log file

Package zach Warning: Deprecated command \foo;
(zach)                \newfoo should be used instead
(zach)                 on input line 28.

whilst subsequent usages will not produce messages any more.

  • More or less what I was about to post but I have been too slow apparently :) – cgnieder May 28 '13 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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