TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to find the previously printed character in LaTeX? E.g:


4\th and 21\th % would like to yield "4thand 21st"
share|improve this question
Nice question! Nevertheless, this answer may be of interest to you. – lockstep Mar 13 '11 at 17:26
@lockstep: Actually, I just read that question and thought: wouldn't n\th look better than \nth{n}? – Tim N Mar 13 '11 at 17:30
@Tim: n\th would gobble any space that follows in the text, so ... probably not. ;-) – lockstep Mar 13 '11 at 17:33
Ah well, with some minor modifications then. – Tim N Mar 13 '11 at 17:34
I'm not sure how this would work. TeX wouldn't know that it would need to remember the character before until after it has read it... – Seamus Mar 13 '11 at 18:05
up vote 8 down vote accepted

The answer, unfortunately, is no. TeX contains a few primitives that modify things before them (\over, \atop, \above and the withdelims variants), but nothing general purpose.

In addition to the various packages which implement printing ordinal numbers, I wrote a fairly straightforward macro that does this here.

share|improve this answer
I know nothing about \lastbox, but could it conceivably be used to do that? – Bruno Le Floch Mar 13 '11 at 23:21
@Bruno: alas, my experience as recorded in the following discussion suggests not: tex.stackexchange.com/questions/6183/…. – Ryan Reich Mar 14 '11 at 4:14

As to the specific application in question, there's the engord package. Examples:


return 1st, 12th, and 123rd. For the specific question, I can't answer.

share|improve this answer

Your Answer


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.