I want to use sub- and superscript together in text mode. I've found this macro to solve the problem


But it doesn't works well when the subscript is long. In that case the subscript overlaps with the following character.

What could be the macro to enable sub- and superscripting in all cases?


3 Answers 3


We need to have enough space for the longest of the two sub-/superscripts. For that we can calculate the maximum of both sub-/superscripts' widths and make a box as wide as the maximum:


\usepackage{fixltx2e} % For \textsubscript






The result

I refrained from using mathmode and \text because \textsuperscript and \textsubscript may have more complex implementations than it would seem (see realscripts, for example).


It's just the same code as for \textsuperscript in the LaTeX kernel with subscripts added.

The result is the same as Andrey's.


An expl3-version:

\cs_new_protected:Nn \my_super_sub:nn
      \hbox_set:Nn \l_tmpa_box { \textsuperscript {#1} }
      \hbox_set:Nn \l_tmpb_box { \textsubscript {#2} }
        { \dim_max:nn { \box_wd:N \l_tmpa_box } { \box_wd:N \l_tmpb_box } }
        { \hbox_overlap_right:n { \box_use:N \l_tmpa_box } \box_use:N \l_tmpb_box }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .