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.

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

\newcommand{\th}{%
  \ifthenelse%
    {\equal{\previouscharacter}{1}}%
    {st}%
    {th}%
}

4\th and 21\th % would like to yield "4thand 21st"
share|improve this question
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

2 Answers 2

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:

\engordnumber{1} 
\engordnumber{12}
\engordnumber{123}

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

share|improve this answer

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.