10

I would like to get the month in text e.g., June and the year in Roman, e.g. MMXIV when I call \the\month and \the\year

I also would like to avoid using any external package (I found some related questions, but all seem to be based on the datetime package):

\today month as text

Month Name in Upper case

How do I "unprotect" an argument?

Change \the\year

7
  • I assume you're up for a macro pair like \MONTH and \YEAR that does that?
    – Werner
    Jun 18, 2014 at 23:57
  • @Werner Well, I don't know if a new macro or to \renew \year and \month Jun 19, 2014 at 0:01
  • Well, see if my answer provides you with hope... :) If not, I'll delete it.
    – Werner
    Jun 19, 2014 at 0:05
  • I'm asking why you don't want to use a package; just for reinventing the wheel? ;-)
    – egreg
    Jun 19, 2014 at 10:17
  • @egreg, maybe because I feel there is no need for a whole package for something that looks so simple? Perhaps I'm mistaken here... Jun 19, 2014 at 10:28

2 Answers 2

10

The following minimal example defines \MONTH and \YEAR that provides the output you're after:

enter image description here

\documentclass{article}
\newcommand{\MONTH}{%
  \ifcase\the\month
  \or January% 1
  \or February% 2
  \or March% 3
  \or April% 4
  \or May% 5
  \or June% 6
  \or July% 7
  \or August% 8
  \or September% 9
  \or October% 10
  \or November% 11
  \or December% 12
  \fi}
\makeatletter
\newcommand{\YEAR}{\@Roman{\the\year}}
\makeatother

\begin{document}

Month: \the\month, \MONTH \par
Year: \the\year, \YEAR

\end{document}
2
  • Smooth :D. Is \month always provided in numeric format? Why is so? Jun 19, 2014 at 0:10
  • @MarioS.E.: Yes. See section 33.5 Time in TeX by Topic.
    – Werner
    Jun 19, 2014 at 0:12
10

I don't see why reinventing the wheel. ;-)

The datetime package supports several languages and, if one is not supported, the package author will surely be glad to add it. Perhaps also an interface for printing the year in Roman numerals would be useful in the package.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[italian,english]{babel}
\usepackage{datetime}

\makeatletter
\newcommand\Romanyear{\@Roman{\year}}
\makeatother

\begin{document}

\monthname, \Romanyear

\selectlanguage{italian}

\monthname, \Romanyear

\end{document}

enter image description here

4
  • I just remember why I didn't try this one: what I have is a \gdef\@thesisdate{\the\month \the\year} in my .sty file. If I use @Werner's solution, I'd have: \gdef\@thesisdate{\MONTH \the\year}, which works just fine for both the pdf document and the hyperref pdf setup later. If I go like your answer, I get a warning saying that \monthname is not a valid token Jun 19, 2014 at 11:18
  • Naturally, the \newcommand{\Romanyear}{...} works perfectly :) Jun 19, 2014 at 11:19
  • 3
    \@Roman{\number\year} can be simplified to \@Roman{\year}, because \year is already a "TeX number". Jun 19, 2014 at 11:47
  • @HeikoOberdiek I'll never remember that \@Roman and the similar commands already do \number or \romannumeral. Thanks.
    – egreg
    Jun 19, 2014 at 12:32

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.