Using the LaTeX 2ε-kernel's \@starttoc
/\addtocontents
-mechanism you can define a command
\ImportantDate{⟨WorkAssignment⟩}{⟨chapter-number⟩}{⟨customary text⟩}
⟨WorkAssignment⟩ = HW/Homework 1 or Quiz 3
⟨chapter-number⟩ = Number of Chapter
⟨customary text⟩ = Customary text
which
- delivers:
⟨WorkAssignment⟩~(Chapter~⟨chapter-number⟩)
%
- via
\addtocontents
creates a \@writefile
-entry for the file \jobname.loids
(loids = list of important dates) denoting the call of the macro \LineWithImportantDate
with arguments holding all information needed for creating another row of the longtable.
Then you can have a macro \listofImportantDates
which—similar to \tableofcontents
—via \@starttoc
imports the .loids-file and creates the \write
-handle for the .loids-file.
You can use \AtBeginDocument
(from the LaTeX 2ε-kernel) and \AfterLastShipout
(from the package atveryend) for prepending/appending the longtable-preamble/postamble to the .loids-file.
You need to redefine \calprintdate
so that also a \hypertarget
is created.
You can use the macros of the package datetime2
- for calculating the day of the week
- obtaining the name of the day of the week
- obtaining the name of the month
- obtaining the day of the month as an ordinal number (st, nd, rd, th appended).
You can define commands \Homework
and \Quiz
which step a counter "homeworks" respective "quizzes" and then call \ImportantDate{⟨WorkAssignment⟩}
, leaving the gathering of remaining arguments to \ImportantDate
.
Syntax is the same as with \ImportantDate
except that ⟨WorkAssignment⟩
is auto-generated:
\Homework{⟨chapter-number⟩}{⟨customary text⟩}
\Quiz{⟨chapter-number⟩}{⟨customary text⟩}
Starred variants of these commands don't produce hyperlinks from the List of important dates to the calendar.
Edit 1: As with slightly older LaTeX 2ε-kernels the \@writefile
-mechanism doesn't take \protected@file@percent
into account, I removed all instances of \protected@file@percent
from my code.
The code (saved as test.tex) compiled successfully using TeXLive 2020 under Debian Buster x86. I had to compile four times without deleting auxiliary-files in between until everything coming from auxiliary files that get created/altered during the latex-run (longtable, hypertargets) matched out correctly.
Edit 2: I added a command
\ImportantDateNote{⟨amount of empty cells at the left of the cell with the note (range from 0 to 2)⟩}%
{⟨amount of cells the note shall span (range from 1 to 3)⟩}%
{⟨flag <=0 or >0 denoting if vertical bar shall be drawn between two consecutive empty cells⟩}%
{⟨alignmant of note l r c p{0.15\textwidth}⟩}%
{⟨text of note⟩}
for placing whatsoever notes into the table of important dates.
The table has three columns, thus the sum of ⟨amount of empty cells at the left of the cell with the note (range from 0 to 2)⟩ and
⟨amount of cells the note shall span (range from 1 to 3)⟩ must not exceed the value 3.
\documentclass[10pt]{article}
%\usepackage[a4paper]{geometry}
\textwidth=7in
\textheight=9.5in
\topmargin=-1in
\headheight=0in
\headsep=.5in
\hoffset -.85in
\usepackage{enumitem}
\usepackage{termcal}
\usepackage{xcolor}
\usepackage{hyperref}
\hypersetup{colorlinks=true, allcolors= blue}
\newcommand{\MWClass}{%%%
\calday[\bf Monday]{\classday}%%%
\skipday
\calday[\bf Wednesday]{\classday}%%%
\skipday
\skipday\skipday
\skipday
}
\setlist[itemize]{itemsep=1pt, topsep=0pt}
\setlist[enumerate]{itemsep=1pt, topsep=0pt}
\renewcommand{\thefootnote}{\fnsymbol{footnote}}
%////////////////////////////////////////////////////////////////////////////
\usepackage[calc, en-GB-numeric]{datetime2}
\usepackage{atveryend}
\DTMlangsetup[en-GB]{ord=raise}
\makeatletter
\newcommand*\ImportantDate@Chaptername{Chapter}%
\newcommand*\ImportantDate@AbbreviatedChaptername{Chapter}%
\newcommand\ImportantDateTempa{}%
\@ifdefinable\ImportantDate{%
\DeclareRobustCommand\ImportantDate{%
\@ifstar{\@ImportantDate*}{\@ImportantDate{}}%
}%
}%
\newcommand\@ImportantDate[4]{%
% #1 - Star/NoStar
% #2 - WorkAssignment - e.g., HW1 or Quiz 1
% #3 - number of chapter
% #4 - customary text
#2 (\ImportantDate@Chaptername~#3)%
\begingroup
\DTMsavenoparsedate{storeddate}{\arabic{year}}{\arabic{month}}{\arabic{date}}{-1}%
\DTMcomputedayofweekindex{\DTMfetchyear{storeddate}-\DTMfetchmonth{storeddate}-\DTMfetchday{storeddate}}{\ImportantDateTempa}%
\addtocontents{loids}{%
\string\LineWithImportantDate#1\@percentchar^^J%
\space\space{\detokenize{#2}}\@percentchar^^J%
\space\space{\detokenize{#3}}\@percentchar^^J%
\space\space{\detokenize{#4}}\@percentchar^^J%
\space\space{\arabic{year}}\@percentchar^^J%
\space\space{\arabic{month}}\@percentchar^^J%
\space\space{\arabic{date}}\@percentchar^^J%
\space\space{\ImportantDateTempa}\@percentchar^^J%
\space\space{caldate.\arabic{year}-\arabic{month}-\arabic{date}}^^J%
}%
\endgroup
}%
\@ifdefinable\LineWithImportantDate{%
\DeclareRobustCommand\LineWithImportantDate{%
\@ifstar{\@LineWithImportantDate{\@secondoftwo}}{\@LineWithImportantDate{\hyperlink}}%
}%
}%
\newcommand\@LineWithImportantDate[9]{%
#1{#9}{#2}&%
#1{#9}{\ImportantDate@AbbreviatedChaptername~#3}&%
#1{#9}{%
\DTMWeekdayname{#8}, \DTMordinal{#7}~\DTMMonthname{#6}, #5#4%
}%
\\\hline
}%
\newcommand\ImportantDateNote[5]{%
% #1 - amount of empty cells at the left of the cell with the note
% #2 - amount of cells the note shall span
% #3 - flag <=0/>0 denoting if vertical bar between 2 consecutive empty cells
% #4 - alignmant of note l r c p{0.15\textwidth}
% #5 - text of note
\@bsphack
\addtocontents{loids}{\string\LineWithImportantNote{#1}{#2}{#3}{#4}{#5}}%
\@esphack
}%
\newcommand\LineWithImportantNote[5]{%
\ifnum#1>0 \exchange{%
\ifnum #3>0 \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{%
\ifnum#1>1 \expandafter\@secondoftwo\else\expandafter\@firstoftwo\fi
}{\@firstoftwo}%
{\multicolumn{#1}{|l}{}&}%
{\multicolumn{1}{|l}{}&\multicolumn{1}{|l}{}&}%
}\fi
\multicolumn{#2}{|#4|}{#5}%
\ifnum\number\numexpr3-#1-#2\relax>0 \exchange{%
\ifnum #3>0 \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{%
\ifnum\number\numexpr3-#1-#2\relax>1 \expandafter\@secondoftwo\else\expandafter\@firstoftwo\fi
}{\@firstoftwo}%
{&\multicolumn{\numexpr3-#1-#2\relax}{l|}{}}%
{&\multicolumn{1}{l|}{}&\multicolumn{1}{l|}{}}%
}\fi
\\\hline
}%
\newcounter{quizzes}%
\newcounter{homeworks}%
\newcommand\homeworksname{Homework}%
\newcommand\quizzesname{Quiz}%
\@ifdefinable\Stopromannumeral{\chardef\Stopromannumeral=`\^^00}%
\newcommand\exchange[2]{#2#1}%
\@ifdefinable\Homework{%
\DeclareRobustCommand\Homework{%
\@ifstar{\@Homework{\expandafter*}}{\@Homework{}}%
}%
}%
\newcommand\@Homework[1]{%
\stepcounter{homeworks}%
\expandafter\ImportantDate#1\expandafter{%
\romannumeral
\expandafter\exchange\expandafter
{\number\value{homeworks}}%
{\expandafter\Stopromannumeral\homeworksname~}%
}%
}%
\@ifdefinable\Quiz{%
\DeclareRobustCommand\Quiz{%
\@ifstar{\@Quiz{\expandafter*}}{\@Quiz{}}%
}%
}%
\newcommand\@Quiz[1]{%
\stepcounter{quizzes}%
\expandafter\ImportantDate#1\expandafter{%
\romannumeral
\expandafter\exchange\expandafter
{\number\value{quizzes}}%
{\expandafter\Stopromannumeral\quizzesname~}%
}%
}%
\renewcommand\calprintdate{%
\hbox{%
\Hy@raisedlink{%
\hypertarget{%
caldate.\arabic{year}-\arabic{month}-\arabic{date}%
}{}%
}%
% You can change this to do some more sophisticated/more beautiful things.
\ifnewmonth\framebox{\monthname\ \ordinaldate}%
\else \ordinaldate\fi
}%
}%
\AtBeginDocument{%
\addtocontents{loids}{\string\begingroup}%
\addtocontents{loids}{\string\renewcommand{\string\arraystretch}{2}}%
\addtocontents{loids}{\string\begin{longtable}{|l|p{0.15\string\textwidth}|l|}}%
\addtocontents{loids}{\string\hline}%
\addtocontents{loids}{%
&\string\bfseries\space Chapter&\string\bfseries\space Due Date\string\\ \string\hline\space \string\endhead
}%
}%
\AfterLastShipout{%
\begingroup
\let\writecopy=\write
\def\write{\noexpand\immediate\noexpand\writecopy}%
\addtocontents{loids}{\string\end{longtable}}%
\addtocontents{loids}{\string\endgroup}%
\endgroup
}%
\newcommand\listofImportantDates{%
\IfFileExists{\jobname.loids}{%
\par
\begingroup
\centering
{\Large Important Dates}\\ \vspace{-1ex} %
\par
\@starttoc{loids}%
\par
\endgroup
}{%
\@starttoc{loids}%
}%
}%
\makeatother
%////////////////////////////////////////////////////////////////////////////
\begin{document}
\listofImportantDates
\clearpage
\newpage
\begin{center}
\begin{calendar}{01/11/2021}{2}
\setlength{\calboxdepth}{0.6in}
\MWClass
\caltexton{1}{\vspace{1ex} Course Introduction}%
\caltextnext{%
\vspace{1ex} %
Lecture 1 \\ \vspace{1ex}
{\bf Chapter 9: Steady-State Power Analysis}%
\vspace{1ex}%
\begin{itemize}
\item[] {\bf Sec 9.1} Instantaneous power%
\end{itemize}%
}
\caltexton{1}{}%
\caltextnext{%
\vspace{1.5ex}%
{\bf\color{red}\Homework{9}{ at 11:59 PM (Online submission)}}%
\ImportantDateNote{1}{2}{0}{c}{\emph{The sooner you do your homework, the sooner it will stop weighing your mind!}}%
}%
\caltextnext{%
\vspace{1.5ex}%
{\bf\color{red}\Quiz*{9}{ at 11:59 PM (Offline omission)}}%
\ImportantDateNote{0}{1}{1}{l}{\emph{A note.}}%
\ImportantDateNote{1}{1}{0}{l}{\emph{A note.}}%
\ImportantDateNote{2}{1}{1}{l}{\emph{A note.}}%
\ImportantDateNote{2}{1}{0}{l}{\emph{A note.}}%
\ImportantDateNote{0}{2}{0}{l}{\emph{A note.}}%
\ImportantDateNote{0}{3}{0}{l}{\emph{A note.}}%
\ImportantDateNote{1}{2}{0}{l}{\emph{A note.}}%
\ImportantDateNote{0}{1}{0}{l}{\emph{A note.}}%
}%
\end{calendar}
\end{center}
\end{document}

