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'm using a counter to increment months in a journal and the datetime package to turn the counter into months. The months then become chapter titles in the document, so I have something like this:

\documentclass{scrbook}

\usepackage[french]{babel}
\usepackage{datetime}
\usepackage{hyperref}
\usepackage{lipsum}

\newcounter{month}

\newcommand{\newmonth}{%
  \addtocounter{month}{1}%
  \chapter{\monthname[\themonth]}
} 

\begin{document}

\newmonth

\lipsum

\newmonth

\lipsum

\end{document}

The month appears ok in the text, but not in the PDF index. I tracked down this problem to \addchaptertocentry, since I can reproduce it by calling \addchaptertocentry{\monthname[\themonth]}.

The .aux file contains the command verbatim:

\@writefile{toc}{\contentsline {chapter}{\numberline {1}\monthname [1]}{1}{chapter.1}}

How can I make it so that the \monthname command is expanded so that the PDF index looks right?

Edit:

My reason for using datetime here is to support multiple languages (French in this example), so I would rather avoid redefining the month list.

share|improve this question
    
Note that the month names defined by datetime for French have lowercase initial. –  egreg Sep 13 '12 at 18:57
    
@egreg: I did note that, and it's been another issue…. –  ℝaphink Sep 13 '12 at 19:22
add comment

1 Answer

up vote 5 down vote accepted

If you don't need the optional argument which are making it non-expandable you could do

This version with language tests and french

\documentclass{scrbook}

\usepackage[french]{babel}

\usepackage{datetime}
\usepackage{hyperref}
\usepackage{lipsum}



\newcounter{month}

\makeatletter

\def\@orgargctr=#1\relax\ifcase\@orgargctr{\ifcase#1 }
\expandafter\def\expandafter\monthname\expandafter{\csname\string\monthname\endcsname[\the\c@month]}

\expandafter\def\csname\string\monthname\endcsname[#1]{%
\if@dt@multilingual
\@ifundefined {monthname\languagename}%
{\csname \string\monthname english \endcsname [#1]}%
{\csname \string\monthname\languagename \endcsname [#1]}%
\else 
\csname\string\monthnameenglish\endcsname [#1]\fi}

%\expandafter\def\expandafter\monthnameenglish\expandafter{\csname\string\monthnameenglish\endcsname}
\makeatother

\newcommand{\newmonth}{%
  \addtocounter{month}{1}%
  \chapter{\monthname}
} 

\begin{document}



\newmonth

\lipsum

\newmonth


\lipsum

\end{document}
share|improve this answer
    
My main reason for using datetime is to support multiple languages so I can create a generic journal class and rely on babel+datetime for month and dates translations. For this reason, redefining \monthname doesn't really help me. –  ℝaphink Sep 13 '12 at 17:56
    
It's possible to make an expandable test for optional arguments, eg bm package has one but there are always some restrictions, If you could make your MWE a bit less minimal and have a language switch or some such it should be possible to redefine it to cope. You have to redefine \monthnaame or use something else as the definition you have doesn't work in expansion contexts –  David Carlisle Sep 13 '12 at 18:32
    
Just adding \usepackage[french]{babel} to the beginning of the preamble switches the month names to French. –  ℝaphink Sep 13 '12 at 18:36
    
I edited the question. –  ℝaphink Sep 13 '12 at 18:42
    
I added a french answer –  David Carlisle Sep 13 '12 at 18:54
add comment

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.