When writing formulas regarding relativity, I often need to write tensor symbols where the ordering of the indices (in sub- and superscript) matters. That is, I want to have several sub- and superscripts with matching height. Ideally I would like to type

\[ T^\mu_\nu^\rho^\sigma_\eta \]

and get the same result as for

\[ T^\mu\vphantom{T}_\nu\vphantom{T}^\rho\vphantom{T}^\sigma\vphantom{T}_\eta \]

I imagine a solution where I make ^ and _ (math-)active to accomplish that, however I would need the height of the box preceding the first ^ or _. As I understand it, obtaining this (at least directly) is impossible, because TeX swallows the T before reading the ^ in my example. Is this accurate?

Is it possible to instead determine the height a sub- or superscript is lowered or elevated from within the sub-/superscript? That way I could save this height for the following sub-/superscripts.

Note: I do realize that this problem could easily be circumvented by placing a macro right before the tensor name and that that may be a cleaner TeX style. This question is more about the possibility of tweaking TeX to behave this way.


This is the job of the tensor package:





enter image description here


To make ^ and _ active throughout the document is asking for trouble. So here, I create two macros to be called in math mode when you wish to implement this special script mode:

  1. \specialscriptmode is a mode declaration which redefines ^ and _ to add empty groups prior to the scripting. This cures the double-super/sub-script problem. It does have the drawback that the script's vertical locations, while all uniform, are not determined by the height of the base. If that is important to the user, then for that we use

  2. \specialscript{<base>} which also will turn on the special script mode, but redefine ^ and _ to set the scripts relative to the proper height of the base. I noted that \vphantom was not sufficient for this purpose, and so had to rely on \left.\vphantom{<base>}\right. with suitable negative pre-kerning.

The macro \restorescriptmode is provided if someone needs to exit the special mode and return to the normal definitions of ^ and _. This will happen by itself upon leaving math mode, but may be needed if you need to restore definitions before leaving math mode.

\catcode`^=\active %
\catcode`_=\active %
\catcode`^=7 %
\catcode`_=8 %
\newcommand\specialscriptmode{\catcode`^=\active \catcode`_=\active }
\newcommand\restorescriptmode{\catcode`^=7 \catcode`_=8 }

enter image description here

  • I think I will go with something like your suggestion (with some additional tweaking to take care of the spacing drawbacks of your answer). You are right to point out that \vphantom{T} doesn't cut it (I should have checked). {\vphantom{T}} does, however (maybe simpler than \left. and \right.). – schtandard Nov 1 '17 at 19:34

You can use following six lines of macros and then you can put only \tensor prefix before tensor. No braces needed.


$\tensor Z^\mu_\nu^\rho^\sigma_\eta_\alpha $


Judging from the other answers, I guess that the answer to my actual question is that this is indeed impossible.

For my application however, there are possibilities to deal with this, as pointed out by the other answers.

  • If this is indeed your thought (I don't think this is the correct answer to your question), you can define this for every possible letter that could be a tensor: \begingroup\lccode`~=`T \lowercase{\endgroup\def~}{\maybetensor T} and then the character T made math active, and with \maybetensor defined in a way that works. – Manuel Nov 2 '17 at 7:53
  • @Manuel: No, I think you misunderstood. I do not want to change the character T (as the tensor could have any name). My question was if it was possible to determine the height and depth of the tensor name after the fact (i.e. within the definition of ^ and _). – schtandard Nov 2 '17 at 8:23

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.