This is the code I am using (along with the datenumber
package) to create subsection titles that include an increasing date.
\DeclareRobustCommand\mysubsectiontitle{Week of \StrLeft{\datemonthname}{3}. \thedateday, \thedateyear}
\newcommand{\mysubsection}[1]{\subsection{\mysubsectiontitle #1}}
The section titles do increase, but the table of contents display the same date across.
Subsections:
TOC:
I am also getting a lot of warnings in the form "Token not allowed in a PDF string (Unicode)."
How can I fix this?
EDIT:
\documentclass[12pt]{article}
\usepackage{xstring}
\usepackage{datenumber}
\setdatenumber{2024}{02}{26}
\newcommand{\mysectiontitle}{\datemonthname~\thedateyear}
\newcommand{\mysection}[1]{\section{\mysectiontitle #1}}
\DeclareRobustCommand\mysubsectiontitle{Week of \StrLeft{\datemonthname}{3}. \thedateday, \thedateyear}
\newcommand{\mysubsection}[1]{\subsection{\mysubsectiontitle #1}}
\begin{document}
\tableofcontents
\mysection{}
\mysubsection{}
\nextdate
\mysubsection{}
\nextdate
\mysubsection{}
\nextdate
\mysubsection{}
\nextdate
\mysubsection{}
\mysection{}
\end{document}
The above covers the relevant code. Output:
EDIT 2: I can get rid of the warnings mentioned above by surrounding the \StrLeft{\datemonthname}{3}
with \texorpdfstring{}{}
, but that does not fix the Table of Contents not updating correctly problem.
.toc
file you'll see what the problem is,\mysubsectiontitle
is never expanded before the data is written to the toc file (due to it being robust). The main problem seems to be\StrLeft{\datemonthname}{3}
is that is removed and\mysubsectiontitle
is a normal\newcommand
it does work.