Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

If I want to use abbreviations for second, third and so on in my LaTeX documents, I am currently doing this: 2$^{nd}$ which seems unsatisfactory. Is there a macro I'm missing? I'm sure I could define one myself, and it would be fairly easy. But this looks like something that should already have been covered...

share|improve this question

6 Answers 6

up vote 172 down vote accepted

You should not use math, when it is normal text. Use \textsuperscript instead: 2\textsuperscript{nd}. You can also define a shortcut for this, e.g.

\newcommand{\ts}{\textsuperscript}

Then you could use 2\ts{nd} in the text.

Edit:
An even nicer solution is to load the package nth with the option super and use the \nth command:

\nth{1}, \nth{2}, \nth{3}, \nth{4}
share|improve this answer
41  
+1 for the nth package –  Will Robertson Oct 14 '10 at 11:54
2  
That's what I'm talking about! I don't even have to think about whether it's "th" or "rd". Awesome. –  Seamus Oct 14 '10 at 12:43
    
Is \nth{<number>} guaranteed not to be hyphenated? –  Oh my ghost Feb 16 '13 at 12:48
    
@CodeMocker I think that would depend on your hyphenation rules. nth doesn't create a box for itself. I would never expect TeX to hyphenate such, though. –  Sean Allred Feb 3 at 19:20

I guess the quickest and easiest solution is to simply write "2nd", "3rd", etc.

Superscripts aren't really necessary.

share|improve this answer
52  
But where's the fun in that? Any chump can just write "2nd"... –  Seamus Oct 14 '10 at 12:40
13  
Unfortunately, sometimes life is a little bit boring – there are solutions that are both simple and correct. But as a consolation, bear in mind that most MS Word users will produce 2-superscript-nd accidentally, and they have no idea how to disable it. –  Jukka Suomela Oct 14 '10 at 12:49
13  
Bringhurst (I think) does recommend against using superscript ordinals. But it's nice to be able to \nth things automatically, especially in math mode. –  Will Robertson Oct 17 '10 at 3:30
8  
This is the correct answer! Remember that English is not French and does not put st, nd, th into superscripts! –  tohecz Oct 24 '12 at 11:48
1  
I read somewhere that the superscript ordinals were usually used by British in the 19th century. I see still here and there. May be this was a foreign influence, but why this changed in the 20th century? To adapt to the preferences of The Chicago Manual of Style or simply because many documents were created with typewriters where it was easier put inline ordinals?. In Spanish there are an undisputed reference for this kind of conventions (the Real Academia Española) but what about English? –  Fran Jan 11 '13 at 10:58

An alternative to nth package is fmtcount.

In this case the command is \ordinalnum. By default the ordinal is formatted as superscript, but this is optional, as it is also in nth:

\usepackage{fmtcount} % equivalent to \usepackage[super]{nth}
\usepackage[level]{fmtcount} % equivalent to \usepackage{nth}

