564

What is the easiest way to superscript text outside of math mode?

For example, let's say I want to write the $n^{th}$ element, but without the math mode's automatic italicization of the th. And what if I still want the n to be in math mode, but the th outside?

jamaicanworm
  • 29,114
  • 19
    See this column in TUGboat for information about not using a superscript "th" – egreg Mar 08 '12 at 22:41
  • 2
    @egreg TL;DR Why should I avoid using the ansber by Werner? – Bernhard Sep 19 '13 at 14:14
  • 2
    @Bernhard Too long? It's one column! … the use of the superscript form seemed to have disappeared around the 1940s and 50s — until its corpse was reanimated by Microsoft. Perhaps it had been lingering, zombie-like, in rural and provincial corners of Britain, North America, and elsewhere in the English-speaking world. – egreg Sep 19 '13 at 14:49
  • 1
    @egreg Sorry, saw three pages, but thanks for your quote :) – Bernhard Sep 19 '13 at 15:44
  • 9
    @Bernhard My summary is: it is an abbreviation style unique to English, people stopped using it because of the spread of typewriters where it looked bad and was cumbersome to produce and then Microsoft decided to bring it back. Thus we shouldn't use it. It seemed like a non-sequitur to me. – Eponymous Apr 14 '14 at 17:20
  • 69
    this is so typical of this community, you ask for vertical lines in tables or superscripts and people step up to tell you DONT because style. the writer of the TUGboat article is wrong in claiming superscript ordinal suffixes are solely a 'Victorian fetish' peculiar to English; his text, confessedly a 'rant', is riddled with loaded words like 'obscenity' and 'ilk'. in fact, superscript used to be common in many languages. The rant gives not a single reason, it's just a rant. – flow Dec 22 '14 at 14:51
  • 12
    @flow: I fully agree, in particular because the authors' claims about multi-letter suffixes and endings derived from the alphabetic form being unique to English are rather baseless. – O. R. Mapper Mar 06 '15 at 11:01
  • 27
    @flow I agree too. What I read in the article is: we used superscript form, until we started using clunky devices that couldn't handle it properly. My opinion: now that we have devices that can render superscript beautifully, let's use them again! – dr. Sybren Apr 02 '15 at 13:52
  • From the TeXbook exercise 18.27: »Incidentally, it is also acceptable to type ‘$n$th’, getting ‘nth’, in such situations; the fact that the n is in italics distinguishes it from the suffix. Typed manuscripts generally render this with a hyphen, but ‘n-th’ is frowned on nowadays when an italic n is available.« – Henri Menke Dec 11 '17 at 22:57
  • 1
    This is a forum about TeX, not English. The title of this post (and hence the people drawn to the question) is general, and not limited to the example given. Discussions about the peculiarities of English superscripts belongs elsewhere. There are languages that regularly use superscripts. For example ᓄᖅᑲᕆᑦ. – EBlake Oct 22 '20 at 21:26
  • FORTRAN used all caps for code for decades. Hardly a reason to say that lower case letters became obsolete in the 50's. The TUGboat article was written in the '05, perhaps the author stirred a pot that didn't exist, just to have an exciting lead. – ShpielMeister Dec 30 '20 at 09:44
  • 3
    I came here because I'm setting an antique text. Whether or not it's appropriate in contemporary texts is irrelevant. – digitig Mar 21 '21 at 16:09
  • 1

7 Answers7

814

You can use \textsuperscript{th}. It sets its contents in text mode and can be used in math or text mode.

Werner
  • 603,163
  • 1
    Actually, this only really works outside math mode. If I try $n^\textsuperscript{th}$, the superscript gets raised too high, creating an awkwardly large space between lines. But $n$\textsuperscript{th} works great--thanks! – jamaicanworm Mar 09 '12 at 00:49
  • 30
    @jamaicanworm: You should use $n\textsuperscript{th}$. – Werner Mar 09 '12 at 00:50
  • 29
    $n^\textsuperscript{th}$ is a double superscript. – Philipp Mar 09 '12 at 00:51
  • 3
    Right! Silly mistake... :) – jamaicanworm Mar 09 '12 at 00:52
  • 10
    @Werner: What is the difference between $n$\textsuperscript{th} and $n\textsuperscript{th}$? Is it the spacing at the end of the inline math environment or why, if else, do you prefer the second one? – strpeter Apr 30 '14 at 08:44
  • 2
    What is the difference between that and $n^\text{th}$? – Johannes Schaub - litb Nov 02 '17 at 21:13
  • 2
    @JohannesSchaub-litb: There is no difference in the output. \textsuperscript is a little lighter to manage (computationally), since \text can't assume you'll be in a superscript; you could be in any one of the 4 math styles. Nesting is also a tad easier with \textsuperscript since it functions in either text/math mode. \text sets it's content in text mode, and therefore nesting would require an explicit switch back to math mode in order to use a \scriptscript style... – Werner Nov 03 '17 at 00:18
  • 7
    Just as a side note: there's also \textsubscript{text}. – qwerty_so Jan 20 '19 at 16:11
  • @strpeter It was directly referring to the remark in the comment above, as in, jamaicanworm should use $n\textsuperscript{th}$ instead of $n^\textsuperscript{th}$. Pretty sure Werner didn't mean to imply that either of $n\textsuperscript{th}$ or $n$\textsuperscript{th} were better. – Egor Hans Dec 24 '19 at 09:25
67

For 99% of applications, Werner's answer is good enough. But since Marienplatz has offered a bounty, there presumably is interest in other ways to do this. So here, I show it done with a stack over a null entry. My preamble definition (output on the second line) appears to give the exact same result as \textsuperscript (output on the first line).

But then, I show how both the size of the script as well as the height of it can be simply changed with my stacking approach, shown in \footnotesize (and lowered) in the 3rd line of output, and in \tiny (and raised) in the last line.

While I stick just to the standard text font sizes, it would be trivial to instead use a \scalebox to get exactly the size of script text desired.

If there is a desire to place the script, not at a fixed elevation, but relative to the height of the character being scripted, that is easy too (just ask).

\documentclass{article}
\usepackage{stackengine}[2013-10-15]
\newcommand\textss[1]{\stackengine{.9ex}{}{\scriptsize#1}{O}{l}{F}{F}{L}}
\begin{document}
\noindent
a\textsuperscript{th}A\textsuperscript{th}\\
a\textss{th}A\textss{th}\\
\renewcommand\textss[1]{\stackengine{.7ex}{}{\footnotesize#1}{O}{l}{F}{F}{L}}
a\textss{th}A\textss{th}\\
\renewcommand\textss[1]{\stackengine{1ex}{}{\tiny#1}{O}{l}{F}{F}{L}}
a\textss{th}A\textss{th}\\
\end{document}

enter image description here

David Carlisle
  • 757,742
25

The old-school solution:

29\raise0.5ex\hbox{th}

(TeXbook, Chapter 11)

ben
  • 359
  • 3
  • 3
16

In ConTeXt, you can use

\high{th}

to get the superscripts in text mode.

Aditya
  • 62,301
12

I use $n^{\text{th}}$. It seems to work okay for me.

Natalya
  • 147
3

After experimenting with variations of \textsuperscript{} and the $n^{}$ math mode superscript with \footnotesize{} and \scriptsize{} (I needed smaller superscript), I found the \uplett{} macro from the phonetic package, thanks to Scott Pakin's The Comprehensive LaTeX Symbol List, (last updated January 2017). It uses a smaller font than \textsuperscript{}, and achieved a better top-right alignment than \footnotesize{$^{}$}, without the automatic italicization.

  • 1
    The question is not about how to change the fonts to suit your needs. For example, you could also \usepackage{relsize} ... a\textsuperscript{\smaller abc} which produces similar results to \usepackage{phonetic} ... a\uplett{abc}. – Werner Dec 11 '17 at 23:01
  • Thanks, I didn't know relsize! My initial question was halfway between jamaicanworm's and his comment on double superscript $n^\textsuperscript{th}$. In my case, as I was used to the italicized math mode, changing math mode for text superscript (assuming it's best practice for true text) made the text look heavier than I needed. Is \uplett{abc} more computationally intensive than \textsuperscript{\smaller{abc}}}? Is \mathrm{abc}a simpler fix since it does not involve an additional package? (unless it does). Thanks for your time. – Pier-Eric Chamberland Dec 12 '17 at 00:45
  • 1
    \mathrm doesn't require an additional package, but it's probably more intuitive to use \text (from amsmath) if you want to print text. I don't think there's much to consider in terms of computational complexity. One should rather consider the contextual syntax that's used and whether it makes sense while providing consistency across your document. By the way \smaller is a switch and doesn't take an argument; so it's {\smaller abc} and not \smaller{abc}. – Werner Dec 12 '17 at 00:56
  • Thanks, much obliged. I would remove those extra brackets in my comment but it is now locked. – Pier-Eric Chamberland Dec 12 '17 at 01:04
  • 1
    You could change your answer, because \footnotesize and \scriptsize are also switches and should be used the same way as shown for \smaller. – TeXnician Jan 02 '19 at 09:15
2

I use $^{\mathrm{th}}$ - the \mathrm command removes the math-mode formatting and leaves you with a superscript in the format of your text.

durbachit
  • 229
  • 4
    That does not work if the surrounding text is in italics (for instance). Mathrm will always produce upright text. The better solution is to use \text from amsmath which is shown in Natalya's answer. – TeXnician Jan 02 '19 at 09:12
  • 2
    Also, \mathrm ignores spaces between characters. $^{\mathrm{some text}}$ produces the same output as $^{\mathrm{sometext}}$. – ttsc Aug 22 '23 at 16:19