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"
  • 4
    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

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.

| improve this answer | |

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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