4

I am making a class syllabus using the "termcal" package and would like to store the starting date for the first class so I can use it for different elements of the syllabus. I am currently trying to store the date using the \DTMsavedate function from the "datetime2" package.

The date will show fine if you use, for example, \DTMusedate{startDate} within a paragraph. But if I try to pass it to the date option for \begin{calender}, I get the error message "Paragraph ended before \setdate@ was complete". Is there a way to make this work? The MWE:

\documentclass[12pt]{article}
\usepackage{termcal}
\usepackage[american,useregional=numeric]{datetime2}
\DTMsavedate{startDate}{2017-8-29}

\begin{document}

\begin{calendar}{\DTMusedate{startDate}}{16} 

\setlength{\calboxdepth}{.3in}
\setlength{\calwidth}{0.8\textwidth} 

% Description of the Week.
\calday[Tuesday]{\classday} 
\skipday
\calday[Thursday]{\classday}
\skipday
\skipday
\skipday
\skipday

\end{calendar}

\end{document}

I would really appreciate any help with this, thanks!

3

First, welcome to TeX.SX. It's nice to see a new user, who knows how to ask and do a MWE.

The termcal package only accepts dates in the format <month>/<day>/<year>. And the date argument of \begin{calendar} is not expanded before parsing, i.e. macros can't be used. The latter can be changed, but this doesn't work with `\DTMusedate'.

If you don't insist on using the datetime2 package, then here is a solution without it.

To save the date, a simple command \startDate is defined, just containing the date in the correct format. And to make macros work as argument for \begin{calendar} \setdate is redefined so it expands the argument before it's parsed.

\documentclass[12pt]{article}
\usepackage{termcal}
\newcommand*{\startDate}{08/29/2017}

\makeatletter
\renewcommand{\setdate}[1]{\expandafter\setdate@#1!}
\makeatother

\begin{document}

\begin{calendar}{\startDate}{16} 

\setlength{\calboxdepth}{.3in}
\setlength{\calwidth}{0.8\textwidth} 

% Description of the Week.
\calday[Tuesday]{\classday} 
\skipday
\calday[Thursday]{\classday}
\skipday
\skipday
\skipday
\skipday

\end{calendar}

\end{document}
4

Following on from Mike's answer, if you really need to use datetime2, you can just make sure that \DTMusedate is fully expanded before being passed as an argument:

\documentclass[12pt]{article}
\usepackage{termcal}
\usepackage[american,useregional=numeric]{datetime2}
\DTMsavedate{startDate}{2017-8-29}

\begin{document}

\edef\startCalendar{\noexpand\begin{calendar}{\DTMusedate{startDate}}{16}}
\startCalendar

\setlength{\calboxdepth}{.3in}
\setlength{\calwidth}{0.8\textwidth} 

% Description of the Week.
\calday[Tuesday]{\classday} 
\skipday
\calday[Thursday]{\classday}
\skipday
\skipday
\skipday
\skipday

\end{calendar}

\end{document}

Here's a minor modification to Mike's suggestion:

\documentclass[12pt]{article}
\usepackage{termcal}
\usepackage{datetime2}
\DTMsavedate{startDate}{2017-8-29}

\newenvironment{mycalendar}[2]{%
 \DTMsetup{monthdaysep=/,dayyearsep=/}%
 \DTMsetstyle{mmddyyyy}%
 \edef\startCalendar{\noexpand\begin{calendar}{#1}{#2}}%
 \startCalendar
}
{\end{calendar}}

\begin{document}

\begin{mycalendar}{\DTMusedate{startDate}}{16}

\setlength{\calboxdepth}{.3in}
\setlength{\calwidth}{0.8\textwidth} 

% Description of the Week.
\calday[Tuesday]{\classday} 
\skipday
\calday[Thursday]{\classday}
\skipday
\skipday
\skipday
\skipday

\end{mycalendar}

\end{document}

This ensures that the date is always in the style required by the calendar environment, even if you have a different date style in the rest of the document. (The change in style is automatically scoped by the mycalendar environment.)

  • 1
    @Nicola Talbot if you define \newenvironment{mycalendar}[2]{\edef\startCalendar{\noexpand\begin{calendar}{#1}{#2}}\startCalendar}{\end{calendar}} in the preamble, the mycalendar environment can be used in the text just like calendar. – Mike Jul 9 '17 at 12:21
  • @Mike Good idea. – Nicola Talbot Jul 10 '17 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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