# Different style for frontmatter chapters in TOC

I am looking for a way to change the style of chapters in the TOC that belong to the front matter. Below I posted a minimal example code to illustrate my goal:

\documentclass{scrbook}
\begin{document}
\frontmatter
\chapter{Preface}
\chapter{Acknowledgements}
\tableofcontents
\mainmatter
\chapter{First Chapter}
\chapter{Second Chapter}
\end{document}


Here, I would like to have the two frontmatter chapters Preface and Acknowlegements to be written in non-bold italics in the TOC, including their page numbers. I manage to write their names in the required style by simply using e.g.

\chapter[\itshape\textmd{Preface}]{Preface}


but this does not change the formatting of the page number.

I define a new cs \matter@switch and appended it to the chapterentry KOMA font. Then I added macros to \frontmatter and \mainmatter which write a redefinition of \matter@switch to the toc file. (I'm sure the code below can be optimized)

\documentclass{scrbook}
\makeatletter
\newcommand\matter@switch{}
\protect\renewcommand\protect\matter@switch{\normalfont\itshape}%
}%
}
\protect\renewcommand\protect\matter@switch{}%
}%
}
\begin{document}
\frontmatter
\tableofcontents
\chapter{Preface}
\chapter{Acknowledgements}
\mainmatter
\chapter{First Chapter}
\chapter{Second Chapter}
\end{document}


This can be achieved by changing the chapter title font/page fonts using the tocloft package and its various commands, \cftchapterfont and \cftchapterpagefont. However, this commands persist until explicitly changed while the ToC is processed. Therefore it's necessary to write the switch back commands directly to the ToC using \addtocontents.

\documentclass{book}
\usepackage{tocloft}%
\begin{document}
\let\cftchapfontorig\cftchapfont
\let\cftchappagefontorig\cftchappagefont
\renewcommand{\cftchapfont}{\itshape}
\renewcommand{\cftchappagefont}{\itshape}%
\frontmatter
\chapter{Preface}
\chapter{Acknowledgements}
\tableofcontents

• Have you heard of \setkomafont and \usekomafont? This seems to be more appropriate than using a package. – Henri Menke Sep 16 '14 at 10:32
• @shiin: This should be answered by Henri Menke -- I provided a solution without \setkomafont -- it should work for other documentsclasses as well – user31729 Sep 16 '14 at 11:10
• @HenriMenke I tried using \setkomafont{chapterentry}{\sffamily\itshape} and \setkomafont{chapterentrypagenumber}{\sffamily\itshape}. While this changes the style, it's a global change and cannot simply be changed back for the chapters in the main matter. – shiin Sep 16 '14 at 11:36