1

There are quite a bit of related questions:

However, after trying out many of the suggested solutions (which are sometimes contradictory) for a couple of hours, and still failing, I thought I post this here now as another question (and hopefully I can add the solution to this case later).

In earlier variants of my code, even the link to glossaries and bibliography was broken, but that seems to work now. In this latest version, everything seems to work, except the link to figures and tables.

Note that the code comes from a template for a PhD thesis, and in principle I think I should not change too much in there.

Example code, test.tex:

\documentclass[listof=totoc]{scrbook}

\usepackage{amsmath}
\usepackage[Bjarne]{fncychap}
\usepackage{hyperref}

% for original fncychap
\makeatletter
\DeclareOldFontCommand{\rm}{\normalfont\rmfamily}{\mathrm}
\makeatother

\title{Thesis}

\begin{document}

\frontmatter

\tableofcontents

\mainmatter
\pagestyle{headings}

\chapter{Introduction}
...

\backmatter

\listoffigures
\listoftables

\end{document}

For reference, my Latex version:

$ pdflatex --version
pdfTeX 3.14159265-2.6-1.40.19 (TeX Live 2018)
kpathsea version 6.3.0
Copyright 2018 Han The Thanh (pdfTeX) et al.
There is NO warranty.  Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Han The Thanh (pdfTeX) et al.
Compiled with libpng 1.6.34; using libpng 1.6.34
Compiled with zlib 1.2.11; using zlib 1.2.11
Compiled with xpdf version 4.00

