TeX - LaTeX Asked on January 6, 2021
Which are the reasons not to always use newcommand{stuffa}{{STUFF}}
instead of newcommand{stuffb}{STUFF}
? In which cases would the former be a bad idea?
The reason I am considering doing this is to make the commands work e.g. in superscripts without extra curly braces, i.e., 2^stuffa
works while 2^stuffb
doesn’t (2^{stuffb}
does). These commands will not only be used in superscripts, though, and I’m interested in a more general answer anyway. (If e.g. xparse
provides a convenient solution to this problem, that would be interesting as well.)
I assume that this is a very basic question that has been answered many times, but I could not find an answer with a reasonable amount of research.
This question is related but does not answer my question.
The definitions are completely different, only add the extra group if you want an extra group
newcommandzzz{bfseries}
would make zzz
an alias for bfseries
and zzz this
would make a bold this
newcommandzzz{{bfseries}}
would do nothing useful as the font change would be in a group that ends immediately.
newcommandrecip{frac{1}}
would define a reciprocal function recip{4}
would typeset 1/4.
newcommandrecip{{frac{1}}}
would do nothing useful as recip{4}
would be {frac{1}}{4}
and raise an error about a missing argument for frac
.
The fact that having the extra group in the definition makes x^stuff
seem to work is an accident of the implementation and should not be used. The documented LaTeX syntax is always to brace superscripts.
In general it will change the spacing,
newcommandzzz{+}
will make zzz
act like +
newcommandzzzb{{+}}
will make zzzb
act like {+}
which isn't usually wanted, and gets no space compare
$1 zzz 2 zzzb 3$
Correct answer by David Carlisle on January 6, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP