# Creating non-math mode substitutes for \overset and \underset not dependent on the amsmath package

I have been using \overset and \underset to stack text, e.g.:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\overset{\text{a}}{\text{b}}$ \\
$\underset{\text{c}}{\text{d}}$
\end{document}


The results seems better proportioned font size, line spacing, and baseline positioning than other solutions I have found for stacked text, however, recently, I found some incompatibilities between another package and amsmath.

• How can I create an alternative to these commands which does not use math mode, but otherwise has identical font sizes and proportions (so that the output is visually the same)?

I found the source code for \overset and \underset in amsmath.dtx:

\newcommand{\overset}[2]{\binrel@{#2}%
\binrel@@{\mathop{\kern\z@#2}\limits^{#1}}}

\newcommand{\underset}[2]{\binrel@{#2}%
\binrel@@{\mathop{\kern\z@#2}\limits_{#1}}}


It seems to be using some code for \limits to define the stacking, however, I can't find anything in the rest of the source of the amsmath package showing how \limits works or how to use it without first specifying math mode.

-
what's the package that conflicts with amsmath? – barbara beeton Jan 27 '12 at 14:24

\limits is a TeX primitive used in the specification of super- and subscripts for math operators.

You could still use math mode, but just force the arguments to be typeset in text mode via some manipulation of the original \overset and \underset definitions:

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath

\begin{document}
\mbox{}\phantom{Without}\llap{With} \verb|amsmath|: $\overset{\text{x}}{\text{a}}~\quad~\underset{\text{x}}{\text{a}}$

\makeatletter
\renewcommand{\overset}[2]{\ensuremath{\mathop{\kern\z@\mbox{#2}}\limits^{\mbox{\scriptsize #1}}}}
\renewcommand{\underset}[2]{\ensuremath{\mathop{\kern\z@\mbox{#2}}\limits_{\mbox{\scriptsize #1}}}}
\makeatother

\end{document}


In the above minimal example, the redefinition of \overset and \underset style sets the two arguments in math mode, although it is not required to be specified explicitly. Additionally, since you're not interested in a math mode application, the binary relation spacing has been removed.

-
Is it possible to just use the array option like: \begin{array}{c} \text{x}\\text{a} \end{array} – azetina Jan 27 '12 at 17:00
@azetina: Yes, and you can specify an optional argument to array as well, using \begin{array}[t]{c} for \underset and \begin{array}[b]{c} for \overset. However, the spacing will be different since the over/under placements are not limits; something that has to be corrected for. – Werner Jan 27 '12 at 17:04

How to implement a \textunderset macro and its companion \textoverset depends on your real necessities. Here's one that tries keeping the main text and the subscript aligned with each other, while avoiding clashes between ascendents and discendents

\documentclass{article}
\makeatletter
\def\dynscriptsize{\check@mathfonts\fontsize{\sf@size}{\z@}\selectfont}
\makeatother
\def\textunderset#1#2{\leavevmode
\vtop{\offinterlineskip\halign{%
\hfil##\hfil\cr\strut#2\cr\noalign{\kern-.3ex}
\hidewidth\dynscriptsize\strut#1\hidewidth\cr}}}

\begin{document}
Abc \textunderset{du}{axy} \textunderset{ud}{axy} def
\end{document}


-