I want to use sub- and superscript together in text mode.
I've found this macro to solve the problem
\def\textsubsuperscript#1#2{\rlap{\textsubscript{#1}}\textsuperscript{#2}}
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?
Best Answer
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:
I refrained from using mathmode and
\text
because\textsuperscript
and\textsubscript
may have more complex implementations than it would seem (seerealscripts
, for example).