I want to parse subscripts and superspricts using expl3 for which I used \def before:
\documentclass{article}
\usepackage{expl3}
\ExplSyntaxOn
\cs_new:Npn \l__parsing_parse_superscript:n ^#1 {superscript = #1}
\cs_new:Npn \l__parsing_parse_subscript:n _#1 {subscript = #1}
\NewDocumentCommand\parsesuperscript{}{\l__parsing_parse_superscript:n}
\NewDocumentCommand\parsesubscript{}{\l__parsing_parse_subscript:n}
\ExplSyntaxOff
\begin{document}
\noindent
\parsesuperscript^10\
\parsesubscript_100 % TODO error
\end{document}
The superscript gets parsed correctly. However for the subscript an error occurs, probably because after \ExplSyntaxOn the underscore is treated as a letter. I also tried \c_underscore_str and \c_math_subscript_token instead of _ in the command definition. How can the underscore be escaped for parsing a subscript? Or are there other solutions for parsing arguments with expl3 that should be prefered?
References:
<command>^#1and<command>_#1should be denoted:w(for “weird”) rather than:n. – Gaussler Aug 23 '21 at 17:23