I'm trying to create a definition of notes that is able to print the notes in the document proper in the order that I write them in, but then produce a Table of contents like list at the beginning of the document that lists the different topics, authors, and notes in a more logical order...
But I'm finding it quite difficult to make it work. I've tried using 'titletoc' and 'tocloft', but have only had any success just writing my own... Unfortunately the best I've been able to do is output a list of topics in order at the end... When really I want it to be at the top of the document. IE ideally I could put the \listoftopics at the beginning and it would print:
- Imperialism 1.1 John Do 2.Alice
- State 2.1 Jane Smith 2.2 Charlie
- Math 3.1 Bob
Is there a better way to go about doing this??
Thanks in advance.
MWE:
\documentclass{article}
\newcounter{topiccounter}
\newcounter{notecounter}[topiccounter]
\newcommand{\topiclist}{}
\newcommand{\addtotopiclist}[1]{%
\xdef\topiclist{\topiclist#1\par}%
}
\newcommand{\tnote}[3]{%
\par % Start a new paragraph
\ifcsname topic@#2\endcsname
% Topic already exists
\else
\stepcounter{topiccounter}%
\expandafter\global\expandafter\let\csname topic@#2\endcsname=1
\addtotopiclist{\thetopiccounter. #2} % Add topic to the list
\fi
\refstepcounter{notecounter}%
\noindent\textbf{\csname thetopic@#2\endcsname. #2} % Topic
\hfill \textit{#1 (\the\numexpr\value{notecounter}+1\relax): #3}% Author (date): title
\par % Start a new paragraph
}
\newcommand{\listoftopics}{%
\section*{Topic List}
\topiclist
}
\begin{document}
\tnote{John Doe}{Imperialism}{2024-03-08}
This is a note about imperialism.
\tnote{Alice}{Imperialism}{2024-03-10}
Another note about imperialism.
\tnote{Jane Smith}{State}{2024-03-09}
This is a note about the state.
\tnote{Bob}{Math}{2024-03-11}
This is a note about math.
\tnote{Charlie}{State}{2024-03-12}
Another note about the state.
\listoftopics % Print the combined list
\end{document}
The issue I'm having is that the command only works at the end of the document, and only prints the title of the topic, not the subtopics. When using the packages, the issue I have is that they are expecting the table of contents to be linear, rather than non-linear which is what I want mine to be!