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

As I know, in the command sequence \the\year, \year gives a number, and \the converts it to text.

What I don't understand is, how to make a command that results in a number but not a piece of text representing that number, like the command \year?

In other words, if I want \theXXX to generate "1234" (without quotes), what do I replace XXX with?

share|improve this question
I'm not quite clear on what you mean here. \the\year yields the year as a number (currently "2011"), while \year may be used directly in places where TeX expects a number. Perhaps you mean the fact that \year is similar in effect to a TeX count register? – Joseph Wright Nov 21 '11 at 13:24
@JosephWright: Hope the edit helps explaining my question. – hpsMouse Nov 21 '11 at 13:36
are you thinking of \value{XXX} (where XXX is the counter name)? or are you not actually using latex? – wasteofspace Nov 21 '11 at 14:07
@Anon: I found \value{XXX} is what I'm looking for. I'm new to latex. Sorry if my question looks stupid. – hpsMouse Nov 22 '11 at 0:33
up vote 5 down vote accepted

This question appears to be more about accessing a counter's value than dates. whlt3 has provided some details on that. Here is an example based on What is the proper method of accessing a counter?.


You declare a counter with \newcounter{XXX}, set the counters value with \setcounter{XXX}{1234}. Then you can access it as \theXXX, or \the\value{xxxx}, and both produce the same output:

enter image description here

You can change the desired formatting of the counters output via \renewcommand{\theXXX}{\Roman{XXX}}, after which \theXXX results in the counter's value being displayed in roman numerals:

enter image description here

This technique is often used to change the style of chapter/section, etc... numbers. See for example Roman numerals for sections and subsections.


If you are interested in specifically formatting and manipulating dates, you should consider



\textbackslash{}theXXX yields \theXXX\par
\textbackslash{}the\textbackslash{}value yields \the\value{XXX}

\textbackslash{}theXXX yields \theXXX\par
\textbackslash{}the\textbackslash{}value yields \the\value{XXX}
share|improve this answer

\year does not just give a number; it gives an internal integer. This is one of the types of integers that TeX knows. Together with the denotation integers (these are just strings of digits, possibly converted between bases) they are known as the normal integers. Besides the normal integers there are also coerced integers, which occur when an internal glue or dimen is coerced to an integer.

TeX goes implicitly from a string of digits to a number, that is, if TeX expects a number then anything that looks like a number is accepted. So 42 is a number. The other way around has to be done explicitly though, either through \romannumeral or \number. When we are dealing with an internal integer, \the is equivalent to \number. Since you ask what you can use for XXXX when you want \theXXXX to print something, the answer is an internal integer. There are quite a lot, the ones that you can easily influence are tokens defined by chardef or mathdef and the contents of count registers.

For non-internal integers you want to use \number instead though. That is to say, \number123 will compile fine, where \the123 will fail.

share|improve this answer
Good answer. You are opening a Pandora's box with \number, which will expand further than you may expect in some cases. – Bruno Le Floch Nov 21 '11 at 21:12
@BrunoLeFloch Yeah, there should be a \relax there. At least, I presume that is what you mean :-). – Roelof Spijker Nov 22 '11 at 0:01
Yes. Or a space. Or any non-expandable thing other than an explicit digit with category code other. \relax is the simplest thing to put. – Bruno Le Floch Nov 22 '11 at 0:08

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.