# Sometimes wrong math font in headers when using KOMA's \sectfont with lineno

I am using the KOMA-Script scrbook class, and I want to have bold math in my section titles (to match the title text). For this I redefine \sectfont, and it works nicely.

\renewcommand{\sectfont}{\bfseries\sffamily\mathversion{bold}}


I think the problem occurs when the double-page is just full, so that any more text would result in an overflow, and there has to be another section after the current page (so that the next page starts with a section header). Also it only happens when I use line numbers from \usepackage{lineno}.

Is lineno incompatible with KOMA-Script? Is there a better way to get bold math fonts in section titles (but not in the TOC and headers)?

I can of course just disable the line numbers as I will with my final document, but this bug makes me suspect I am doing something wrong, and something else might break. Also, I can just stuff \nolinenumbers into my \sectfont and it seems to work, but if I'm doing something wrong and fragile, then that would be just fixing the symptoms. A MWE is below (compare the top of page 6 with page 4 and 8):

\documentclass[paper=A4,11pt,headsepline,footsepline]{scrbook}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{blindtext}
\usepackage{lineno}

\renewcommand{\sectfont}{\bfseries\sffamily\mathversion{bold}}

\begin{document}

\tableofcontents
\cleardoublepage

\linenumbers

\chapter{Title $xyz$ containing $\chi^2$ math}
\section{Section $A$}
% this double-page is probably not full enough, but
% one more \blindtext will make it overflow
\blindtext\blindtext\blindtext\blindtext
\blindtext\blindtext\blindtext

\section{Section $B$}
% this double-page exhibits the bug.
\blindtext\blindtext\blindtext\blindtext
\blindtext\blindtext\blindtext\blindtext

\section{Section $C$}
% this double-page is identical, but doesn't exhibit the bug,
% since there is no section after it (?)
\blindtext\blindtext\blindtext\blindtext
\blindtext\blindtext\blindtext\blindtext

% uncomment this and the bug appears for section C, too:
%\section{Section $D$}
\end{document}

-
Add \mathversion{normal} to the head font, e.g. \renewcommand\headfont{\mathversion{normal}\normalfont}. –  Ulrike Fischer Mar 11 '14 at 10:10
Thanks, that worked! If you post it as an answer I can accept it. I guess using \mathversion{bold} in sectfont causes undefined behavior because it may or may not be invoked on a page, but there is nothing by default that undoes it - unlike \bfseries which is undone by \normalfont. –  jdm Mar 11 '14 at 10:31

Add \mathversion{normal} to the head font, e.g. \renewcommand\headfont{\mathversion{normal}\normalfont}.
And quite probably \addtokomafont{pageheadfoot}{\mathversion{normal}\normalfont} would work, too? –  Speravir Mar 11 '14 at 20:54