我如何修改下面的命令来获取版本(问题:使用 xparse 进行递归多重下标和上标)不会水平堆叠子/上标,而是一起移动
喜欢
T_{bc}^{arf}
我试图删除,\object
但这没有用“双上标错误”
我不想改变命令语法(这样我就可以灵活地:-)!
\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}
答案1
您可以使用相同的命令获得这两种行为,只需使用 *-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}