14

Is it possible to make LaTeX believe that the current year is 2012, so that \the\year prints 2012?

\documentclass{article}
\begin{document}
  % What to do so that the following prints 2012?
  \the\year
\end{document}

I haven't found advice in The \the command; trying to set \year using \setcounter{year}{2012} didn't work either.

3
  • 2
    It's an internal variable, not a LaTeX counter: \year=2012
    – egreg
    Jun 16 '14 at 21:54
  • @egreg: Thanks for enlightening me, works like a charm but has to come after \begin{document} (not a problem for me). Care to write this as an answer? How does this fit the accepted answer of the linked question?
    – krlmlr
    Jun 16 '14 at 22:02
  • I have supplemented my answer there with these parameters.
    – egreg
    Jun 16 '14 at 22:09
21

TeX initializes \day, \month, \year and \time at the beginning of a job; they are internal integer registers that can be assigned new values. However, there is no LaTeX interface for modifying their values, so the primitive TeX assignment style has to be used: thus

\year=2012

will do, and similarly for the other registers mentioned above. Leave a space (or end of line) after the value, or append \relax to be sure.

Note that \time is initialized with the number of minutes past midnight when the job started. The initial values of \day, \month and \year are the expected ones.

You can print their values by prefixing the register's name with \the, as described in The \the command.

6

Just for fun, without a TeX primitive:

\documentclass{article}
\usepackage{advdate}
\begin{document}
\ThisYear{1492}      Christopher Columbus discovers America in \the\year. \par
\AdvYear{509}        {\em\the\year: A Space Odyssey} was a film made in% 
\AdvYear{-33}        \the\year. \par 
\SetDate[20/07/1969] Man takes first steps on the Moon in \today. \par
\AdvanceDate[16403]  But today is \today.
\end{document}
2
  • Interesting. So, the advdate package interacts with the TeX variables?
    – krlmlr
    Jun 17 '14 at 7:04
  • @krlmlr Yes. Commands as \ThisYear are fairly simple (only do \year#1 \relax) but the package is justified because add x days to \today and obtain the right date is not so easy.
    – Fran
    Jun 17 '14 at 15:23
6

Just for fun, a quick LaTeX interface to the year:

\documentclass{article}

\makeatletter
\let\c@year\year
\makeatother
\newcommand*{\theyear}{\Roman{year}}

\setcounter{year}{2012}

\begin{document}
\theyear
\end{document}

Result

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.