1

In https://tex.stackexchange.com/a/512752/13492, it was shown how to produce both a short and a detailed table of contents (TOC) in a memoir document. And so that each of the two TOCs is listed as an entry in the other TOC but not in itself. (This method preserves any pagestyle the author uses.)

However, as soon as I load biblatex in such a document, on the 2nd pdflatex pass, it generates an error in creating the TOC.

The error:

(./test.toc

./test.toc:9: LaTeX Error: Something's wrong--perhaps a missing \item.
 ...                                                                                                
l.9 ...hapter}{Detailed Contents}{iii}{section*.2}
                                                  %

The toc file:

\boolfalse {citerequest}\boolfalse {citetracker}\boolfalse {pagetracker}\boolfalse {backtracker}\relax 
\defcounter {refsection}{0}\relax 
\@nameuse {MurderShort}
\defcounter {refsection}{0}\relax 
\contentsline {chapter}{Short Contents}{i}{section*.1}% 
\defcounter {refsection}{0}\relax 
\@nameuse {MurderLong}
\defcounter {refsection}{0}\relax 
\contentsline {chapter}{Detailed Contents}{iii}{section*.2}% 
\defcounter {refsection}{0}\relax 
\contentsline {chapter}{\chapternumberline {1}Chap}{1}{chapter.1}% 
\defcounter {refsection}{0}\relax 
\contentsline {section}{\numberline {1.1}Test}{1}{section.1.1}% 
\defcounter {refsection}{0}\relax 
\contentsline {subsection}{\numberline {1.1.1}Test}{1}{subsection.1.1.1}% 

The source:

\documentclass{memoir}

%% Same error created even if no bibresource
%\begin{filecontents}{mybib.bib}
%@article{wombat,
%   author   = {Walther Wombat},
%   title    = {The meaning of 42},
%   journal  = {Journal of skepticism},
%   date     = {2016},
%}
%\end{filecontents}

%%% SECTIONING:
\setsecnumdepth{subsection}

%% BIB:
% ERROR WITH biblatex used!
\usepackage[backend=bibtex,style=numeric]{biblatex}
%\addbibresource{mybib.bib}

%% CROSS-REF:
\usepackage[pdftex]{hyperref}
\hypersetup{colorlinks, citecolor=red}

