9

I have made a class file. It defines commands for use in document files. I want to change some of the command names, but I also want old document files to work without changing them.

Here's an example to illustrate:

\begin{filecontents}{a.cls} 
\ProvidesClass{a}
\LoadClass{scrartcl}
\RequirePackage{scrpage2}
%
\def\commandnameA#1{\def\@commandnameA{#1}}
\commandnameA{}
%
\newpagestyle{a}{{}{}{A:\@commandnameA}}{{}{}{}}
\pagestyle{a}
\end{filecontents}
\documentclass{a}
\begin{document}
\commandnameA{test}
test
\end{document}

For this example I want to change "commandnameA" to "commandnameB" in the class file and have the document file work whether it contains \commandnameA{test} or \commandnameB{test}.

Any help is appreciated.

3 Answers 3

14

\let\commandnameB\commandnameA in your class file. Then the two macros are the same!

1
  • 6
    or \def\commandnameB{\commandnameA} if you want to keep both in sync even after \commandnameA got redefined. Apr 10, 2011 at 12:41
6

You may add a warning that \commandnameA is deprecated:

\def\commandnameB{%
  \commandnameA%
  \ClassWarning{yourclass}{Command \string\commandnameA\space is deprecated.%
  \MessageBreak Use \string\commandnameA\space instead.}%
}
4

Since \commandnameA and/or \commandnameB expect an argument, Tobi's solution should have been

\protected\def\commandnameB{%
  \ClassWarning{myclass}{Command `\string\commandnameA' is deprecated.
  \MessageBreak Use `\string\commandnameB' instead}%
  \commandnameA
}

I have added \protected because \commandnameB is not expandable.

3
  • It would be nicer if you could keep your answer self-contained and could avoid questions to the poster and others.
    – user10274
    Feb 21, 2012 at 1:30
  • @MarcvanDongen: Thanks. I have removed why?.
    – Ahmed Musa
    Feb 21, 2012 at 13:20
  • I didn't mean you should remove the question. I had hoped you could expand on it further. It would provide more insight and would improve the answer. That's all.
    – user10274
    Feb 21, 2012 at 13:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .