2

I try to change the color of my chapter heading:

\documentclass{scrbook}
\usepackage{xcolor} 
\definecolor{myColor_MainA}{RGB}{0,64,119}
\addtokomafont{section}{\color{myColor_MainA}}
% \addtokomafont{chapter}{\color{myColor_MainA}}

\begin{document}
 \chapter{first}
 \section{here}
\end{document}

and get following error:

! Missing $ inserted.
<inserted text> 
                $
l.8  \chapter{first}

! Extra }, or forgotten $.
\size@chapter ->\huge \color {myColor_MainA}

l.8  \chapter{first}

! Missing $ inserted.
<inserted text> 
                $
l.8  \chapter{first}

! Missing } inserted.
<inserted text> 
                }
l.8  \chapter{first}
  • Remove the underscore _ from the color name. – sodd Aug 20 '15 at 14:57
2

It's a bug in KOMA-Script (2015/07/02 v3.18). The chapter uses the command \usefontofcomafont{chapter} which disables the color commands by assigning \color to \relax. This way, the argument of \color remains and the underscore in the name is typeset as text, causing trouble, because _ is not in math mode.

Workarounds:

  • A color name, which is can be processed in text mode without error (without underscore, see nordev's comment).

  • \string before the underscore also fixes the issue. The color name remains valid (the name is used inside \csname and \endcsname), and the name can be processed in text typesetting mode.

    \addtokomafont{chapter}{\color{myColor\string_MainA}}
    
  • Markus Kohm already answered that he expects this issue fixed in the next version of KOMA-Script. – Heiko Oberdiek Aug 20 '15 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.