2

Is there any package that fixes the height of tensor indices?

For example, I'd like to horizontally align indices in the following expression representing antisymmetrization of a and b,

\documentclass{article}
\linespread{1.5}\selectfont
\begin{document}
$e_i^{[a}q^{b]c}$
\end{document}

Is there any universal method not forcing me to use \phantom in each expression, like here?

\documentclass{article}
\linespread{1.5}\selectfont
\begin{document}
$e_i^{[a}q^{b]c}_{\phantom{d}}$
\end{document}
egreg
  • 1,121,712
Bilbo
  • 23

2 Answers2

5

You could either put a \mathstrut (a box with the height of the ( symbol) into the subscript of q

\documentclass{article}
\linespread{1.5}\selectfont
\begin{document}
$e_i^{[a}q_{\mathstrut}^{b]c}$
\end{document}

enter image description here

or you could adjust the superscript raise and subscript drop document wide

\documentclass{article}
\linespread{1.5}\selectfont
\everymath{
    \fontdimen14\textfont2=1.1ex
    \fontdimen17\textfont2=0.9ex
}
\begin{document}
$e_i^{[a}q^{b]c}$
\end{document}

enter image description here

Henri Menke
  • 109,596
2

Here's an implementation similar to what the tensor package does, but ensuring empty superscript or subscript is added at each stage.

\documentclass{article}
\usepackage{amsmath,xparse}

\ExplSyntaxOn
\NewDocumentCommand{\tensor}{mm}
 {
  #1
  \group_begin:
  \bilbo_tensor:w #2
 }

\cs_new_protected:Npn \bilbo_tensor:w
 {% start the recursion
  \peek_catcode_remove:NTF \c_math_subscript_token
   {
    \bilbo_tensor_sub:n
   }
   {
    \peek_catcode_remove:NTF \c_math_superscript_token
     {
      \bilbo_tensor_sup:n
     }
     {
      \group_end:
     }
   }
 }
\cs_new_protected:Nn \bilbo_tensor_sub:n
 {% typeset the subscript with a phantom superscript
  {}
  \c_math_subscript_token{#1}
  \c_math_superscript_token{\vphantom{d}}
  % look for a superscript
  \bilbo_tensor_sup:w
 }
\cs_new_protected:Nn \bilbo_tensor_sup:n
 {% typeset the superscript with a phantom subscript
  {}
  \c_math_superscript_token{#1}
  \c_math_subscript_token{\vphantom{d}}
  % look for a subscript
  \bilbo_tensor_sup:w
 }
\cs_new_protected:Npn \bilbo_tensor_sup:w
 {% look for a ^
  \peek_catcode_remove:NTF \c_math_superscript_token
   {
    \bilbo_tensor_sup:n
   }
   {% no ^, end
    \group_end:
   }
 }
\cs_new_protected:Npn \bilbo_tensor_sub:w
 {% look for a _
  \peek_catcode_remove:NTF \c_math_subscript_token
   {
    \bilbo_tensor_sub:n
   }
   {% no _, end
    \group_end:
   }
 }

\ExplSyntaxOff

\begin{document}

$\tensor{e}{_i^{[a}}\tensor{q}{^{b]c}}$

\end{document}

enter image description here

egreg
  • 1,121,712