# xparse embellishment not capturing all inside of braces

I am currently learning, playing with xparse, and have the following demo command partially working:

\let\oldlog\log
\RenewDocumentCommand{\log}{s m e{_^}}{%
\ensuremath{%
\mathrm{log}%
\IfValueT{#3}{_#3}%
\IfValueT{#4}{^#4}%
\IfBooleanTF{#1}{\!\left(#2\right)}{#2}%
}%
}


My issue is the current result. What I expect is that \log{x}^{yy}_{zzz} gives:

Why doesn't the embellishment argument, e{_^} capture the whole content in the braces for ^{yy} and _{zzz}?

• What's the advantage over typing \log_{zzz}^{yy}(x)? Sep 7, 2021 at 16:18
• @egreg In this case, nothing. I am just learning xparse, and this was easy enough to do. I spent 30 or more minutes wrapping my head around this issue with embellishments, thinking it was some kind of extra layer of complexity. Sep 7, 2021 at 16:28
• Just remember that the correct syntax for subscript and superscripts is always with braces, that sometimes can be omitted. More to the point, the braces around a mandatory argument are always stripped off by TeX and in this case you need to supply them back. Sep 7, 2021 at 16:35
• For an example of a non-trivial use of embellishments, see this answer: tex.stackexchange.com/a/602341/202780 Sep 7, 2021 at 16:41
• @DonHosek Well, it seems to me that most TeX gurus give the opposite recommendation. As you know, commands \left and \right don’t even give the delimiters \mathopen and \mathclose status. On top of that, \left...\right change the positioning of indices: \left(...\right)^2 vs. (...)^2. The interval ]–1,0] can be typed \mathopen]-1,0], or, preferably, via some command (e.g. via \DeclarePairedDelimiter, the interval package, or some custom solution; nobody will be surprised to learn that mine is based on semantex). Sep 7, 2021 at 18:47

Ooof I worked it out; Turns out you need _{#3} and ^{#4}.
\let\oldlog\log