TransWikia.com

Conflict between tikz and tableofcontents

TeX - LaTeX Asked on August 12, 2021

To submit my paper, I need to use the Springer document class (link below). It turns out that it creates a conflict between Tikz and ‘tableofcontents’ which causes the compiler to not create a bibliography (go figure). If I remove either the Tikz declarations, and/or the table of contents command, the bibliography runs just dandy. I spent a while trying to understand where the conflict lies, but it is beyond me.

I stripped my file to the bare minimum, and added a sample bib file. Unfortunately, the class files are too long to post here directly, but here is the link from Springer’s webpage (only the svjour3.cls and svglov3.clo files are needed).

main.tex:

documentclass[smallextended]{svjour3}
%%% Springer class for Math Z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
usepackage{tikz}
usepackage{tikz-cd}
usetikzlibrary{positioning,arrows,calc}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

usepackage[backend=biber]{biblatex}
addbibresource{bibliography.bib}

begin{document}
title{Bibliography trouble}
author{GI Joe}

maketitle

%%%%%%%%%%%%%%%%
tableofcontents{}
%%%%%%%%%%%%%%%%

section{One section is enough for trouble}

{large
The Springer document class creates a clash between Tikz and Table of Contents. 

No bibliography entry is created for~cite{A} or~cite{B}. But if you comment the tikz package declarations (lines 5--7), {bf OR} if you comment the table of contents command (line 20), the bibliography runs just fine.} 

begin{center}{Large WHY!?}end{center}

nocite{*}
printbibliography

end{document}

bibliography.bib:

@article {A,
AUTHOR = {Arthur Ashe},
TITLE = {An able acorn},
JOURNAL = {Antarctica J.},
VOLUME = {1},
YEAR = {1901},
NUMBER = {1},
PAGES = {1--2}
}


@incollection {B,
AUTHOR = "Barry Bonds",
TITLE = "Bibliography blunders",
BOOKTITLE = "Bibliography Book",
PAGES = "1--100",
PUBLISHER = "Basic Books",
YEAR = "1901"
}

2 Answers

The problem seems to be the use of AtEndDocumet in the svjour3.cls. This code is used for set to small the font size of the contents. A possible workaround is just comment the are problematic lines in svjour3.cls,

1152c1152
<     %section*{contentsname}%
---
>     section*{contentsname}%
1154,1155c1154,1155
<     %addtocontents{toc}{begingroupprotectsmall}%
<     %AtEndDocument{addtocontents{toc}{endgroup}}%
---
>     addtocontents{toc}{begingroupprotectsmall}%
>     AtEndDocument{addtocontents{toc}{endgroup}}%

and set the font size of contents in the main document:

%%%%%%%%%%%%%%%%
section*{contentsname}%
{small
tableofcontents{}
}
%%%%%%%%%%%%%%%%

Original,

enter image description here

and with the workaround

enter image description here

Answered by Sergio Llorente on August 12, 2021

The problem is that the class tries to write at end document to the toc an endgroup:

 AtEndDocument{addtocontents{toc}{endgroup}}%

but tikz issues a clearpage first, and then the write is never executed.

As a work around you can add this to the preamble.

makeatletter
providecommand*protected@iwrite[3]{%
  begingroup
  letthepagerelax
  #2%
  letprotect@unexpandable@protect
  edefreserved@a{immediatewrite#1{#3}}reserved@a
  endgroup
  if@nobreakifvmodenobreakfifi
}
AtEndDocument{letprotected@writeprotected@iwrite}

makeatother

begin{document}

An alternative with a current latex is to redefine tableofcontents to use another hook:

makeatletter
renewcommandtableofcontents{%
    section*{contentsname}%
    @starttoc{toc}%
    addtocontents{toc}{begingroupprotectsmall}%
    AddToHook{shipout/lastpage}{addtocontents{toc}{endgroup}}%
    }

makeatother

Answered by Ulrike Fischer on August 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP