1

I'm using Markus Kohm's fix to include the prefix "Appendix" also in the table of contents. Unfortunately, this screws up the bookmarks (or indices) generated by hyperref, as shown in the screenshots below the MWE:

\documentclass[appendixprefix]{scrbook}

\usepackage{hyperref}
\usepackage{etoolbox}

%% From http://www.komascript.de/node/1766
\newcommand*{\SavedOriginaladdchaptertocentry}{}
\appto\appendixmore{%
  \let\SavedOriginaladdchaptertocentry\addchaptertocentry
  \renewcommand*{\addchaptertocentry}[2]{%
    \ifstr{#1}{}{% Eintrag ohne Nummer
      \SavedOriginaladdchaptertocentry{#1}{#2}%
    }{% Eintrag mit Nummer
      \SavedOriginaladdchaptertocentry{}{%
        \string\expandafter\string\MakeUppercase\string\appendixname
        ~#1\autodot\string\enskip{}#2}%
    }%
  }%
}


\title{Some title}  
\author{Some author}

\begin{document}
\maketitle 

\frontmatter
\tableofcontents               

\mainmatter
\chapter{Some chapter}

\appendix
\chapter{appendix chapter}
\section{Section in appendix}

\end{document}

Screenshot from Sumatra (pdfTeX, TeXLive 2015): enter image description here

Screenshot from evince (XeTeX, TeXLive 2013): enter image description here

Any ideas what's going on here?

1
  • The \string\expandafter\... line is of no meaning to the pdf viewer, because it's partially unexpandable LaTeX code and can't be understood as a bookmark entry. You need \texorpdfstring{texcontent}{pdfcontent} for this.
    – user31729
    Oct 16, 2015 at 8:07

2 Answers 2

3

The \string\expandafter\... line is of no meaning to the pdf viewer, because it's partially unexpandable LaTeX code (\MakeUppercase is the villain here!) and can't be understood as a bookmark entry. You need \texorpdfstring{texcontent}{pdfcontent} for this.

I've wrapped \texorpdfstring{...}{...} around the offending line and use \appendixname for the pdfcontent part -- \appendixname is expandable and replaced by Appendix (in English language settings)

\documentclass[appendixprefix]{scrbook}

\usepackage{hyperref}
\usepackage{etoolbox}

%% From http://www.komascript.de/node/1766
\newcommand*{\SavedOriginaladdchaptertocentry}{}
\appto\appendixmore{%
  \let\SavedOriginaladdchaptertocentry\addchaptertocentry
  \renewcommand*{\addchaptertocentry}[2]{%
    \ifstr{#1}{}{% Eintrag ohne Nummer
      \SavedOriginaladdchaptertocentry{#1}{#2}%
    }{% Eintrag mit Nummer
      \SavedOriginaladdchaptertocentry{}{%
        \texorpdfstring{\string\expandafter\string\MakeUppercase\string\appendixname
        ~#1\autodot\string\enskip{}#2}{\appendixname}}%
    }%
  }%
}


\title{Some title}  
\author{Some author}

\begin{document}
\maketitle 

\frontmatter
\tableofcontents               

\mainmatter
\chapter{Some chapter}

\appendix
\chapter{appendix chapter}
\section{Section in appendix}

\end{document}
1
  • The question is, if this is really needed to make it that complicated or is this an old fix to some older KOMA setup?
    – user31729
    Oct 16, 2015 at 8:19
2

Here is another suggestion:

enter image description here

Code:

\documentclass[appendixprefix]{scrbook}

\usepackage[hypertexnames=false]{hyperref}
\usepackage{etoolbox}

\appto\appendix{%
  \renewcommand{\addchaptertocentry}[2]{
    \ifstr{#1}{}{%
      \addtocentrydefault{chapter}{}{#2}%
    }{%
      \addtocentrydefault{chapter}{}{\chapapp~#1: #2}%
    }%
  }
}

\title{Some title}  
\author{Some author}

\begin{document}
\maketitle 

\frontmatter
\tableofcontents

\mainmatter
\chapter{Some chapter}

\appendix
\chapter{First appendix chapter}
\section{Section in first appendix}
\chapter{Second appendix chapter}
\section{Section in second appendix}
%
\addchap{Chapter without number}

\end{document}

You must log in to answer this question.

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