I noticed, that if you underline headings with the use of ulem
and redefining \sectionlinesformat
(as done in this answer) does conflict with hyperref
. The conflict only occurs on unnumbered sections, subsections and subsubsections (regardless whether they are unnumbered due to a starred version, the usage of \addsec
or the setting of \setcounter{secnumdepth}{<number>}
), so essentially on those macros which use \sectionlinesformat
-- not on those which use \chapterlinesformat
(chapters).
The error doesn't occur if you don't expand the argument of the \headuline
macro (remove all \expandafter
s) or if you don't use hyperref
.
The problem is, without expanding the argument of \headuline
the headings are not breakable.
The error message is:
! Extra \else.
\H@old@ssect ...empty {#5}\@@par }\endgroup \else
\edef \@svsechd {\unexpand...
You can use the following MWE to reproduce the error:
\documentclass[a4paper,11pt]{scrreprt}
\usepackage[normalem]{ulem}
\makeatletter
\renewcommand{\chapterlinesformat}[3]{%
\setbox0\hbox{\expandafter\headuline\expandafter{#2}}% @hangfrom had no effect so I used this setup for chapters
\usebox0\parbox[t]{\dimexpr\textwidth-\wd0}{%
\expandafter\headuline\expandafter{#3}%
}%
}
\renewcommand{\sectionlinesformat}[4]{%
\@hangfrom{\hskip #2\expandafter\headuline\expandafter{#3}}%
{\expandafter\headuline\expandafter{#4}}%
}
\makeatother
\newcommand\headuline{%
\bgroup\markoverwith{\rule[-0.42ex]{0.25ex}{1.2pt}}\ULon%
}%
\setcounter{secnumdepth}{3}
\usepackage{hyperref}
\begin{document}
\chapter{This is a really long chapter heading and I'm proud of it. It is so
long it needs more than one row to be printed.}
\section{This is a really long section heading and I'm proud of it. It is so
long it needs more than one row to be printed.}
\subsection{This is a really long section heading and I'm proud of it. It is so
long it needs more than one row to be printed.}
\subsubsection{This is a really long section heading and I'm proud of it. It is so
long it needs more than one row to be printed.}
\chapter*{This is a really long chapter heading and I'm proud of it. It is so
long it needs more than one row to be printed.}
\section*{This is a really long section heading and I'm proud of it. It is so
long it needs more than one row to be printed.}
\subsection*{This is a really long section heading and I'm proud of it. It is so
long it needs more than one row to be printed.}
\subsubsection*{This is a really long section heading and I'm proud of it. It is so
long it needs more than one row to be printed.}
\end{document}