Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I modify the command below to obtain a version (of the question: recursive multiple subscript and superscript with xparse) which does not stack the sub/superscripts horizontally but moves all together

like

T_{bc}^{arf}

I tried to remove the \object but this did not work "double superscript error"

I don't want to change the command syntax (so that I am flexible :-)!

\documentclass{article}
\usepackage{xparse}
\NewDocumentCommand{\tensorkor}{m >{\SplitList{,}}O{}}
 {\begingroup
  \mathsf{#1}%
  \newcommand\object{\vphantom{\mathsf{#1}}}%
  \ProcessList{#2}{\dotensorkor}%
  \endgroup}
\NewDocumentCommand{\dotensorkor}{m}
 {%
  \object#1%
 }
\begin{document}
$\tensorkor{T}[^a,_b,_c,^r,^f]$

what I want is $T_{bc}^{arf}$
\end{document}

enter image description here

share|improve this question
    
So you'd like that \somemacro{T}[^a,_b,_c,^r,^f]$ produces the same result as $\mathsf{T}^{arf}_{bc}$? –  egreg May 10 '13 at 14:10

1 Answer 1

up vote 4 down vote accepted

You can get both behaviors with the same command, just using a *-variant:

\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\tensorkor}{ s m O{} }
 {
  \IfBooleanTF{#1}
   { \gabriel_nonstacked:nn { #2 } { #3 } }
   { \gabriel_stacked:nn { #2 } { #3 } }
 }

\cs_new_protected:Npn \gabriel_stacked:nn #1 #2
 {
  \mathsf{#1}%
  \clist_map_inline:nn { #2 }
   {
    \vphantom{\mathsf{#1}} ##1
   }
 }

\tl_new:N \l_gabriel_sup_tl
\tl_new:N \l_gabriel_sub_tl

\cs_new_protected:Npn \gabriel_nonstacked:nn #1 #2
 {
  \tl_clear:N \l_gabriel_sup_tl
  \tl_clear:N \l_gabriel_sub_tl
  \clist_map_inline:nn { #2 }
   {
    \gabriel_decide:Nn ##1
   }
  \mathsf{#1}\sp{\l_gabriel_sup_tl}\sb{\l_gabriel_sub_tl}
 }

\cs_new_protected:Npn \gabriel_decide:Nn #1 #2
 {
  \token_if_math_superscript:NTF #1
   {
    \tl_put_right:Nn \l_gabriel_sup_tl { #2 }
   }
   {
    \tl_put_right:Nn \l_gabriel_sub_tl { #2 }
   }
 }

\ExplSyntaxOff
\begin{document}
$\tensorkor{T}[^a,_b,_c,^r,^f]$

$\tensorkor*{T}[^a,_b,_c,^r,^f]$
\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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