Consider the following two macro definitions:



Although the two variants of \setmacro have a different \meaning they are equivalent in what they eventually do (if used correctly). In my opinion, the former definition is easier to read while the latter is more flexible and, possibly, more efficient. So which one should be preferred?

  • When such a decision is being made, it is worth thinking about using \let. It's not always possible to use \let in this case, but if it is, it might be the best compromise between efficiency and error checking (see Martin Scharrer's answer). Oct 7, 2012 at 12:07

1 Answer 1


The second form is indeed more efficient because the argument doesn't have to be read, inserted and read again (while the second read process is quicker), but only the first one is fully "stable".

Note that the second form would still allow a parameter text like \setmacro#1{foo #1 bar} which would expand to \def\macro#1{foo #1 bar}. In most cases you don't want that. Also it requires braces afterwards: \setmacro\foo would lead to \def\macro\foo which would read everything up to the next { as parameter text and then causes problems with error messages which are difficult to understand for an end-user. This case would work with the first definition.

If you define \setmacro as part of a class or package (like \title etc.) I would use the first version. The overhead is not meaningful on modern systems, especially if the set-macro is only used once or twice, but you are avoiding issues if the set-macro is used in a wrong or unexpected way.

  • Does your note about avoiding issues hold when \def\setmacro#{\def\macro}?
    – morbusg
    Jun 19, 2012 at 8:57
  • 5
    @morbusg: This would still cause an error if a user uses \setmacro\foo. Now you get a better error message, but still it doesn't work like some LaTeX users would expect it. Jun 19, 2012 at 9:00

You must log in to answer this question.

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