1

I use the code below to create schedules of weekly lectures (on fridays):

\documentclass{article}
\usepackage{advdate}

%... Set the first lecture date
\ThisYear{2019}
\ThisMonth{3}
\ThisDay{1}

\newif\iffirst
    \firsttrue
%%%
\newcommand{\nextlec}{%
  \iffirst
    \firstfalse
  \else
    \AdvanceDate[7]%
  \fi
  \section*{\today}
    \vspace{-5mm}
}

\begin{document}
\nextlec
Lecture 01.

\nextlec
Lecture 02.

\nextlec
Lecture 03.

\nextlec
Lecture 04.

\nextlec
Lecture 05.

\end{document}

How can I change it (still using advdate) if I want \nextlec returning a two-lectures-a-week schedule (say, on tuesdays and on thursdays)?

1
  • Can you give more information? What should this "schedule" look like? Do you mean that \nextlec should alternate between Tuesdays and Thursdays? I would also make it print the "Lecture X". Btw, even though you say that you want to keep using advdate, the datetime2 package provides much more control over dates so I'd recommend using it.
    – user30471
    Dec 5, 2018 at 23:46

1 Answer 1

3

I am not entirely sure if this is what you want but the code below alternates between adding 2 and 5 days to the current date (as there are 2 days between Tuesday and Thursday and 5 days between Thursday and Tuesday). I've also put the "Lecture X" title into the \nextlec command and changed the start date of the first lecture to March 3, 2019, since this is a Tuesday. The output (for the first four lectures) is:

enter image description here

Here is the code:

\documentclass{article}
\usepackage{advdate}

%... Set the first lecture date
\ThisYear{2019}
\ThisMonth{3}
\ThisDay{5}

\newcounter{lecture}
% make \thelecture print Lecture X, with 0-padding for lectures 1-9
\renewcommand\thelecture{%
  Lecture~\ifnum\value{lecture}<10\relax0\fi\arabic{lecture}.}
\newcount\lectureoffset% TeX counters are more convenient 
\newcommand{\nextlec}{%
  \AdvanceDate[\lectureoffset]% increase offset by 2 or 5 (initially 0)
  \ifnum\lectureoffset=2\relax\lectureoffset=5%
  \else\relax\lectureoffset=2%
  \fi%
  \refstepcounter{lecture}% increment the lecture number
  \section*{\today}\vspace{-5mm}\thelecture
}

\begin{document}

  \nextlec
  \nextlec
  \nextlec
  \nextlec
  \nextlec
  \nextlec
  \nextlec
  \nextlec
  \nextlec
  \nextlec

\end{document}

The key is that I have introduced the TeX counter \lectureoffset, which is used to print the date via \AdvanceDate[\lectureoffset]. Each time that \nextlec is used this counter is alternatively incremented by 2 or 5.

You could also use something like the pgffor package to automate this further so that, for example, to print 20 lectures you could write something like:

\foreach \lec in {1,...,20} \nextlec

For this to work you would need to add a few \global statements to the definition of \nextlec:

\newcommand{\nextlec}{%
  \AdvanceDate[\lectureoffset]% increase offset by 2 or 5
  \ifnum\lectureoffset=2\relax\global\lectureoffset=5%
  \else\relax\global\lectureoffset=2%
  \fi%
  \refstepcounter{lecture}% increment the lecture number
  \section*{\today}\vspace{-5mm}\thelecture
}

You must log in to answer this question.

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