0

When using \addchap{} in scrbook class sections below that chapter do not get the correct bookmark jump mark beyond the first use. In practice that means once you click on a bookmark that points you to a section in a chapter >1 you always end up in chapter 1. I've included an example: Once you click on the bookmark "Failing bookmark Second Introduction" it takes you to the section "First Introduction" instead of the corresponding one. scrhackdoesnt seem to help, how do I fix this?

The Failing bookmark is highlighted in this picture

\documentclass{scrbook}
\usepackage[english]{babel}
\usepackage[bookmarksopen,bookmarksopenlevel=0,bookmarksdepth=1]{hyperref} 
\usepackage{lipsum}
\usepackage{scrhack}
\begin{document}
\tableofcontents

\part{A part}
\addchap{First Chapter}
\section{First Introduction}
\lipsum[1-5]
\section{First Explanation}
\lipsum[4-5]

\part{Second part}
\addchap{Second Chapter}
\lipsum[6-7]
\section{Failing bookmark Second Introduction}
\lipsum[9-10]
\section{Failing bookmark Second Explanation}
\lipsum

\part{Working Bookmark Part}
\chapter{Working Bookmark Chapter}
\lipsum[6-7]
\section{Working Bookmark Introduction}
\lipsum[9-10]
\section{Working Bookmark Explanation}
\lipsum

\end{document}
  • You also get wrong section numbering. You have sections "0.1" below the \addchap. How do you want to handle this? – Ulrike Fischer Nov 1 '17 at 14:36
  • @UlrikeFischer - that is true - I'm removing that 0 by using \renewcommand*\thesection{\arabic{section}}-but it didn't seem relevant to the question for me, hence I had left it out. – nhck Nov 1 '17 at 14:40
  • @nhck: Why are you stripping the chapter number from the section number? This is confusing your readers (Having a reference for section 2 from first chapter and a section 2 from 4th chapter, for example -- which one do you mean then?) and asking for trouble. Now the hyper anchors must fail and the link goes wrong. If you don't need chapters at all, then use scrartcle or article instead – user31729 Nov 1 '17 at 15:56
  • @ChristianHupfer You are correct. I am implementing conference proceedings, so each paper is a chapter. The reason to go w/o numbers is more aesthetical/political and not reversable. In printed form it isn't too confusing. As for the pdf: it would be more usable if you could click the sections, but if it is not possible to set the right anchor I'll just skip them. – nhck Nov 1 '17 at 16:04
1

You need to ensure that \theHsection -- the id hyperref uses for the links -- is defined in a way that it is unique for every section. In your example it works by adding \thepart to \theHsection. If in your real document there are more unumbered chapters then you will have to add some additional counter that you increase at every \addchapter.

\documentclass{scrbook}
\usepackage[english]{babel}
\usepackage[bookmarksopen,bookmarksopenlevel=0,bookmarksdepth=1]{hyperref}
\usepackage{lipsum}
\usepackage{scrhack}
\renewcommand*\thesection{\arabic{section}}
\renewcommand\theHsection{\thepart-\HyperLocalCurrentHref-\thesection}
\begin{document}
\tableofcontents

\part{A part}
\addchap{First Chapter}
\section{First Introduction}
\lipsum[1-5]
\section{First Explanation}
\lipsum[4-5]

\part{Second part}
\addchap{Second Chapter}
\lipsum[6-7]
\section{Failing bookmark Second Introduction}
\lipsum[9-10]
\section{Failing bookmark Second Explanation}
\lipsum

\part{Working Bookmark Part}
\chapter{Working Bookmark Chapter}
\lipsum[6-7]
\section{Working Bookmark Introduction}
\lipsum[9-10]
\section{Working Bookmark Explanation}
\lipsum

\end{document}
  • Yes, that seems to work, unfortunately my minimal working example was too minimal b/c as soon as you have more than one chapter fore each part this stops to work. I guess that is basically due to \thechapter returning 0. I've tried to add an extra counter - but little luck. – nhck Nov 1 '17 at 15:56
  • 1
    You simply need a \newcounter{whatever}, use \thewhatever in \theHsection and then increment it before every \addchap with \stepcounter{whatever}. – Ulrike Fischer Nov 1 '17 at 16:06
  • I just saw that scrbook has some code for the anchors of \addchap. So you could try \renewcommand\theHsection{\HyperLocalCurrentHref-\thepart-\thechapter-\thesection} – Ulrike Fischer Nov 1 '17 at 16:19
  • Ha! Perfect. That works like I imagined it! Should we update it in your solution? edit: I added it. – nhck Nov 1 '17 at 16:45

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.