Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'd like to use datetime's \monthname as part of a command; consider this snippet of command line pdflatex use:

$ pdflatex
This is pdfTeX, Version 3.1415926-1.40.11 (TeX Live 2010)
 restricted \write18 enabled.
**\documentclass{article}
entering extended mode
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, dumylang, nohyphenation, lo
aded.

*\usepackage{datetime}
(/PATH/TO/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/PATH/TO/texlive/texmf-dist/tex/latex/base/size10.clo))

*\newdate{someDate}{30}{05}{2011}
(/PATH/TO/texlive/texmf-dist/tex/latex/datetime/datetime.sty
(/PATH/TO/texlive/texmf-dist/tex/latex/fmtcount/fmtcount.sty
(/PATH/TO/texlive/texmf-dist/tex/latex/base/ifthen.sty)
(/PATH/TO/texlive/texmf-dist/tex/latex/graphics/keyval.sty)
(/PATH/TO/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty)
(/PATH/TO/texlive/texmf-dist/tex/latex/fmtcount/fc-english.def)
(/PATH/TO/texlive/texmf-dist/tex/latex/fmtcount/fc-USenglish.def)
No configuration file fmtcount.cfg found.
))

*\newcommand\someDateStr{\getdateday{someDate} \monthname[\getdatemonth{someDate}] \getdateyear{someDate}}

*\typeout{\someDateStr}
30 \monthname[05] 2011

*\typeout{\monthname[\getdatemonth{someDate}]}
\monthname[05]

So, it looks like in the construct \monthname[\getdatemonth{someDate}], Latex will expand only \getdatemonth{someDate}, but not the \monthname part; I'm suspecting it has something to do with the square brackets as arguments, because if I try to use edef instead, I get an error:

*\edef\someDateStr{\getdateday{someDate} \monthname[\getdatemonth{someDate}] \getdateyear{someDate}}
! Argument of \reserved@a has an extra }.
<inserted text> 
                \par 
<*> ...atemonth{someDate}] \getdateyear{someDate}}

? 

So, the question is: how can I use \monthname[\getdatemonth{someDate}] as a part of a newcommand, such that it results with (in this case) "May"?

Thanks in advance for any responses,
Cheers!

share|improve this question

1 Answer 1

up vote 3 down vote accepted

The main problem with datetime is that it is oriented towards printing dates rather than manipulating them.

A "completely expandable" version would be

\makeatletter
\newcommand{\xnewdate}[4]{\@namedef{date@#1}{/#2/#3/#4/}}
\def\xgetdateday#1{\expandafter\expandafter\expandafter\xget@I\csname date@#1\endcsname}
\def\xgetdatemonth#1{\expandafter\expandafter\expandafter\xget@II\csname date@#1\endcsname}
\def\xgetdateyear#1{\expandafter\expandafter\expandafter\xget@III\csname date@#1\endcsname}
\def\xget@I/#1/#2/#3/{#1}
\def\xget@II/#1/#2/#3/{#2}
\def\xget@III/#1/#2/#3/{#3}
\def\xgetdatemonthname#1{%
\ifcase\number\xgetdatemonth{#1}\relax
\or January%
\or February%
\or March%
\or April%
\or May%
\or June%
\or July%
\or August%
\or September%
\or October%
\or November%
\or December%
\fi}
\makeatother

\typeout{\xgetdateday{somedate} \xgetdatemonthname{somedate} \xgetdateyear{somedate}}
share|improve this answer
    
Uh, oh :) - Thanks for that, @egreg :) I simply wanted to use the \monthname in a \hypersetup for a PDF title, and it was crashing the same way \typeout did, which is why I formulated the OP in that way... Nice to know that this entails complications - and how to get around them :) Cheers! –  sdaau May 30 '11 at 19:41
1  
Is there maybe another package that would allow date manipulation? I have the same kind of issue inserting dynamic dates into a PDF table of contents. –  ℝaphink Sep 13 '12 at 12:06
    
@ℝaphink No package that I know of. Maybe you can ask a question stating more precisely what you need. –  egreg Sep 13 '12 at 12:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.