But there are some advantages over nth:

  1. Limited multilingual support (English, French, Spanish, Portuguese, German and Italian). For example, in a Spanish document \nth{3} is formatted incorrectly as "3th" but \ordinalnum{3} is rendered almost correctly as "3º" (see addendum).

  2. Optional gender. For example \ordinalnum{3}[f] produces in Spanish the feminine ordinal "3ª" (tercera). There is also a neuter option (n). By default the gender is m (masculine).

  3. Is if possible switch between raise and level versions of ordinals in the same document (I can't imagine why, but who know!) with \fmtcountsetoptions{fmtord=raise} or \fmtcountsetoptions{fmtord=level}

  4. For English-only users, obviously (1) and (2) features are useless, but the ftmcount package has also many other ordinal commands, as \ordinal{counter} or \ordinalstring{counter} to print a counter as section as an ordinal ("3th") or as textual ordinal ("third") and more.

A third package, engord, also print numbers (\engordnumber{12}), counters (\engord{page}) and can switch between styles with \engordraisetrue or \engordraisefalse, but there are not multilingual or gender support.

On the other hand, for enumerated lists you can use the moreenum package with the labels \raisenth or \levelnth. A MWE:

\documentclass{article}
\usepackage{moreenum}
\begin{document}
\begin{enumerate}[label=\raisenth* --- ,start=1]
\item one
\item two
\item three
\end{enumerate}
\end{document}

Addendum: Ordinals in Spanish.

Although often not used, according to the RAE there must be a dot before the superscript, as in any abbreviation ended with a superscript as explained here. Then, the correct ordinal is "3.o" (tercero) or "3.er" (tercer) but not "3º".

In most cases one can just typing 1.º or 1.ª because is Spanish keyboards there are a key for the º ª \ symbols. However, the problem remain with numbers that can be ended by .er (1,3,13,21,23,31,33,etc.). Moreover, in some fonts the º and ª symbols are underlined (as in the keyboard), that it is correct in Spanish, but can produce inconsistencies if one type, for example, 1º,2º,3\textsuperscript{er},4º. Another problem is that these symbols are only in lower case even using \MakeUppercase.

The babel package take care of the format of Spanish abbreviations with a superscript suffix, and thus with the spanish option one can use n\sptext{os} to obtain for example n.os ("numbers" in plural), but moreover provide a shorthands for masculine and femenine ordinals (also in uppercase) using " which is not used in LaTeX for quotes. In this way, instead of 1\sptext{er} on can use just 1"er for example. In summary:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{bera}
\usepackage[spanish,es-noindentfirst]{babel}
\begin{document}

\subsubsection*{Lowercase}

1º, 2º, 3º ... 1ª, 2ª, 3ª \dotfill 
Keyboard input, incorrect (no dots). \\
1.º, 2.º, 3.º ... 1.ª, 2.ª, 3.ª 
\dotfill Keyboard input, correct but underlined.\\ 
1\sptext{o}, 2\sptext{o}, 3\sptext{o} ... 
1\sptext{a}, 2\sptext{a}, 3\sptext{a} 
\dotfill With Babel \verb|\sptext{}| command.\\
1"o, 2"o, 3"o ... 1"a 2"a 3"a \dotfill 
With "\ Babel shorthand.\\
1"er 2"o 3"er ... 1"a 2"a 3"a 
\dotfill Apocopate version (primer, tercer, etc.).

\subsubsection*{Upppercase}

\MakeUppercase{1.º, 2.ª, 3.\textsuperscript{er}} ...  
or ... 1.º, 2.ª, 3.\textsuperscript{ER}  
\dotfill (wrong way)\\
1"o 2"a  3"er  $\neq$ \MakeUppercase{1"o 2"a  3"er ... }  
or ...  1"O 2"A  3"ER 
\dotfill (babel way, correct)

\end{document}

MWE

share|improve this answer
2  
The moreenum package actually just uses fmtcount at bottom. (I wrote the package: it's nice to see that a question I asked prompted my to write a package which then became an answer to that question.) –  Seamus Jan 10 '13 at 11:14
    
@Seamus, I knew from the moreenum that load fmtcount and even that the author read this site (egreg quote) but I did not realize that your username is the name of the author! Is the danger of answer in this site: May be you're trying to give a lesson to the teacher! X-D –  Fran Jan 10 '13 at 14:40

If you are using ConTeXt MkIV, you can even imitate the automatic conversion of MS Word:

\usemodule[translate]
\translateinput[2nd][2\high{nd}]
\enableinputtranslation

\starttext
On the 2nd of November \unknown
\stoptext

This will translate all 2nd into 2\high{nd}.

share|improve this answer
1  
Neat. How does this \translateinput work? It looks like XeTeX's input mapping but it must occur earlier in the processing. –  Will Robertson Oct 17 '10 at 3:28
    
I am not 100% sure on how it works. The translate module just registers a "user" filter. Looking at the source, this is how I understand what is happening. The input file is read line by line and first the input translation (encoding regimes and such) is done, then unicode translation (collapsing characters, etc) is done, and finally user translations are done. All this is done in the openers.textopen function in data-tex.lua file. –  Aditya Oct 17 '10 at 7:38
    
Is it possible to implement \translateinput in LaTeX as well? Might come in handy. –  marczellm Jan 10 '13 at 10:11
    
@marczellm: Since \translateinput is based on luatex, it is possible to implement it in LuaLaTeX. But I don't know how easy it will be to translate the ConTeXt code to LaTeX. –  Aditya Jan 10 '13 at 20:24

If you're after speed when writing, this solution seems to be the quickest to type

\documentclass{article}
\usepackage{xspace}

\newcommand\nd{\textsuperscript{nd}\xspace}
\newcommand\rd{\textsuperscript{rd}\xspace}
\newcommand\nth{\textsuperscript{th}\xspace} %\th is taken already
\begin{document}
This is the 2\nd of December. Or the 4\nth of July. Or 3\rd place in a race.
\end{document}

The \xspace command intelligently decides whether there should be a space after the macro or not.

MWE

share|improve this answer
3  
For maintain the space when appropriate you can use the package xspace. There are several questions about this package in the corresponding tag. –  Fran Jan 10 '13 at 23:06
    
Thanks! Edited my answer to include xspace. –  Nathanael Farley Jan 11 '13 at 8:51
    
I know this answer is quite old, but the question Drawbacks of xspace is maybe worth to have a look at … –  Tobi Dec 12 '13 at 13:35
    
Which drawbacks? \xspace works in both normal and math mode. –  Nathanael Farley Dec 12 '13 at 22:22
    
This is my preferred approach as it makes the source code far nicer to read. Who wants to read \nth{4}? –  Daniel Buckmaster May 6 at 3:04

Although this question is quite old and has very good answers, I think that maybe there are other people as type-lazy as me, who might appreciate my approach.

Edit: In response to egreg's comments, I wanted to adapt my answer - but the proposed changes would mean that the answer coincides with Nathanael Farley's answer, except for the fact that I redefined \th. egreg strongly cautions about compatibility issues with actually typing þ when redefining \th - use at your own risk.

In the interest of completeness, here's my original answer, which distinguished between math mode and text:

\documentclass{article}

\usepackage[english]{babel}
\usepackage{xspace}
\usepackage{mathtools} % only for \binom

\let\thorn\th % so that thorn-rune \th is not lost
\renewcommand{\th}{%
    \ifmmode% math mode
        ^\mathrm{th}%
    \else%
        \textsuperscript{th}\xspace%
    \fi%
}
% similar commands for \st \nd \rd (which are unoccupied)

\begin{document}
Works both in text (5\th, {\it 2\nd}, {\bf 1\st}, {\sf 3\rd})
and math mode $\displaystyle \left(
5\th, \, \binom{n}{5}\th, \, \sum_{1\st}^{n\th}\right).$
\end{document}

th-demo

This variant will always print upright letters in math mode, instead of adapting to the ambient text style. For a variant that adapts to the ambient style (e.g. italics in theorem environments, use \textsuperscript without distinguishing cases, see Nathanael Farley's answer).

I can imagine that someone might consider an exponent hidden in a macro bad form, but then, cases like n^2\nd seem far-fetched (and ugly), and I think it's obvious to anyone using LaTeX that this would need to be grouped. For powers, I guess I would prefer the inconsistency of $n^2$-th to $(n^2)\th$ anyway. These kinds of questions seem to be a hotly debated topic, see http://english.stackexchange.com/q/36512.

As a side note, I first tried to build an automatic \th which reads the previous character along the lines of How to find the previously printed character?, but managing \lastbox and the other primitives turned out to be way above my head. Also, even if this worked, writing 1\th is really not much quicker than writing 1\st (using the above), whereas the latter one is much more intuitive.

share|improve this answer
    
Even though it only an example, and my comments are not important, I can't help myself. (1) I don't see why is everyone so obsessed with \xspace, but it's your personal preference, just be sure that it's frowned upon in some journals. (2) You should definitely never need ordinals inside math. (3) Don't use \left(...\right), especially not for sums and integrals. Better try \biggl(...\biggr). (4) Many copy editors with change 1\st to 1st anyways (i.e., no superscript), so why all the fuss ... –  tohecz Dec 11 '13 at 16:03
    
Thanks for the comment. Short responses in order: (1) I have no experience with other solutions that avoid gobbled spaces, but am open to everything that works. (2) The math-examples are contrived, but $(n_1+1)\th$ isn't, and if the brackets are larger than the base size the superscript wouldn't be positioned correctly. Also, it's a compatibility precaution. (3) This was purely for bracketing the examples without overloading the MWE, I usually use \DeclarePairedDelimiter from mathtools (which are nicely scalable to the desired size). –  Axel Dec 11 '13 at 16:24
1  
Redefining \th is a very bad idea. Try using UTF-8 encoding and type a þ in your document. Of course, simply using \textsuperscript in every case is easier. And, finally, no: th shouldn't be superscripted. –  egreg Dec 12 '13 at 10:44
    
Duly noted. I can see the reason to avoid redefining \th, but since I have never encountered (let alone used) the rune in question, I felt comfortable in taking this risk. Do you know of any package which uses this internally? You're right about needing no disambiguition if both are to be set in the ambient textstyle, but I like having the possibility of treating them differently (also I wasn't sure what xspace would do in math mode). Lastly, superscripting or not comes down to personal preference (various style guides notwithstanding), otherwise there wouldn't be interest in the question. –  Axel Dec 12 '13 at 11:19
    
@Axel Please, use the @ mechanism to answer comments, so a notification is issued. Since \textsuperscript{th} in math mode does ^{\mbox{\fontsize\sf@size\selectfont #1}}, it seems useless doing \mathrm{th} in that case. So doing \newcommand{\nth}{\textsuperscript{th}} does better than the complicated macro you're using. Add \xspace, if you prefer; in math mode it does nothing. –  egreg Dec 12 '13 at 11:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.