1

Is it possible to use \MakeUppercase in KOMA-Script’s \sectionlineformat to get uppercase section headers without breaking hyperef’s PDF bookmarks? The following example shows the problem. The \addsec headline in the bookmarks points to the firs page (i.e. what hyperref/TeX thinks is a “a fixed one”).

\documentclass{scrartcl}

\usepackage{hyperref}

\makeatletter
\renewcommand\sectionlinesformat[4]{%
   \ifstr{#1}{section}{%
      \@hangfrom{\hskip#2\relax #3}{\MakeUppercase{#4}}%
%      \@hangfrom{\hskip#2\relax #3}{\texorpdfstring{\MakeUppercase{#4}}{#4}}% doesn't work
   }{%
      \@hangfrom{\hskip#2\relax #3}{#4}%
   }%
}
\renewcommand{\sectionformat}{\MakeUppercase}
\makeatother

\begin{document}
Test
\clearpage
\addsec{Addsec on page 2}
Text
\end{document}

The \texorpdfstring trick doesn’t work. I already found out that hypperref seems to “inject” something in the #4 argument of \sectionlinesformat where the \MakeUppercase happens to break the “injection”.

Is it possible to use \MakeUppercase here at all, or is there another way of getting upper case section headers?

1 Answer 1

2

You're missing \phantomsection:

\documentclass{scrartcl}

\usepackage{hyperref,bookmark}

\makeatletter
\renewcommand\sectionlinesformat[4]{%
   \ifstr{#1}{section}{%
      \@hangfrom{\hskip#2\relax #3}{\phantomsection\MakeUppercase{#4}}%
   }{%
      \@hangfrom{\hskip#2\relax #3}{#4}%
   }%
}
\makeatother

\begin{document}
Test
\clearpage
\addsec{Addsec on page 2}
Text
\clearpage
\addsec{Addsec on page 3}
Text
\end{document}

Loading bookmark is usually recommended, but it's not essential for the solution.

3
  • That was easy. Thanks! Could you pleas explain a bit, why the phantom section is nessecary here?
    – Tobi
    Jul 22, 2018 at 22:06
  • @Tobi The title wants to go in the bookmarks, so an anchor needs to be made. I don't know what scrartcl does normally or whether hyperref patches it. A good start would be to look at the meaning of \sectionlinesformat after \begin{document}
    – egreg
    Jul 23, 2018 at 7:19
  • Hi, sorry for the late reply! It seems like hyperref uses \NR@ssect, but adding \MakeUppercase at a lower level is impossible since the “knowledge” of the section type isn’t available anymore. I stuck to adding the \phantomsection and it worked fine.
    – Tobi
    Aug 5, 2018 at 21:06

You must log in to answer this question.

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