2

I used \the\year many times on a template. So when I compile the document, the current year is used.

The problem is that I created many documents last year, in 2017, and now I have to fix some small parts.

How to redefine \the\year to print 2017 instead of 2018?

I don't want to find/replace to write 2017 by hand.

  • 1
    \year is a counter register. Just do \year=2017 and it will work. Try this: \documentclass{article} \begin{document} \year=2017 \today \end{document} – Phelype Oleinik Apr 26 '18 at 23:47
  • @PhelypeOleinik, perfect. I suspected about counter, but I tried only setcounter. – Sigur Apr 26 '18 at 23:59
  • If you mean to get 2017 in the printout, type 2017 or define your own macro. Leave \year alone. – egreg Apr 27 '18 at 8:24
  • @Sigur \setcounter only works if the counter was created with \newcounter. When you do \newcounter{year}, for example, the counter register created is \c@year. That's why \setcounter didn't work. Following egreg's advice you could create a \newcounter{year}, then \setcounter{year}{\year}, or \setcounter{year}{2017}, then use \theyear instead (of course this would require some find/replace). – Phelype Oleinik Apr 27 '18 at 11:07
  • @PhelypeOleinik, your solution worked very well. Since the ideal is to compile and print the document around October of every year, I believe that no other changes will be necessary. So, your solution worked very well in this particular case. Please, post an answer, if you wish. – Sigur Apr 27 '18 at 11:31
2

As requested :)

When you create a LaTeX counter, you give a "symbolic" name. For example, \newcounter{year} gives access to a counter register that can be accessed with \c@year. So when you use \setcounter{year}, the counter used is \c@year.

\year, as well as \month, \day, and \time are primitive counter registers (i.e.: not allocated with \newcount nor accessible with \count<n>), and you cannot use them with LaTeX counters. So to change their value you have to use TeX's syntax:

\year=2017

For example, if you compile this document:

\documentclass{article}
\begin{document}
\year=2017
\today
\end{document}

you'll have today's date, but a year back.

But these counters are expected to contain the current date so, as egreg said in his comment, "Leave \year alone". For example, the LaTeX kernel contains a check to see if the version is more than 5 year old (disabled). Other packages may rely on something similar, so it would be better not to do it.

  • Thanks. Since I'm not going to compile those files anymore (I did just to fix some typos), your solution was OK. For this year I'm going to use the same template or maybe updated, but the year should be 2018, so it will work. – Sigur Apr 27 '18 at 19:44

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.