[Tex/LaTex] Superscript and subscript together in text mode

subscriptssuperscriptstext-mode

I want to use super and subscript at the same time in text mode. I cannot use math mode because I created macros which only work in text mode.

I found this question: Vertically aligning textsuperscript and textsubscript together

But the suggested answer does not work because the width of the resulting text is based only on the subscript, if the superscript is longer the text overlaps with the content afterwards.

I created the following versions for longer sub / superscripts but i need them combined:

\documentclass{scrartcl}
\usepackage[english]{babel}

\def\SPSBbottom#1#2{\rlap{\textsuperscript{#1}}\textsubscript{#2}}
\def\SPSBtop#1#2{\rlap{\textsubscript{#2}}\textsuperscript{#1}}

\begin{document}

prefix\SPSBbottom{long}{1}text \\[1cm]
prefix\SPSBbottom{1}{long}text \\[1cm] % Working combination
prefix\SPSBtop{long}{1}text \\[1cm] % Working combination
prefix\SPSBtop{1}{long}text \\[1cm]

\end{document}

If I could place two text at the same place and the width is taken from the longer one than using \textsuperscript{#1 'and' \phantom{#2}}\textsubscript{#2 'and' \phantom{#2}} could work but I do not know how to do this.

Alternatively one could use the math form $A^{top}_{bottom}$ where top and bottom are in a nested normal mode (\text{} does not work). But I found no way to do this as well.

Thanks in advance 🙂

Best Answer

Duplicate the definition of \textsuperscript:

\documentclass{article}

\makeatletter
\DeclareRobustCommand{\textsupsub}[2]{{%
  \m@th\ensuremath{%
    ^{\mbox{\fontsize\sf@size\z@#1}}%
    _{\mbox{\fontsize\sf@size\z@#2}}%
  }%
}}
\makeatother

\begin{document}

X\textsupsub{ab}{c}X\textsupsub{c}{ab}X

\end{document}

Add \strut to the second argument if you prefer.

enter image description here

Related Question