2

I am trying to adapt this advance date method for a 3-day syllabus without success.

The goal is to create a M-W-F class schedule. The method in the link above is for a two-day schedule. It takes the three-letter day of the week for the current date ("Mon", "Tue", etc.) and compares it to the width of a box containing the startdate (e.g. "Mon"). If the widths are equal, it advances two and the prints the date two days ahead. Otherwise, it it advances five days. By contrast, I need to advance the date two days if the current date is "Mon", two days if the current date is "Wed", and three days otherwise.

Assuming classes start on a Monday, the two-day method saves "Mon" in a box for the boolean comparison used to advance dates. So I created a second box for "Wed"

\newsavebox{\MONDAY}\savebox{\MONDAY}{Mon}% Mon
\newsavebox{\WEDNESDAY}\savebox{\WEDNESDAY}{Wed}% WED

and then added another condition in the "if" statement:

\newcommand{\class}[1]{%
  \cleardate{mydate}% Clear date
  \newdate{mydate}{\the\day}{\the\month}{\the\year}% Store date
  \section*{\displaydate{mydate} \quad #1}% Set heading
  \setbox1=\hbox{\shortdayofweekname{\getdateday{mydate}}{\getdatemonth{mydate}}{\getdateyear{mydate}}}%
  \ifdim\wd1=\wd\MONDAY
    \AdvanceDate[2]
  \else
  \ifdim\wd1=\wd\WEDNESDAY
    \AdvanceDate[2]
  \else
    \AdvanceDate[3]
  \fi%
}

but this does not work. Any tips?

Full MWE:

\documentclass{article}
\usepackage[ddmmyyyy]{datetime}% http://ctan.org/pkg/datetime
\usepackage{advdate}% http://ctan.org/pkg/advdate

\newdateformat{syldate}{\THEMONTH/\THEDAY/\THEYEAR}%(\shortdayofweekname%{\THEDAY}{\THEMONTH}{\THEYEAR})}

\newsavebox{\MONDAY}\savebox{\MONDAY}{Mon}% Mon
\newsavebox{\WEDNESDAY}\savebox{\WEDNESDAY}{Wed}% WED

\makeatletter
\newcommand{\cleardate}[1]{%
  \expandafter\let\csname date@#1@d\endcsname\relax% Clear day
  \expandafter\let\csname date@#1@m\endcsname\relax% Clear month
  \expandafter\let\csname date@#1@y\endcsname\relax% Clear year
}
\makeatother

\newcommand{\class}[1]{%
  \cleardate{mydate}% Clear date
  \newdate{mydate}{\the\day}{\the\month}{\the\year}% Store date
  \section*{\displaydate{mydate} \quad #1}% Set heading
  \setbox1=\hbox{\shortdayofweekname{\getdateday{mydate}}{\getdatemonth{mydate}}{\getdateyear{mydate}}}%
  \ifdim\wd1=\wd\MONDAY
    \AdvanceDate[2]
  \else
  \ifdim\wd1=\wd\WEDNESDAY
    \AdvanceDate[2]
  \else
    \AdvanceDate[3]
  \fi%
}

\SetDate[14/01/2019]


\begin{document}

\class{First class}
\class{Second class}
\class{Third class}


\class{Fourth class}
\class{Fifth class}
\class{Sixth class}
\class{Seventh class}

\end{document}
3
  • Based on what I can see, it works. You're just missing a closing \fi in your definition of \class.
    – Werner
    Jan 4, 2019 at 21:57
  • @Werner sorry but where would this closing \fi go? I already have one at the end. If I had a \fi after the \ifdim\wd1=\wd\WEDNESDAY I get an error: Extra \else..
    – invictus
    Jan 7, 2019 at 12:48
  • You need an \fi right after the other \fi to end the first \ifdim. (I'll let @werner add this as an answer).
    – Alan Munn
    Jan 7, 2019 at 13:43

1 Answer 1

2

Your code works without problem once you close the outer conditional with a \fi:

enter image description here

\documentclass{article}

\usepackage[ddmmyyyy]{datetime}% http://ctan.org/pkg/datetime
\usepackage{advdate}% http://ctan.org/pkg/advdate

\newdateformat{syldate}{\THEMONTH/\THEDAY/\THEYEAR}

\newsavebox{\MONDAY}\savebox{\MONDAY}{Mon}% Monday
\newsavebox{\WEDNESDAY}\savebox{\WEDNESDAY}{Wed}% Wednesday

\makeatletter
\newcommand{\cleardate}[1]{%
  \expandafter\let\csname date@#1@d\endcsname\relax% Clear day
  \expandafter\let\csname date@#1@m\endcsname\relax% Clear month
  \expandafter\let\csname date@#1@y\endcsname\relax% Clear year
}
\makeatother

\newcommand{\class}[1]{%
  \cleardate{mydate}% Clear date
  \newdate{mydate}{\the\day}{\the\month}{\the\year}% Store date
  \section*{\displaydate{mydate} \quad #1}% Set heading
  \setbox1=\hbox{\shortdayofweekname{\getdateday{mydate}}{\getdatemonth{mydate}}{\getdateyear{mydate}}}%
  \ifdim\wd1=\wd\MONDAY
    \AdvanceDate[2]
  \else
    \ifdim\wd1=\wd\WEDNESDAY
      \AdvanceDate[2]
    \else
      \AdvanceDate[3]
    \fi
  \fi
}

\SetDate[14/01/2019]

\begin{document}

\class{First class}
\class{Second class}
\class{Third class}

\class{Fourth class}
\class{Fifth class}
\class{Sixth class}
\class{Seventh class}

\end{document}

Additionally, consider migrating to datetime2 since datetime is considered obsolete.

2
  • would I need to change any of the above code if using datetime2?
    – invictus
    Jan 8, 2019 at 18:49
  • @invictus: Yes. With the change to an updated package version, there are some fundamental changes to the code (macros; not just their construction, but their names and usage).
    – Werner
    Jan 8, 2019 at 20:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .