1

Can I use xparse e-type arguments to redefine how subscripts and superscripts work for a command (e.g., make \mybeta put all sub/super scripts in parens)? I tried defining

 \NewDocumentCommand{\mybeta}{e_e^}{\beta_{(#1)}^{(#2)}}

And it seems to work fine if I place them in the order the arguments are specified but not when I try

 \mybeta^{n}_{s}

where I get a double subscript warning when I want $\beta^{(n)}_{(s)}$

I'm guessing that maybe I need to use e{_^} as the argument specification but if I do that how do I tell the _ and ^ arguments apart or recover them? Or is there a different/better way I should be going about this and I've misunderstood the embellishments entirely?

5
  • Use 'e{_^}' to specify the embellishments. It should "just work." Sep 5 '20 at 1:38
  • Huh, it does. That's so weird...so you never use multiple e arguments in specifying your command. Sep 5 '20 at 1:41
  • @PeterGerdes We tried a few ways to express how to have 'mixed order' arguments: the e{_^} one was by far the best
    – Joseph Wright
    Sep 5 '20 at 8:14
  • @JosephWright It's perfectly clear now that I understand it but I just assumed that it would be written as e{_}e{^} rather than e{_^} and I got lost when I tried to dig through the code. Thanks for your reply and the excellent work on xparse. I really love NDC Sep 6 '20 at 9:09
  • @JosephWright By the way is there any easy way to do arbitrary order delimited arguments, e.g., suppose I have exactly one ( ) argument and want it to be picked up wherever it appears. I don't suppose there is an easy way to do this (or the embellishments wouldn't be limited to picking up just the next unit (group? token?). And yes I know that's usually a bad idea but I'm translating math notation that already uses brackets, Sep 6 '20 at 9:21
4

The solution is, as you predicted, to use e{_^} in your argument specification. The order of the embellishments doesn’t matter. And yes, it’s amazing that it works!

2
  • Not quite what I predicted. I'd assumed that each e specification corresponded to one argument so e{_^} would scoop up whatever follows either an ^ or _ and assign it to #1. Guess not. Thanks , this is super useful. I'll leave my answer up since you commented on it. Sep 5 '20 at 1:46
  • 1
    I think we wrote them simultaneously! Sep 5 '20 at 1:47
1

Apparently (thanks to @LateXeraXeTal) you just use

 \NewDocumentCommand{\mybeta}{e{_^}}{\beta_{(#1)}^{(#2)}}

I admit I'm a bit confused as to why you don't use multiple e argument type specifiers to do this. Would one ever use multiple e type arguments?

2
  • I personally have not seen multiple e{} arguments used, but that doesn’t meant it’s not possible. Hopefully one of the LaTeX3 devs can comment. Sep 5 '20 at 1:45
  • I haven't tested this, but I think that if you did, e.g., \NewDocumentCommand{\foo}{e{^}e{_}}, you would be requiring the embellishments to come in that order. That being said, and again I haven't tested this, you could, theoretically do \NewDocumentCommand{\foo}{e{^}e{^}} and have two (optional) embellishments. Or you could allow embellishments in different places in an argument list with mandatory and optional arguments.
    – Don Hosek
    Jun 23 '21 at 3:03

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.