2

I am trying to write a course syllabus for a class that meets only certain days of the week (M, W). I want to check the day of the class and advance it by 2 days or 5 days depending on the day. The following code does not seem to work (fails at the \ifthenelse statement)

\documentclass{article}
\usepackage{advdate}
\usepackage[ddmmyyyy]{datetime}
\usepackage{tikz}

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

 \newcommand{\class}[1]{  
 \def \currday {\shortdayofweekname{\the\day}{\the\month}{\the\year}}
 \ifthenelse{\equal{\currday}{Mon}}{\AdvanceDate[2]}{\AdvanceDate[5]}
 \section* {\syldate{\today} \quad #1}
 }

 \SetDate[06/01/2014]

 \begin{document}
 \class{First Class} 
 \class{Second class}
 \class{Class after holiday}

 \end{document}

The reason I want to do this way, is because I want to check if the \today is in a list of holidays and if so automatically advance to the next class day. Any advice on how to do this? More efficient code is also appreciated.

1
  • 1
    Welcome to TeX.sx! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question.
    – Werner
    Dec 30, 2013 at 20:57

1 Answer 1

4

Hopefully, this is what you're after:

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}%(\shortdayofweekname%{\THEDAY}{\THEMONTH}{\THEYEAR})}

\newsavebox{\MONDAY}\savebox{\MONDAY}{Mon}% Mon

\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
    \AdvanceDate[5]
  \fi%
}

\SetDate[06/01/2014]

\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}

The process stores the date in mydate to join the interfaces of datetime and advdate. The comparison against the day-of-the-week is done by testing the width of the word Mon. Each three-letter/short-date has a different length:

enter image description here

5
  • Great! thanks for the explanation. It is quite helpful. I have a follow up. I will ask it here.
    – Nikhil
    Dec 29, 2013 at 12:54
  • Follow up: I notice this is sensitive to the font. It doesn't work if I use the fourier font for instance (\usepackage{fourier}). How can I get around this?
    – invictus
    Sep 2, 2019 at 18:23
  • 1
    @invictus: Rather use \AtBeginDocument{\savebox{\MONDAY}{Mon}} than setting \MONDAY within the preamble.
    – Werner
    Sep 2, 2019 at 20:40
  • where exactly would that line go? before the declaration of \class? After?
    – invictus
    Sep 4, 2019 at 13:44
  • 1
    @invictus: This MWE should make it clear.
    – Werner
    Sep 4, 2019 at 15:38

You must log in to answer this question.