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}
  • Welcome to TeX.SE. You could use tensor package. – Sebastiano Apr 15 '19 at 7:15
  • You can give a look at Subscripts for primed variables. (Not an exact duplicate but the problem is basically the same.) – campa Apr 15 '19 at 7:44
  • @Sebastiano Thank you, however the tensor package is not working in this case. – Bilbo Apr 15 '19 at 8:10
  • @campa I've already provided a better solution above. I'm asking for a package that is positioning all the indices in all the expressions at once. – Bilbo Apr 15 '19 at 8:12
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

| improve this answer | |
  • The second answer is the solution to my question. Thank you! – Bilbo Apr 15 '19 at 8:22
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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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