# isodate in section titles with correct PDF bookmarks

I want to use isodate's \printdate as part of a command to create a new section. Simplified example:

\documentclass{article}

\usepackage{hyperref}
\usepackage[american]{isodate}

\newcommand{\datesec}[1]{\section{Date \printdate{#1}}}

\begin{document}

\datesec{2010-11-01}

\end{document}


This gets numerous errors when run through pdflatex, starting with:

! Undefined control sequence.
\@nnil ->\@nil

l.10 \datesec{2010-11-01}


I've tried every expansion trick I know (which is not saying much). In my experiments it also seems to me that I've managed to make a section heading successfully include the date, but then the PDF bookmark generated (I think) by hyperref just shows "Date " without including the output from \printdate.

How can I use \printdate in a section title and also have it generate a correct, complete PDF bookmark? Thanks!

P.S.: I've had a little more luck with datetime's \formatdate but not much, and it also has a less pleasing syntax.

• What you are trying to do looks really hard to achieve because the isodate macros really aren't oriented towards being fully expandable. What exactly are your requirements? What features of the isodate package do you need? – Harald Hanche-Olsen Nov 4 '10 at 19:28
• I'm looking for the ability to type a short ISO date, like 2010-11-01, and then be able to choose (and maybe later change) how that date will be formatted. I need to include this date in some kind of command (like \datesec) that will create a section, but maybe later will create a subsection or a subsubsection instead, etc. Make sense? – dsedivec Nov 4 '10 at 20:40

This compiles, but I had to turn it around

\documentclass{article}
\usepackage{hyperref}
\usepackage[american]{isodate}

\begin{document}
\newcommand{\datesec}[1]{\texorpdfstring{Date \printdate{#1}}{}}

\section{\datesec{2010-11-01}}

\end{document}

• Thanks for the answer. As I commented above (after you left this answer) I'd vastly prefer to put the \section in the command so that I can change its nesting within other sections later. – dsedivec Nov 4 '10 at 21:20

Here's one of those annoying "I'm changing the problem" kind of answers to my own question: If you can use LuaTeX (I can), then it might be feasible to punt the date handling out to Lua rather than isodate. Example (just a toy, advice is not to put any significant amount of Lua code inline, but instead put it in a separate file):

\documentclass{article}

\usepackage{luacode}
\usepackage{hyperref}

\begin{luacode*}

MONTHS = {
["01"]="January",
["02"]="February",
["03"]="March",
["04"]="April",
["05"]="May",
["06"]="June",
["07"]="June",
["08"]="August",
["09"]="September",
["10"]="October",
["11"]="November",
["12"]="December",
}

function format_date(date_str)
year, month, day = date_str:match("(%d+)-(%d+)-(%d+)")
return string.format("%s %s, %s", MONTHS[month], day, year)
end

\end{luacode*}

\begin{document}

\datesec{2010-11-01}

Test 1

\datesec{2999-09-09}

Test 2

\end{document}


To my great, surprise, this works: