2

I am having a hard time getting a running head working when using scrlayer-scrpage in conjunction with enotez. I already figured that is not possible at the moment to have endnotes for numbered and unnumbered chapters (see: here and here). Therefore, I removed the endnotes in my unnumbered chapters, unfortunately.

However, I’m still getting a wrong heading label for the last chapter when using \printendnotes in conjunction with koma-script’s scrlayer-scrpage.

enter image description here

Here is my MWE:

\documentclass[paper = 155mm:220mm]{scrbook}

\usepackage{blindtext}
\usepackage{libertine}

\usepackage{scrlayer-scrpage}% sets pagestyle scrheadings automatically
\automark{chapter}

\renewcommand*\chaptermark[1]{%
  \markboth{\ifnumbered{chapter}{\chaptermarkformat}{#1}}{#1}%
}

% enotez 
\usepackage{enotez}
\setenotez{
  list-heading = \addchap{#1},
  list-name = {Supplemental material by chapter},
  backref,
  split=chapter,
  reset=true,
  split-title={\chaptername\ <ref>: <title>}
}
\DeclareInstance{enotez-list}{chapter}{paragraph}{heading=\chapter{#1}}
\NewSplitTitleTag{title}{\nameref{ch:<split-level-id>}}


\usepackage{letltxmacro}
\LetLtxMacro\origchapter\chapter
\RenewDocumentCommand\chapter{som}{%
  \IfBooleanTF{#1}
    {% starred chapter, no label then
      \origchapter*{#3}%
    }
    {% else add a label
      \IfNoValueTF{#2}
        {\origchapter{#3}}
        {\origchapter[#2]{#3}}%
      \expanded{\noexpand\label{ch:\arabic{chapter}}}%
    }%
}

\usepackage{hyperref}

\begin{document}

\tableofcontents

\addchap{Prologue}
The first unnumberd chapter is the prologue.
\Blindtext[7]

\chapter{The First Day}
The first numbered chapter. This is something\endnote{That is the first day’s endnote. Something is a word.} you should consider.
\Blindtext[7]

\chapter{The Second Day}
The second numbered chapter. This is another\endnote{That is the second day’s endnote. Another is a word.} thing you should consider.
\Blindtext[7]

\chapter{The Third Day}
The third numbered chapter. I have no\endnote{That is the third day’s endnote. No means no yet.} idea what to talk about.
\Blindtext[7]

\addchap{Epilogue}
The last unnumberd chapter is the epilogue.
\Blindtext[7]

\printendnotes
\Blindtext[7]


\addchap{References}
\Blindtext[7]

\addchap{Literature}
\Blindtext[7]


\end{document}

Requirements

A solution should not break the running head

  • Running head for numbered chapters:
    • Left side (even): Chapter n
    • Right side (odd): Title of the chapter
  • Running head for unnumbered chapters: Title on both sides

Should I give up on scrlayer-scrpage, and try my luck fancyhdr instead?

EDIT

Note, if I switch to use chapter*{}, it will destroy my running head, yet if fixes the the listing \printendnotes

1 Answer 1

3

Well the log-file warns you quite explicitly: you have multiply defined labels, as \addchap uses \chapter internally and so issues labels too after your redefinition. Test for numbered chapters as you do it for \chaptermark.

You should also define \theHendnote to get unique destinations.

\documentclass[paper = 155mm:220mm]{scrbook}

\usepackage{blindtext}
\usepackage{libertine}

\usepackage{scrlayer-scrpage}% sets pagestyle scrheadings automatically
\automark{chapter}

\renewcommand*\chaptermark[1]{%
  \markboth{\Ifnumbered{chapter}{\chaptermarkformat}{#1}}{#1}%
}

% enotez
\usepackage{enotez}
\setenotez{
  list-heading = \addchap{#1},
  list-name = {Supplemental material by chapter},
  backref,
  split=chapter,
  reset=true,
  split-title={\chaptername\ <ref>: <title>}
}
\DeclareInstance{enotez-list}{chapter}{paragraph}{heading=\chapter{#1}}
\NewSplitTitleTag{title}{\nameref{ch:<split-level-id>}}


\usepackage{letltxmacro}
\LetLtxMacro\origchapter\chapter
\RenewDocumentCommand\chapter{som}{%
  \IfBooleanTF{#1}
    {% starred chapter, no label then
      \origchapter*{#3}%
    }
    {% else add a label
      \IfNoValueTF{#2}
        {\origchapter{#3}}
        {\origchapter[#2]{#3}}%
      \Ifnumbered{chapter}{\label{ch:\arabic{chapter}}}{}% %<--- only labels for numbered chapters
    }%
}

\usepackage{hyperref}
\newcommand\theHendnote{\arabic{chapter}.\theendnote} %<--- for hyperref
\begin{document}

\tableofcontents

\addchap{Prologue}
The first unnumberd chapter is the prologue.
\Blindtext[7]

\chapter{The First Day}
The first numbered chapter. This is something\endnote{That is the first day’s endnote. Something is a word.} you should consider.
\Blindtext[7]

\chapter{The Second Day}
The second numbered chapter. This is another\endnote{That is the second day’s endnote. Another is a word.} thing you should consider.
\Blindtext[7]

\chapter{The Third Day}
The third numbered chapter. I have no\endnote{That is the third day’s endnote. No means no yet.} idea what to talk about.
\Blindtext[7]

\addchap{Epilogue}
The last unnumberd chapter is the epilogue.
\Blindtext[7]

\printendnotes
\Blindtext[7]


\addchap{References}
\Blindtext[7]

\addchap{Literature}
\Blindtext[7]


\end{document}

enter image description here

4
  • Thank you so much! What is theHendnote what is that line actually doing: \newcommand\theHendnote{\arabic{chapter}.\theendnote}
    – Kalaschnik
    Jan 3, 2022 at 10:26
  • that is a command used by hyperref to make the counter unique. Jan 3, 2022 at 10:31
  • googling theHendnote hyperref leads to zero results — is that some secret hyperref thing? Just curious why hyperref needs this, since it should grant unique counters by design?
    – Kalaschnik
    Jan 3, 2022 at 10:36
  • 1
    hyperref uses (if it exists) \theH<counter> to create the destination names. Search for \theHsection or \theHchapter or so for examples. Jan 3, 2022 at 10:57

You must log in to answer this question.

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