3

When using the datetime2 package in a scrlttr2 document, I get the error:

/usr/share/texlive/texmf-dist/tex/latex/datetime2/datetime2.sty:368: LaTeX Error: \today undefined.

See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help. ... l.368 \renewcommand*{\today} {%

The code to reproduce this looks like:

\documentclass[british]{scrlttr2}
%\usepackage{polyglossia}
%\setmainlanguage[variant=british]{english}
\usepackage{babel}
\usepackage{datetime2}
\begin{document}
\begin{letter}{test}
\opening{Hello}
\today
\closing{Bye}
\end{letter} 
\end{document}

If you take out datetime2, the document works fine and \today is defined.

The only way I have found to temporarily fix the problem is to call \newcommand\today{} before loading datetime2 but it would be nice to know why I have to.

  • Well the first guess is that scrlttr2 defines \today at \begin{document}. – Ulrike Fischer Feb 11 '16 at 12:27
  • @UlrikeFischer ah indeed, that seems to be the case. Although, looking at the source, there is also a definition for \today not in a \atBeginDocument{} but has some conditions attached to it which I don't really understand. – ArTourter Feb 11 '16 at 12:41
  • It's lucky you posted it now (and that I happened to see you question) as I was just about to upload a new version of datetime2. I've added a check for scrlttr2, and will upload the new version (which will be 1.4) shortly. – Nicola Talbot Feb 11 '16 at 12:48
  • Oh brilliant! Thanks @NicolaTalbot. Perfect timing! – ArTourter Feb 11 '16 at 12:51
  • I've uploaded v1.4, but it make take a few days to get into the distributions. – Nicola Talbot Feb 11 '16 at 13:38
3

As mentioned in the comments, the problem stems from scrlttr2 only defining \today at the start of the document (unlike most classes that define \today when the class loads). As from v1.4, datetime2 now checks for scrlttr2 (and doesn't assume \today is already defined). For earlier versions, the following is a temporary fix:

\documentclass[british]{scrlttr2}

\usepackage{babel}

\def\today{}
\usepackage{datetime2}
\let\orgtoday\today

\begin{document}
\let\today\orgtoday
\begin{letter}{test}
\opening{Hello}
\today
\closing{Bye}
\end{letter}
\end{document}

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.