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)



 \def \currday {\shortdayofweekname{\the\day}{\the\month}{\the\year}}
 \section* {\syldate{\today} \quad #1}


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


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
    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 '13 at 20:57

Hopefully, this is what you're after:

enter image description here

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


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

  \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

  \cleardate{mydate}% Clear date
  \newdate{mydate}{\the\day}{\the\month}{\the\year}% Store date
  \section*{\displaydate{mydate} \quad #1}% Set heading



\class{First class}
\class{Second class}
\class{Third class}
\class{Fourth class}
\class{Fifth class}
\class{Sixth class}
\class{Seventh class}


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

| improve this answer | |
  • Great! thanks for the explanation. It is quite helpful. I have a follow up. I will ask it here. – Nikhil Dec 29 '13 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 '19 at 18:23
  • 1
    @invictus: Rather use \AtBeginDocument{\savebox{\MONDAY}{Mon}} than setting \MONDAY within the preamble. – Werner Sep 2 '19 at 20:40
  • where exactly would that line go? before the declaration of \class? After? – invictus Sep 4 '19 at 13:44
  • 1
    @invictus: This MWE should make it clear. – Werner Sep 4 '19 at 15:38

Your Answer

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