TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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). – Patrick Häcker Oct 7 '12 at 12:07
up vote 21 down vote accepted

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.

share|improve this answer
Does your note about avoiding issues hold when \def\setmacro#{\def\macro}? – morbusg Jun 19 '12 at 8:57
@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. – Martin Scharrer Jun 19 '12 at 9:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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