I have a symbol, which I want to give a underscipt, subscript and superscript.

I tried:


But now I get a space between my symbol and the sub and superscript. Can this space be removed?

Or if someone knows a different method without any use of \DeclareMathOperator: you are more than welcome.

N.B. I tried many other things, with worse result.


Here's my proposal:


\makeatletter % access "private" commands
    \vrule height \ht\z@ depth \dp\z@ width \z@

$\wmat[2]_i^j$ $\scriptstyle\wmat[2]_i^j$ $\scriptscriptstyle\wmat[2]_i^j$


The centered subscript is always in \scriptscriptstyle so as to avoid it making for bad spacing.

enter image description here

The strategy is to define a math operator that accepts an optional argument for the centered subscript. However, this subscript should not influence the vertical size of the ‘w’, in order that the standard subscript and superscript are set to the letter.

So I typeset ‘w with the subscript’ twice, one with \wmat@false and one with \wmat@true. The first instance is used to make a phantom that has the same vertical size of ‘w with the subscript’, placed in a \mathop atom of its own. The second instance is also typeset in a \mathop atom; a \! between them removes the space that TeX adds between consecutive \mathop atoms.

I build a box containing ‘w with the subscript’ (details later); in the \wmat@false case this is used to make a vertical rule as high and deep as the box, with zero width. This will reserve the needed vertical space but produce no visible output. In the \wmat@true case the box is resized to have the same vertical dimensions as a plain ‘w’. This will be the last item that TeX will see and to which it will attach the _j^i items that follow.

Now how's the box built? I found that using \operatorname*{w}_2 places the subscript too far down below the ‘w’, so a different method is needed. I use the primitive TeX method for alignments. I open a \vtop, that is a box containing vertical material, with the reference point given by the top item inside it (it will be \mathrm{w}).

Inside the \vtop I build an \ialign (a wrapper around \halign with some initialization). This does a one column table, with no vertical space between rows (by \offinterlineskip) except the explicitly added \kern1pt. The top row contains, as said, \mathrm{w} in the needed size (via \mathpalette); the bottom row contains the subscript, always in \scriptscriptstyle.

The \vtop is assigned to a box register, so it is possible to access its dimensions (for typesetting the zero width rule in the \wmat@false case) or change them (for making it appear the same as ‘w’). Then the box is used in the \wmat@true case).

Information about \halign is found in the TeXbook or in TeX by Topic.

  • I'm not a TeX expert (but I have started on Knuth's book). Could you explain line by line what is happening? In particular I don't understand the function of @, and the second empty pair of brackets in \newcommand{\wmat}[1][]. Also it is not clear where xparse is used, because the documentations says it is a replacement for \newcommand, but I still see \newcommend. – Jens Wagemaker Jan 30 at 11:03
  • @JensWagemaker xparse is a relic of a previous attempt and is not needed here. I'll add some explanations. For the @, it is customary to use it in “private” command names, so as not to conflict with user level commands. – egreg Jan 30 at 11:15
  • @JensWagemaker I added some explanations. – egreg Jan 30 at 11:38
  • Can you explain what \wmat@false is? Because it looks like a control sequence, but the only control sequence that is defined until the first use of \wmat@false is \wmat. – Jens Wagemaker Feb 1 at 11:43
  • @JensWagemaker \wmat@false is defined by \newif\ifwmat@ and makes the conditional return false when used. Similarly for \wmat@true. – egreg Feb 1 at 11:47

You code generates a double subscript error. Perhaps what you want is this:

\[ \smash{\wmat_2}\mathllap{\phantom{\wmat}}_i^j \]

You might want to define a macro if you want to use this more than once.

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.