This is a macro for producing vector length symbols. The mandatory argument m receives vector notations, which the optional argument o receives whatever should be added as subscripts if they are needed. However, the subscript notation does not seem to work, as the MWE below prints subscripts as if they were normal characters in the equation. Is the underscore character recognised as its own character and not an operator in xparse commands?
\documentclass[10pt]{article}
\usepackage{amsmath,xparse}
\newcommand{\abs}[1]{\ensuremath{\lvert #1 \rvert}}
\ExplSyntaxOn
\NewDocumentCommand \len { m o } {
\IfNoValueTF{#2} {
\ensuremath{\abs{\vec{#1}}}
} {
\ensuremath{\abs{\vec{#1}_{#2}}}
}
}
\ExplSyntaxOff
\begin{document}
\[ \len{f}[\text{s.max}]=\mu_s\len{F}[N] \]
\end{document}
I'd rather not use the t_ argument. I'm not going to use the optional argument for anything other than the subscript anyways, and adding _ every time I write a subscript is just way too many unnecessary _s.
\NewDocumentCommand \len { m O{} }{\ensuremath{\abs{\vec{#1}_{#2}}}}. Actually, I would define\NewDocumentCommand\len{ m O{} }{\ensuremath{\lvert\vec{#1}_{#2}rvert}}so that you don't have multiple\ensuremath's coming from\absand\len. – Jul 02 '19 at 04:59_has no special meaning in this example - expl3 syntax has not been activated. – Ulrike Fischer Jul 02 '19 at 06:14\ExplSyntaxOn...\ExplSyntaxOffaround theNewDocumentCommand...{}part. This would activate theexpl3syntax that provides special meaning for the underscore. Using\sb{...}would be the correct solution here, as a deleted comment had pointed out before. – Paul Kim Jul 02 '19 at 13:24^symbol is working fine as a superscript operator. Would that mean that said symbol can be used as a superscript even inexpl3syntax? – Paul Kim Jul 02 '19 at 13:26^will keep it's normal meaning also whenexpl3syntax is enabled. Btw, if you have found a solution that fixes your problem, you can also add an answer yourself and accept it. Otherwise I'd vote to close this question, as it seems to have been solved in the comments. – siracusa Jul 04 '19 at 01:18