[Tex/LaTex] Why does \today crash in Tufte-LaTeX using ‘isodate’ when passed as an argument

datetimeisodatetufte

I'm trying to use the isodate package with Tufte-LaTeX, but get

! Illegal parameter number in definition of \reserved@a.

when I use \today as an argument to certain functions (e.g. \printdate or \allcaps):

\documentclass[]{tufte-handout}    
\usepackage[iso,american]{isodate}    
\begin{document}    
\allcaps{\today}    
\end{document}

If \date is set, I get a different error

! Argument of \reserved@a has extra }.

Using \protect\today fixes the above, but I still get the errors when I try to use the date as I need to:

\documentclass[]{tufte-handout}    
\usepackage[iso,american]{isodate}    
\date{\protect\today}
%\date{5/16/1961} % Works fine if a date is provided
\begin{document} 
\makeatletter   
\printdate{\@date}
\end{document}

Best Answer

The default definition of \@date and \date is

\def\@date{\today}
\def\date#1{\gdef\@date{#1}}

This is not changed by isodate, which however redefines \today. You can check if the user has said \date{...} with

\def\kernel@date{\today}
\ifx\@date\kernel@date
  <what to do if no \date command has been given>
\else
  <what to do if \date has been given>
\fi

Of course if one says \date{21 marzo 2012}, \printdate would have a hard time in producing the date in correct form with

\printdate{\csname @date\endcsname}

(this is the same as \makeatletter\printdate{\@date}\makeatother, but more economical).