# Scrreprt indent after chapter heading after patchcmd

In the following example, I've added a patch to the \chapter as an attempt to fix hyperref links. (See Hyperref chapter in twocolumn mode (without using multicols).)

\documentclass[parskip=half]{scrreprt}
\usepackage{hyperref}
\usepackage[twocolumn,landscape]{geometry}
\usepackage{etoolbox}
\makeatletter
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\chapter}{\@afterindentfalse}{\@afterindentfalse\leavevmode}{}{}
\makeatother

\usepackage{lipsum}

\begin{document}
\tableofcontents
\chapter*{Preface}%
\lipsum[1-5]
\chapter{Introduction}
\lipsum[1-5]
\section{Lipsum}
\lipsum[1-3]
\end{document}


This, however, gives me a weird indent only after non-starred \chapter headings. Some of the indent is removed by placing a % at the end, as \chapter{Introduction}%, but not all of it. For starred \chapter headings, the behaviour is similar, though I can remove the entire indent by using %.

The behaviour goes away when I comment out the line

\patchcmd{\chapter}{\@afterindentfalse}{\@afterindentfalse\leavevmode}{}{}


But this fails to solve the original problem. I've looked at the scrreprt.cls file to try to eyeball a bug, but don't have the expertise to identify it. The behaviour is only present in twocolumn format.

\newcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
\thispagestyle{\chapterpagestyle}%
\global\@topnum\z@
\@afterindentfalse
\SecDef\@chapter\@schapter
}
\newcommand*{\@chapter}{}
\def\@chapter[#1]#2{%
\ifnum \scr@osectarg=\z@
\@scr@tempswafalse
\else
\scr@istest#1=\@nil
\fi
\if@scr@tempswa
\else
\ifcase \scr@osectarg\relax
\or
\or
\or
\fi
\fi
\ifnumbered{chapter}{%
\refstepcounter{chapter}%
\@maybeautodot\thechapter
\typeout{\@chapapp\space\thechapter.}%
\ifx\scr@ds@tocentry\@empty\else
\fi
}{%
\ifx\scr@ds@tocentry\@empty\else
\fi
}%
\ifdim \@chapterlistsgap>\z@
\doforeachtocfile{%
\iftocfeature{\@currext}{chapteratlist}{%
}{}%
}%
}%
\fi
\if@twocolumn
\if@at@twocolumn
\else
\fi
\else
\fi
}
\use@chapter@o@preamble
\use@preamble{chapter@u}%
}
\@tempskipa=\glueexpr \scr@chapter@sectionbeforeskip\relax
\ifdim\@tempskipa<\z@\@tempskipa-\@tempskipa\fi
{%
\setlength{\parindent}{\z@}\setlength{\parfillskip}{\fill}%
\normalfont\sectfont\nobreak\nobreak\usekomafont{chapter}{}%
\def\IfUseNumber{\ifnumbered{chapter}}%
\if@chapterprefix
\raggedchapter
\let\IfUsePrefixLine\@firstoftwo
\let\@tempa\@firstofone
\else
\let\IfUsePrefixLine\@secondoftwo
\let\@tempa\@hangfrom
\fi
\@tempa{%
\IfUseNumber{%
\usekomafont{chapter}{%
\IfUsePrefixLine{%
{\usekomafont{chapterprefix}{%
}}%
}{%
\chapterformat
}%
}%
}{}%
}%
{%
\IfUsePrefixLine{}{\raggedchapter}%
\interlinepenalty \@M
\usekomafont{chapter}{#1}\par
}%
}%
\nobreak\par\nobreak
\@tempskipa=\glueexpr \scr@chapter@sectionafterskip\relax
\ifdim\@tempskipa<\z@\@tempskipa-\@tempskipa\fi
}

• \patchcmd{\chapter}{\@afterindentfalse}{\@afterindentfalse\leavevmode}{}{} is always going to destroy the spacing after a chapter head. Not doing that would be the start, but I couldn't see a clear description of the problem you are trying to solve. – David Carlisle Mar 1 '15 at 17:07
• It was a suggested solution to the problem of ensuring hyperlinks to chapter headings don't aim too low in twocolumn. – Hugh Mar 1 '15 at 17:10
• Can you provide a link to that suggested solution? KOMA is very sensitive in what it is doing. – Johannes_B Mar 1 '15 at 17:21
• tex.stackexchange.com/a/230582/18414 – Hugh Mar 1 '15 at 17:22

For me the combination of your code and the part of the cited question from Werner seems to work for me. The copied part starts with % copy from http://tex.stackexchange.com/questions/230577, Werner and ends at \begin{document}.

Please check the following MWE:

\documentclass[parskip=half]{scrreprt}

\usepackage[twocolumn,landscape]{geometry}
\usepackage{lipsum}
\usepackage{hyperref}

\usepackage{etoolbox}
%\makeatletter
%% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
%\patchcmd{\chapter}{\@afterindentfalse}{\@afterindentfalse\leavevmode}{}{}
%\makeatother

% copy from http://tex.stackexchange.com/questions/230577, Werner
% Add extra hyper target for chapter: chapter..\thechapter
\renewcommand*{\chapterformat}{%
\chapappifchapterprefix{\nobreakspace}\thechapter\autodot\enskip}%
}
\makeatletter
% Update \addcontentsline to jump to new hyper target _only_ if \chapter is used
{\Hy@writebookmark}% <search>
{\ifnum\pdfstrcmp{chapter}{#2}=0 % Chapter mark
\edef\@currentHref{chapter..\thechapter}%
\fi
\Hy@writebookmark}% <replace>
{}{}% <success><failure>
\makeatother

\begin{document}
\tableofcontents
\chapter*{Preface}%
\lipsum[1-5]
\chapter{Introduction}
\lipsum[1-5]
\section{Lipsum}
\lipsum[1-3]
\end{document}


The result for the preface: