I'm trying to parse a date (say, a due date) in a DD-MMM-YYYY format, e.g., 06-May-2012 and create macros \dueday, \duemonth, and \dueyear. I use xstring
's commands to extract the substrings. Then I use xstring'
s \IfStrEqCase
to generate the numeric \duemonth
:
\documentclass{article}
\usepackage{xstring}
\begin{document}
\newcommand{\duedate}{06-May-2012}
\newcommand{\dueday}{\StrBefore{\duedate}{-}}
\newcommand{\duemonthname}{\StrBetween[1,2]{\duedate}{-}{-}}
\newcommand{\dueyear}{\StrBehind[2]{\duedate}{-}}
Reconstruction: \dueday-\duemonthname-\dueyear.
%\renewcommand{\duemonthname}{May} % This appears to solve the problem.
\IfStrEqCase{\duemonthname}{%
{Jan}{\newcommand{\duemonth}{1}}%
{Feb}{\newcommand{\duemonth}{2}}%
{Mar}{\newcommand{\duemonth}{3}}%
{Apr}{\newcommand{\duemonth}{4}}%
{May}{\newcommand{\duemonth}{5}}%
{Jun}{\newcommand{\duemonth}{6}}%
{Jul}{\newcommand{\duemonth}{7}}%
{Aug}{\newcommand{\duemonth}{8}}%
{Sep}{\newcommand{\duemonth}{9}}%
{Oct}{\newcommand{\duemonth}{10}}%
{Nov}{\newcommand{\duemonth}{11}}%
{Dec}{\newcommand{\duemonth}{12}}%
}
\duemonth % This should output 5.
\end{document}
which fails with an error message TeX capacity exceeded
. The \IfStrEqCase
doesn't seem to be the problem, because if I issue \renewcommand{\duemonthname}{May}
right before it, everything is fine. This suggests that the error is due to splitting commands, but their outputs are what I expect them to be (at least their "visible" outputs are). What is causing the error then?
\StrBefore{\duedate}{-}[\dueday]\StrBetween[1,2]{\duedate}{-}{-}[\duemonthname]
. Every command ofxstring
has an optional argument which saves the result in a command. See documentation.