I am aware that there is a question on this site with the exact same title as mine, but what I am after is quite different.
I have written some course notes whose contents could be organised in two ways: the first is the logical content of the document (the natural way the topics should be structured), the other is by lectures (i.e., lecture 1, lecture 2, etc.). The latter is useful for students, especially if they miss a lecture and would like to know exactly what they missed.
I like to indicate both in my table of contents, and my current solution is to have a command I created called \newlecture{day}{month}{year}
, this adds a nice header in the text and adds a line to the table of contents:
Here is the code for the MWE:
\documentclass{article}
% Packages
\usepackage{lipsum,parskip}
\usepackage[hidelinks]{hyperref}
\usepackage[british]{datetime2}
% Date format
\DTMlangsetup[en-GB]{monthyearsep={,\space}}
% Lecture counter
\newcounter{lecture}
\newcommand\newlecture[3]{%
\stepcounter{lecture}
\phantomsection\textbf{LECTURE \thelecture}\hfill{\itshape \DTMdisplaydate{#3}{#2}{#1}{-1}}%
\addcontentsline{toc}{section}{\normalfont\itshape Lecture \thelecture~(\DTMdisplaydate{#3}{#2}{#1}{-1})}}
\begin{document}
% Contents
\tableofcontents
\pagebreak
\newlecture{14}{10}{2021}
\section{Introduction}
\lipsum[1-5]
\subsection{What this course is about}
\lipsum[6-10]
\subsection{The Exam}
\lipsum[11-15]
\section{Some Basic Techniques}
\lipsum[16-20]
\subsection{Arithmetic Functions}
\lipsum[21-25]
\subsection{M\"obius Inversion and Dirichlet Convolution}
\lipsum[26-30]
\subsection{Partial Summation}
\lipsum[31-35]
\newlecture{21}{10}{2021}
\lipsum[36-40]
\subsection{The Euler--Maclaurin Formula}
\lipsum[41-45]
\section{Proof of the Prime Number Theorem}
\lipsum[46-50]
\subsection{Some Initial Bounds}
\lipsum[51-55]
\end{document}
Now I think it would make the table of contents look cleaner if, Instead of a new line for lectures, I had a marginnote, something like this:
How can I add these to my contents with a similar command? I know I can do something like \section{Title\marginnote{...}}
but that would create a margin note where the section appears also. I'd rather keep the margin notes just for the ToC (plus, sometimes I have to stop mid-section, so the command \newlecture
can appear at any stage, not necessarily at the start of a section or subsection).