# Subscript. Superscript. Middlescript?

What's the best way to vertically center inline text for both math and text modes?

Is there something similar to \textsuperscript for non-math mode?

• In math mode you have \vcenter{\hbox{..}} in text mode you have \raisebox{\dimexpr\depth-.5\totalheight+\fontdimen22\textfont2\relax}{..} (this one is from memory, I can't test it right now). Let's hope in the future \vcenter is extended into text-mode so we do not need to play with this kind of things… – Manuel Jun 18 '15 at 14:10
• @Manuel There's \textvcenter in TeX by Topic (12.6.8): \def\textvcenter{\hbox \bgroup$\everyvbox{\everyvbox{}\aftergroup$\aftergroup\egroup}\vcenter} – egreg Jun 18 '15 at 14:14
• @egreg Magicians existed long before I came to this TeX world, I see. – Manuel Jun 18 '15 at 14:20
• Thanks for the quick responses. I found the TeX by Topic resource, but my ignorance is limiting my ability to implement @egreg's solution. Do I just use \textvcenter{lipsum}? Is this built in, or do I need to define this macro in the preamble? I can't seem to get it working. – kgo Jun 18 '15 at 14:31
• After you add the definition that egreg posted you use it like the math mode one basically \textvcenter{\hbox{lipsum}}. – Manuel Jun 18 '15 at 14:34

It's a good occasion for illustrating a macro by Victor Eijkhout, that can be found in TeX by Topic, section 12.6.8; the advantage over directly using \vcenter is that \setbox<number>=\xvcenter{...} is possible.

The \midscript macro chooses a smaller size in (first level) subscripts or superscripts. It won't give good results in second level ones.

\documentclass{article}

% macro by V. Eijkhout in TeX by Topic
\makeatletter
\protected\def\xvcenter{%
\hbox\bgroup$\everyvbox{\everyvbox{}\aftergroup\m@th\aftergroup$\aftergroup\egroup}%
\vcenter
}
% The \everyvbox token list will be executed
% just after the { that follows \vcenter;
% the closing } will trigger the three \aftergroup tokens
• @kgo Eijkhout's macro allows \setbox0=\textvcenter{...} – egreg Jun 18 '15 at 15:01
• @egreg - I couldn't have said it more succinctly. :-) – Mico Jun 18 '15 at 15:08
• And \setbox0 just hides text? So Eijkhout's solution just adds a hiding functionality to 'middletext'? – kgo Jun 18 '15 at 15:08