1

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:

expected

But instead, I get this:

actual

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

14
  • What's the advantage over typing \log_{zzz}^{yy}(x)?
    – egreg
    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
  • 1
    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.
    – egreg
    Sep 7, 2021 at 16:35
  • 1
    For an example of a non-trivial use of embellishments, see this answer: tex.stackexchange.com/a/602341/202780
    – Don Hosek
    Sep 7, 2021 at 16:41
  • 1
    @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).
    – Gaussler
    Sep 7, 2021 at 18:47

1 Answer 1

2

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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