2

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:

enter image description here

enter image description here

TOC:

enter image description here

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:

enter image description here

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.

6
  • 2
    Why don't you show usable code? tex.meta.stackexchange.com/a/10137/245790
    – MS-SPO
    Commented Feb 28 at 14:41
  • @MS-SPO Is that good?
    – user206144
    Commented Feb 29 at 2:12
  • 1
    If you take a look in the .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.
    – daleif
    Commented Feb 29 at 12:40
  • 1
    Also note that your three letter abbreviation is wrong for May.
    – daleif
    Commented Feb 29 at 12:42
  • 2
    Just for etiquette @MikeSmith, the question space should be reserved for questions only and the answer space for answers, editing the answer into your question was done with the best intentions and I know you are new but please don't do that, it clutters up the questions :) I've +1 to counteract your -1 question score that someone probably gave you for that, hope you ask more questions here :) Feel free to clean your question up like you did in your edit but don't put an answer in it please
    – piJT
    Commented Feb 29 at 13:56

1 Answer 1

2

Not 100% sure why \StrLeft is so bad here. But I chose a different route. By doing the month list manually we can ensure that there are no abbreviation dot after May.

\documentclass[12pt]{article}
\usepackage{xstring}
\usepackage{datenumber}
\setdatenumber{2024}{02}{26}
\newcommand\AbrevMonth{%
  \ifcase\value{datemonth}%
  \or Jan.%
  \or Feb.%
  \or Mar.%
  \or Apr.%
  \or May%
  \or Jun.%
  \or Jul.%
  \or Aug.%
  \or Sep.%
  \or Oct.%
  \or Nov.%
  \or Dec.%
  \fi%
}
\newcommand{\mysectiontitle}{\datemonthname~\thedateyear}
\newcommand{\mysection}[1]{\section{\mysectiontitle #1}}

\newcommand\mysubsectiontitle{Week of \AbrevMonth\ \thedateday, \thedateyear}
\newcommand{\mysubsection}[1]{\subsection{\mysubsectiontitle}}

\begin{document}


\tableofcontents

\mysection{}

\mysubsection{}
\nextdate
\mysubsection{}
\nextdate
\mysubsection{}
\nextdate
\mysubsection{}
\nextdate
\mysubsection{}

\mysection{}

\end{document}

You must log in to answer this question.