11

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

Mario S. E.
  • 18,609

2 Answers2

13

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}
Werner
  • 603,163
12

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

egreg
  • 1,121,712
  • 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 – Mario S. E. Jun 19 '14 at 11:18
  • Naturally, the \newcommand{\Romanyear}{...} works perfectly :) – Mario S. E. Jun 19 '14 at 11:19
  • 3
    \@Roman{\number\year} can be simplified to \@Roman{\year}, because \year is already a "TeX number". – Heiko Oberdiek Jun 19 '14 at 11:47
  • @HeikoOberdiek I'll never remember that \@Roman and the similar commands already do \number or \romannumeral. Thanks. – egreg Jun 19 '14 at 12:32