2

I asked this question How to do recursive program with latex and got the following excellent answer by @JosephWright

\documentclass{article}
\usepackage{advdate}

% Set the first practice date
\ThisDay{7}
\ThisMonth{2}
\ThisYear{2019}

%... the number of days between lectures
\newcommand*{\lecturegap}{7}

\makeatletter
\newcounter{holiday}
\newcommand*\addholiday[3]{%
  \stepcounter{holiday}%
  \@namedef{holiday\arabic{holiday}}{%
    \def\holidayDay{#1}%
    \def\holidayMonth{#2}%
    \def\holidayYear{#3}%
  }%
}
\makeatother
\newcommand*{\holidayDay}{0}
\newcommand*{\holidayMonth}{0}
\newcommand*{\holidayYear}{0}
\addholiday{3}{3}{2019}  % ter Carnaval
\addholiday{18}{4}{2019} % qui Atividade complementar
\addholiday{19}{4}{2019} % sex Santa
\addholiday{21}{4}{2019} % dom Tiradentes/Páscoa
\addholiday{1}{5}{2019}  % qua Trabalhador
\addholiday{19}{6}{2019} % qua Aniv. Rib. Preto

\newif\ifholiday
\newcommand*{\groupA}{}
\makeatletter
\newcommand*{\nextprac}{%
  \holidayfalse
  \count0=1 %
  \loop
    \ifnum\count0>\value{holiday}\else
      \@nameuse{holiday\number\count0 }%
      \ifnum 0%
        \ifnum\holidayDay=\day1\else0\fi
        \ifnum\holidayMonth=\month1\else0\fi
        \ifnum\holidayYear=\year1\else0\fi
        =111 %
        \holidaytrue
        \count0=\value{holiday}%
        \else
      \fi
    \advance\count0 by 1 %
  \repeat
  \ifholiday
    \AdvanceDate[\lecturegap]%
    \expandafter\nextprac
  \else
    \ifx\groupA\empty
      \edef\groupA{%
        {\day=\the\day\month=\the\month\year=\the\year\relax\noexpand\today}}%
      \expandafter\expandafter\expandafter\nextprac
    \else
      \AdvanceDate[\lecturegap]%
      \section*{\groupA\space$\parallel$ \today}%
      \def\groupA{}%
      \AdvanceDate[\lecturegap]%
    \fi
  \fi
}

\begin{document}

  \nextprac
  Practice one

  \nextprac
  Practice two

  \nextprac
  Practice three

  \nextprac
  Practice four

  \nextprac
  Practice five

  \nextprac
  Practice six

  \nextprac
  Practice seven

  \nextprac
  Practice eight

  \nextprac
  Practice nine

  \nextprac
  Practice ten

\end{document}

However, a few months latter, I realized that this code affects page numbering. But I cannot figure out how it is affected nor how to fix it.

The only thing I realized is that the page number becomes the exact number of holidays created by \addholiday command.

My question is: how to restore page numbering without leaving the presented code away?

  • 1
    \count0 refers to the page number. – egreg Mar 25 at 13:26
  • 1
    @JosephWright should stick to expl3 then he wouldn't using \count0 as loop variable ;-) (he probably wanted to use \count@) – Ulrike Fischer Mar 25 at 13:27
1

You're using \count0 in the wild, which contains the page number.

Change all occurrences of \count0 into \@tempcnta

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.