5

I have read in the official LaTeX2e for class and package writers guide (section 2.7.2 "Make it robust") that one should aim to use as many LaTeX commands as possible.

As an example, they suggest to use newcommand instead of def. Looking at the implementation of newcommand described in source2e it is easy to see that newcommand is just layer on top of def with additional features.

But what do I use instead of let? There are several sources that adress the difference between let and def already, and so my question is, is there a LaTeX equivalent that defines a macro to another macro at point of definition? In other words, I want to create a new macro storing the source code of another macro such that it becomes independent.

Consider this MWE:

\documentclass{article}

\begin{document}

\newcommand\A{A} % original A macro \A

\let\B\A % B macro is the same as A macro \renewcommand\A{} % A is now empty (but B is still the old A macro) \A

\renewcommand\A{\B} % A is now original A again \A

\end{document}

I am interested if there exists a LaTeX alternative to let, that replaces \let\B\A in the MWE. Something like \newcommand\B{\A} but instead of \B being the macro \A I want \B to be the source code of \A, so it won't get altered through a \renewcommand.

gyha4
  • 107
  • Note that "\A isn't now original A again" at your last step. The \A is macro which expands to \B and \B expands to A. But when you initializes \A at the beginning of your test then \A expands directly to A. – wipet Jun 30 '22 at 18:59

1 Answers1

7

There is no need to replace \let in your example, your \newcommands are simple. But if you define commands with an optional argument or robust commands then you should copy them with \NewCommandCopy (requires a rather current LaTeX) as that also copies the inner structure.

Ulrike Fischer
  • 327,261