I already tried multiple things, but maybe in the wrong combination, or wrong import order, or wrong options, or so.

  • \phantomsection somewhat works, but it then links to the end of the previous chapter, not the beginning of the new chapter.
  • \usepackage{tocbibind} (or with some of the options) does not seem to work. More specifically:
    • \usepackage{tocbibind} (without options) adds a "Contents" chapter (which I don't want) and breaks the bibliography chapter link in the TOC. The glossary link still works, and the list of tables/figures link still does not work.
    • \usepackage[nottoc]{tocbibind} is like without options but without the extra "Contents" chapter.
    • \usepackage[nottoc,notlof,notlot]{tocbibind} is just the same as \usepackage[nottoc]{tocbibind}. notlof or notlot does not seem to have an effect.
  • index=totoc in the documentclass options (via) does not seem to have an effect.
  • \usepackage{nomencl} (with variants of the options) does not seem to have an effect.

Probably relevant are also the hyperref options. I think I need to have hypertexnames=false in there, as this was in the original template like this. Also, changing this seems to break other things.

Also, in some places, it is stated that hyperref should come first. In other places, it is stated that it should come last. In yet other places, it is stated that glossaries should come after hyperref.

I noticed, the \usepackage[Bjarne]{fncychap} seems to cause this. If I remove this, it works. However, I need to use it. (Also, I noticed that the template comes with the fncychap v1.34 package. However, if I use the normal one (from Tex Live 2018), I get the same problem. In addition, maybe some Class scrbook Error: undefined old font command \rm error, but that is easy to work around, and not related here.)


Edit: After randomly trying around, after the answer from Ulrike Fischer, without really understanding what I'm doing, I added this (right after the last \usepackage):

\makeatletter
\renewcommand\@schapter[1]{%
    \begingroup
      \let\@mkboth\@gobbletwo
      \Hy@GlobalStepCount\Hy@linkcounter
      \xdef\@currentHref{\Hy@chapapp*.\the\Hy@linkcounter}%
      \Hy@raisedlink{%
        \hyper@anchorstart{\@currentHref}\hyper@anchorend
      }%
    \endgroup
    \H@old@schapter{#1}%
   }
\makeatother

(I got this code from my /usr/local/texlive/2018/texmf-dist/tex/latex/koma-script/hyperref.hak file.)

And this seems to fix the problem... Maybe someone can explain why it works? Or if it really solves the problem, or maybe introduces other problems?


Further edit: In my fncychap.sty, I found this:

%%% Begin: To avoid problem with scrbook.cls (fncychap version 1.32)

%%OUT:
%\def\@schapter#1{\if@twocolumn
%                   \@topnewpage[\@makeschapterhead{#1}]%
%                 \else
%                   \@makeschapterhead{#1}%
%                   \@afterheading
%                 \fi}

%%IN:
\def\@schapter#1{%
\if@twocolumn%
  \@makeschapterhead{#1}%
\else%
  \@makeschapterhead{#1}%
  \@afterheading%
\fi}

%%% End: To avoid problem with scrbook.cls (fncychap version 1.32)

If I just remove that, it also seems to fix my problem? I wonder though, what is it what fncychap tried to fix here? I.e. what was meant by "avoid problem with scrbook.cls"?


As a side node, daleif argues in the comments that you better should avoid fncychap and scrbook if you can. fncychap was last updated in 2007.

14
  • 1
    Please reduce the example to only those pieces that are actually needed. – daleif Jul 7 '20 at 13:42
  • @daleif I reduced it further. Also I added a fix for some Tex Live versions and fncychap, it should compile now. Note that I want to have the glossaries in it, and also a table in it, because this combination is important. I don't want to fix the list of tables link but then introduce other problems in other parts. – Albert Jul 7 '20 at 14:00
  • 1
    The general idea is that you can trim things down to the minimal example that exhibits the problem (no bibliography, no glossary). Then you can figure out why your TOC isn't linking to particular tables or figures. Then you can put the fix into your actual project, and see if there is some new complication. But there usually isn't. (And if fncychap is contributing to the problem, that's only one extra line in your minimal example.) – Teepeemm Jul 7 '20 at 14:16
  • You should probably drop \usepackage[Bjarne]{fncychap} the hypertargets seems to work correctly when it is not loaded. When loaded things go wrong. Plus it has not been updated in 13 years. – daleif Jul 7 '20 at 14:27
  • Additionally load glossaries before hyperref (only cleverref needs to go after hyperref) – daleif Jul 7 '20 at 14:28
0

scrbook contains patches that it executes after hyperref has been loaded. In this patch it reverts the definition of the chapter commands and so overwrites the patches from hyperref. scrbook obviously doesn't expect that the chapter commands have be changed by some other package.

You can try this:

\documentclass[listof=totoc,
enabledeprecatedfontcommands]{scrbook}
%disable scrbook patch:
\makeatletter
\renewcommand\scr@chapter@after@hyperref@patch{}
\makeatother
\usepackage[Bjarne]{fncychap}


\usepackage[%
hypertexnames=false,%
bookmarks=true,%                   %%% generate bookmarks ...
bookmarksnumbered=true,%           %%% ... with numbers
]{hyperref}

\title{Thesis}

\begin{document}
\frontmatter
\tableofcontents

\mainmatter

\chapter{Introduction}
\chapter{Conclusion}

\backmatter

\listoffigures

\listoftables
\end{document}
4
  • I get LaTeX Error: \scr@chapter@after@hyperref@patch undefined. for that. Am I doing sth wrong? – Albert Jul 7 '20 at 14:53
  • Then your system is older than mine and I can't help you ... – Ulrike Fischer Jul 7 '20 at 14:57
  • Actually, your answer lead me to a somewhat working solution now. I extended my question. Maybe you have an idea if this is a valid option? – Albert Jul 7 '20 at 15:32
  • it could work. it is more or less what hyperref does and what scrbook destroys. – Ulrike Fischer Jul 7 '20 at 15:41
0

Download the latest fncychap package here, and copy the fncychap.sty into the directory of your Latex code.

Open the file. You will find some code like this:

%%% Begin: To avoid problem with scrbook.cls (fncychap version 1.32)

%%OUT:
%\def\@schapter#1{\if@twocolumn
%                   \@topnewpage[\@makeschapterhead{#1}]%
%                 \else
%                   \@makeschapterhead{#1}%
%                   \@afterheading
%                 \fi}

%%IN:
\def\@schapter#1{%
\if@twocolumn%
  \@makeschapterhead{#1}%
\else%
  \@makeschapterhead{#1}%
  \@afterheading%
\fi}

%%% End: To avoid problem with scrbook.cls (fncychap version 1.32)

Remove this code, or comment it out.

This seems to solve the problem.

scrbook has its own definition of \@schapter and this breaks it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.