I would like to make a function \des{a}{b} that produces the following result:
\des{Q}{1} > Q_1\des{Q_c}{1} > Q_{c,1}
I have tried to adapt the code in this answer but I could not figure out how to put my second argument after the comma in the subscript.
This is the code I have produced:
\NewDocumentCommand\des{mm}{\csname riccardo_des:nn\endcsname{#1}{_}{#2}}
\ExplSyntaxOn
\cs_new_protected:Npn \riccardo_des:nn #1 #2 #3
{
\tl_set:Nn \l_tmpa_tl { #1 }
\tl_if_in:NnTF \l_tmpa_tl { #2 }
{ \tl_replace_all:Nnn \l_tmpa_tl { #2 } { \riccardo_dessb:n } }
{ \tl_put_right:Nn \l_tmpa_tl { \sb { #3 } } }
\tl_use:N \l_tmpa_tl
}
\cs_new_protected:Npn \riccardo_dessb:n #1
{ \sb { #1 , des } }
\ExplSyntaxOff
I want to substitute ,des in the line before the last with the second argument I pass to the \des function. How can I do this?





$\des{Q_c}{1}$, the comma betweencand1seems be both too small and placed too low. Any way to fix this? – Mico Jul 31 '18 at 19:02\mathbf. Not saying I can account for that, but just to point me in the right direction, should the<comma> 1be in\mathbf? – Steven B. Segletes Aug 01 '18 at 11:47\mathbfshould be wrapped around the outside, as in\mathbf{\des{Q_{ab}}{c}}– Steven B. Segletes Aug 01 '18 at 12:02\newcommandx{\myquantity}[4][1=, 2=, 3=]{\des{#3{\mkcomp{#1}{#2}}}{#2}}\newcommand{\mkcomp}[2]{\ifthenelse{\equal{#2}{}}{\mathbf{#1}}{#1}}– Simone Gaiarin Aug 01 '18 at 12:15#4appears not to be used, what is the meaning of the optional argument[1=, 2=, 3=]which makes no sense to me? Finally, what would be a typical or challenging usage example of\myquantity? – Steven B. Segletes Aug 01 '18 at 12:49\myquantitylogic. – Steven B. Segletes Aug 01 '18 at 12:57\myquantitycommand; I don't think that\newcommandxis the best way to go. – egreg Aug 01 '18 at 13:52$\des[\bar]{\psi_\alpha}{\delta}$works just fine. – Steven B. Segletes Aug 30 '18 at 15:33