9

I tried to define \th to put the letters "th" in superscript for ordinal numbers. LaTeX tells me that \th is already defined. How is it defined? Would it be really bad to redefine it?

  • 3
    Not as bad as using superscript "th" if you can avoid it. – jon Oct 13 '15 at 2:30
  • gonzalo has given the true answer. i just want to draw your attention to the definition of \nth in the tugboat macros (documentation here). this provides appropriate english ordinal indicators for numbers up to greater than 100. – barbara beeton Oct 13 '15 at 15:01
  • @jon I agree, but my coauthor Iikes superscripts. – dejongbrent Oct 13 '15 at 22:30
17

If you run

\documentclass{article}
\usepackage[T1]{fontenc}

\begin{document}

\meaning\th

\th

\end{document}

you get

enter image description here

\th is defined in the kernel as

\DeclareTextSymbol{\th}{T1}{254}

and produces the thorn (a letter in the Old English, Gothic, Old Norse and modern Icelandic alphabets, as well as some dialects of Middle English.)

Yes, it's in general a bad idea to redefine an already defined macro and even more a kernel one (with the possible exception, in some cases, that you know exactly what you are doing and why you are doing it); that's why \newcommand (unlike \def) checks to see first if the command is already defined. I'd suggest you to choose another name for your command (\Th, for example).

If you, however, insist on redefining \th (let's say you consider that you won't need the thorn and you are sure that your redefinition won't have undesired effects beyond suppressing access to the thorn), at least I'd suggest you to save the original definition first:

\let\oldth\th
\renewcommand\th{<your definition>}

In your particular case, place "th" for ordinals, you could use the fmtcount package:

\documentclass{article}
\usepackage{fmtcount}

\begin{document}

\ordinalnum{3}, \ordinalnum{4}

\end{document}

enter image description here

  • Thanks! One question though: Why do you use \let, but \renewcommand? Wouldn't \newcommand and \renewcommand be a more consistent combination? Would \let throw an error for an already-defined command? – dejongbrent Oct 14 '15 at 1:16
  • 1
    @dejongbrent You are welcome! Regarding your question, \let and \newcommand are essentially different. \let, as I used it in my example, makes a copy of a command; \newcommand defines a command. Those are different actions. In my code I made \oldth be a copy of \th; and then redefine \th; in this way, \oldth is still the thorn and \th will be whatever you had redefined it to be. – Gonzalo Medina Oct 14 '15 at 1:48
  • @dejongbrent In this concrete case I could've used \newcommand\oldth{\th}, but \let is more general. – Gonzalo Medina Oct 14 '15 at 1:52

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.