% Short and detailed TOCs:
% daleif (https://tex.stackexchange.com/a/512752/13492)
\makeatletter
\newcommand\MurderShort{}
\newcommand\MurderLong{}
\newcommand{\longcontentsname}{Detailed Contents}
\newcommand{\shortcontentsname}{Short Contents}
\newcommand{\shorttableofcontents}[1][1]{%
  \begingroup
  \setcounter{tocdepth}{#1}
  \let\contentsname\shortcontentsname
  \addtocontents{toc}{\protect\@nameuse{MurderShort}}
  % only works with hyperref
  \renewcommand\MurderShort[5]{}
  \tableofcontents
  \endgroup
}
\newcommand{\longtableofcontents}[1][3]{%
  \begingroup
  \setcounter{tocdepth}{#1}
  \let\contentsname\longcontentsname
    \addtocontents{toc}{\protect\@nameuse{MurderLong}}
  % only works with hyperref
  \renewcommand\MurderLong[5]{}
  \tableofcontents
  \endgroup
}
\makeatother

%% FOR THIS TEST:
\usepackage{kantlipsum}

\begin{document}

\frontmatter
\shorttableofcontents[1]
\cleardoublepage
\longtableofcontents

\mainmatter
\chapter{Chap}\kant[1]
\section{Test}\kant[1]
\subsection{Test}\kant[1]

%\backmatter
%\printbibliography

\end{document}

Note that I deliberately commented out the \bibresource line, the fileconents block that creates the .bib file, and the \backmatter...\printbibliography -- because even if they are uncommented, exactly the same error occurs.

There is no TOC error if the \usepackage[...]{biblatex} is omitted! So there is some very strange (to me) interaction between biblatex and the two-TOCs code.

Here is the .toc file with everything the same except that the biblatex loading line is commented out (and everything works OK):

\@nameuse {MurderShort}
\contentsline {chapter}{Short Contents}{i}{section*.1}% 
\@nameuse {MurderLong}
\contentsline {chapter}{Detailed Contents}{iii}{section*.2}% 
\contentsline {chapter}{\chapternumberline {1}Chap}{1}{chapter.1}% 
\contentsline {section}{\numberline {1.1}Test}{1}{section.1.1}% 
\contentsline {subsection}{\numberline {1.1.1}Test}{1}{subsection.1.1.1}% 

Package versions:

There are currently the lastest at CTAN.

  • memoir 2018/12/12 v3.7h
  • biblatex 2019/08/31 3.13a
  • hyperref 2019/09/28 v7.00a
murray
  • 7,944
  • 1
    You can see it from the toc immediately, that murder trick only works if the chapter line is right after the murderer, here an extra line is injected. A line with four tokens and the murderer eats five thus the error. You might ge away with redefining the murderer to eat 9 args always leaving behind at least the first four. Btw don't give hyperref the pdftex option, it autodetects the engine. – daleif Oct 23 '19 at 22:23
  • @daleif: Sorry, I don't understand. Do you mean \newcommand\MurderShort[9]{} and \newcommand\MurderLong[9]{} but then inside the definitions of \newcommand\shorttableofconents and \newcommand\longtableofcontents to leave \renewcommand\MurderShort[5]{} and \renewcommand\MurderLong[5]{}? I tried that, and same error. If not that, what did you mean? In any case, why does the error occur only when biblatex is also loaded? – murray Oct 24 '19 at 00:49
  • 1
    Biblatex inserts this line \defcounter {refsection}{0}\relax, compare the toc with and without biblatex (you probably have to delete the toc in between). So, \renewcommand\MurderShort[5]{} could be changed to \renewcommand\MurderShort[9]{#1#2#3#4}` etc, this eats nine tokes and reinsert the first four (untested, I'm currently on a tablet), – daleif Oct 24 '19 at 06:25
  • @daleif Since the refsection counter is only useful if there is an actual ToC entry, \renewcommand\MurderShort[9]{} would also work. (I tested with \renewcommand\MurderShort[9]{} and it worked.) \renewcommand\MurderShort[9]{##1##2##3##4} doesn't quite work because the macro expansion eats the group, so it would need to be \renewcommand\MurderShort[9]{##1{##2}{##3}##4}. Do you want to write up a short answer? – moewe Oct 24 '19 at 06:28
  • @moewe feel free, I had forgotten the ## and bracing – daleif Oct 24 '19 at 06:35
  • @daleif I won't have time to write a proper answer until tonight, so I'd prefer you going for it, but if you haven't written one until then I can cobble something together. – moewe Oct 24 '19 at 06:40

1 Answers1

2

The toc you posted explains what is going on (thanks you for posting them).

biblatex seems to insert \defcounter {refsection}{0}\relax all over the place. No idea why. Presumably biblatex is patching the toc writing macros to include those lines. So now we have

\@nameuse {MurderShort}
\defcounter {refsection}{0}\relax 
\contentsline {chapter}{Short Contents}{i}{section*.1}% 

as oppose to

\@nameuse {MurderShort}
\contentsline {chapter}{Short Contents}{i}{section*.1}% 

which the murderer was designed for.

Luckily it is only 4 tokens extra

So you should be able to change

  \renewcommand\MurderShort[5]{}

to either

\renewcommand\MurderShort[9]{}

or if that line is actually used for something

\renewcommand\MurderShort[9]{##1{##2}{##3}##4}

or we'll have to patch biblatex's patch, which seems annoying to attempt.

daleif
  • 54,450
  • Either form of the \renewcommand\MurderShort (and similarly for MurderLong now does works without error -- but only if biblatex is loaded. If biblatex is not loaded, same error occurs in processing .toc even though nothing weird appears in the .toc (except the expected \@nameuse {MurderShort} and \@nameuse {MurderLong} lines. – murray Oct 24 '19 at 14:37
  • @murray exactly, because if how biblatex patches addcontentsline you have to choose what setup you use for your document. – daleif Oct 24 '19 at 14:41
  • It's still weird that biblatex is adding those lines to toc. I wonder why! – murray Oct 24 '19 at 15:38
  • @murray me too, makes it difficult to repatch as well. – daleif Oct 24 '19 at 15:44
  • One still troublesome detail: Even though the TOC code is used after hyperref is loaded, the link in Short Contents to "Detailed Contents" takes me to the first line of that Detailed Contents TOC (and similarly for the line in Detailed Contents to "Short Contents") rather than to the top of the other TOC's page. – murray Oct 24 '19 at 16:47
  • @murray Please post which package versions you're using – daleif Oct 24 '19 at 16:52
  • I added the package versions at the end of my OP here. (All should be latest from CTAN with TeXLive 2019.) – murray Oct 24 '19 at 17:18
  • @murray not at pc, so cannot test. Perhaps we need to do our own patching and step away from murderers. We'll need to insert an if construction before and after each entry made by each tableofcontents. Trouble here is to write an incomplete if to disk in a rwo step manner (first to the aux and then to the toc) will have a look when I'm at a pc – daleif Oct 24 '19 at 17:22