1

I try to add custom line in TOC. I use \cftaddnumtitleline as described in memoir manual

\documentclass{memoir}
\begin{document}

  \tableofcontents*

  \cftaddnumtitleline{toc}{section}{1. }{First}{\thepage}
  First text
  
  \cftaddnumtitleline{toc}{section}{2. }{Second}{\thepage}
  Second text 
\end{document}

I expect, that I will see the section-like entries in TOC. But instead I got:

enter image description here

How should I fix it? Or is there other way to add custom TOC line?

UPDATE: It seams like a memoir bug that affects latest version:

  • memoir 2021/03/23 v3.7o bug does not exist
  • memoir 2022/07/29 v3.7r bug exists
  • memoir 2022/11/17 v3.7.19 bug exists
6
  • 1
    I just copied your code and run it pdflatex pdflatex on Windows 10 TexWorks (with TeXlive 2021) and cannot replicate your image (this is how mine compiles). Can you include more details on your system, TeX version etc please?
    – JamesT
    Feb 10, 2023 at 15:05
  • 1
    Tried in overleaf and got the same result overleaf.com/read/vyppwstgwrbr This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022) (preloaded format=pdflatex 2022.8.9) 10 FEB 2023 15:06 entering extended mode \write18 enabled. %&-line parsing enabled. **main.tex (./main.tex LaTeX2e <2022-06-01> patch level 5 L3 programming layer <2022-08-05> (/usr/local/texlive/2022/texmf-dist/tex/latex/memoir/memoir.cls Document Class: memoir 2022/07/29 v3.7r configurable book, report, article document class Feb 10, 2023 at 15:08
  • 1
    On local setup This is LuaHBTeX, Version 1.15.0 (TeX Live 2022) (format=lualatex 2023.2.5) 10 FEB 2023 14:51 restricted system commands enabled. Document Class: memoir 2022/11/17 v3.7.19 configurable book, report, article do cument class Feb 10, 2023 at 15:09
  • 2
    Very strange. On my first LeTeX run of your MWE on a ubuntu systemI get a ToC that looks normal, but on a second run, without changing any code, I get your result. I gave up maintaining memoir some years ago and have no idea what might be causing this. Apologies. Feb 10, 2023 at 19:06
  • 2
    My memory is certainly not what it was but I have a vague recollection that some time ago the LaTeX kernel code was updated. Perhaps the kernel and memoir coders weren't synchronized. (It's always good to blame someone else!). Feb 10, 2023 at 19:18

1 Answer 1

1

I found a solution that appears to work on Overleaf, add this command to the preamble:

\renewcommand{\cftaddnumtitleline}[5]{%
  \addtocontents{#1}%
    {\protect\contentsline{#2}{\protect\numberline{#3}%
                              {\protect\ignorespaces #4}}{#5}\newline}}

I added the \newline at the end of the command after {#5}. It produces this (on Overleaf):

enter image description here

Code:

\documentclass{memoir}

\renewcommand{\cftaddnumtitleline}[5]{%
  \addtocontents{#1}%
    {\protect\contentsline{#2}{\protect\numberline{#3}%
                              {\protect\ignorespaces #4}}{#5}\newline}}

\begin{document}
\tableofcontents*

\cftaddnumtitleline{toc}{section}{1. }{First}{\thepage}
First text
  
\cftaddnumtitleline{toc}{section}{2. }{Second}{\thepage}
Second text 
\end{document}

The original command looks like this (after going on CTAN for memoir and finding the .dtx file):

\newcommand{\cftaddnumtitleline}[5]{%
  \addtocontents{#1}%
    {\protect\contentsline{#2}{\protect\numberline{#3}%
                              {\protect\ignorespaces #4}}{#5}}}

I have no idea what broke for your TOC to look like that, way above my understanding, but for the maintainer there was an update for the kernel as @Peter Wilson pointed out in the comments that corresponds with my version working (v3.7o) and then your version containing the bug (3.7r).

% \changes{v3.7o}{2021/03/23}{Maintenance and a provide for the kernel}
% \changes{v3.7p}{2021/06/16}{Small adjustments of memoir vs memhfixc}
% \changes{v3.7q}{2022/02/20}{Maintenance}
% \changes{v3.7r}{2022/07/29}{Maintenance}
% \changes{v3.7.19}{2022/11/17}{Maintenance}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .