# Memoir, how to make \makechapterstyle aware if chapter title is in frontmatter?

for my book i define own chapter style which i like to use only in body of document (after \mainmatter). in front matter i like to preserve default memoir chapter style.

background:

my chapter style gives the following result:

in the front matter i increase text width to the right border of chapter title (see mwe below). consequently chapter title is pushed out of page (in this case title of table of content, i.e.: "Content").

to make it visible, i looking for how to make my chapter style aware, where is used. for star i like to have in front matter memoir default style.

mwe:

\documentclass{memoir}
\usepackage{lmodern}
\usepackage{tikz}
%---------------------------------------------------------------%
\newlength{\marginwidth}
\setlength{\marginwidth}{\dimexpr\marginparsep+\marginparwidth\relax}
\newsavebox{\bookbox}
\newcommand{\zfcbookname}[1]{\sbox{\bookbox}{\textsc{#1}}}
\zfcbookname{<book title>}
%---------------------------------------------------------------%
\makechapterstyle{zfcBook}{%
\setlength\beforechapskip{9\baselineskip}
\setlength\afterchapskip{7\baselineskip}
\setlength\midchapskip{1\baselineskip}
\renewcommand*{\chaptitlefont}{\normalfont\Huge\bfseries}
\renewcommand*{\chapnamefont}{\chaptitlefont}
\renewcommand*{\chapnumfont}{\bfseries\fontsize{77}{84}\selectfont}
\renewcommand*{\printchaptername}{}
\renewcommand*{\printchapternum}{%
\begin{tikzpicture}
%-------
\node[name=chapter,
rectangle,fill=white,minimum width=\textwidth,minimum height=22mm,
\node[above left] at (chapter.south east) {
\ifanappendix\chaptitlefont\@chapapp\fi
\chapnumfont\thechapter};
\node[below right=1mm and 0mm] at (chapter.south west) {\usebox{\bookbox}};
%-------
\end{tikzpicture}
}%end od print chapter num
\renewcommand*{\printchaptertitle}[1]{
\raggedleft{\chaptitlefont ##1}\par\nobreak%
}% end of print chapter title
}%end of zfcBook
%---------------------------------------------------------------%
\usepackage{lipsum}

\begin{document}
\chapterstyle{zfcBook}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\frontmatter
\changetext{0pt}{\marginwidth}{-\marginwidth}{0pt}{0pt}
\tableofcontents                                % kazalo
\changetext{0pt}{-\marginwidth}{\marginwidth}{0pt}{0pt}
\mainmatter

\chapter{ena}
\lipsum[11]
\section{ena ena}
\section{ena dva}
\section{ena tri}
\chapter{dva}
\section{dva ena}
\section{dva dva}
\section{dva tri}
\end{document}


question:

how to change my \makechapterstyle that it will be aware of \frontmatter and there use or default memoir style or new defined style (very different from one used in \mainmatter)?

• i just "discover" a simple solution: move \chapterstyle{zfcBook} after \mainmatter ... it seems that i should delete my question :-( Jan 1, 2018 at 17:38
• Inside \frontmatter the numbered version is not used, so you can add stuff to \printchapternonum, which will be executed under \chapter* and within frontmatter. I sometimes add a switch in \printchapternonum when I have all the typesetting (name and number) inside \printchaptertitle, then I can distinguish between the two cases. Feb 1, 2018 at 10:04

Does \if@mainmatter...\else ...\fi inside \makechapterstyle help?

\frontmatter sets \@mainmatterfalse.

\documentclass{memoir}
\usepackage{lmodern}
\usepackage{tikz}
%---------------------------------------------------------------%
\newlength{\marginwidth}
\setlength{\marginwidth}{\dimexpr\marginparsep+\marginparwidth\relax}
\newsavebox{\bookbox}
\newcommand{\zfcbookname}[1]{\sbox{\bookbox}{\textsc{#1}}}
\zfcbookname{<book title>}
%---------------------------------------------------------------%

\makeatletter
\makechapterstyle{zfcBook}{%
\if@mainmatter
\setlength\beforechapskip{9\baselineskip}
\setlength\afterchapskip{7\baselineskip}
\setlength\midchapskip{1\baselineskip}
\renewcommand*{\chaptitlefont}{\normalfont\Huge\bfseries}
\renewcommand*{\chapnamefont}{\chaptitlefont}
\renewcommand*{\chapnumfont}{\bfseries\fontsize{77}{84}\selectfont}
\renewcommand*{\printchaptername}{}
\renewcommand*{\printchapternum}{%
\begin{tikzpicture}
%-------
\node[name=chapter,
rectangle,fill=white,minimum width=\textwidth,minimum height=22mm,
\node[above left] at (chapter.south east) {
\ifanappendix\chaptitlefont\@chapapp\fi
\chapnumfont\thechapter};
\node[below right=1mm and 0mm] at (chapter.south west) {\usebox{\bookbox}};
% -------
\end{tikzpicture}
}%end od print chapter num
\renewcommand*{\printchaptertitle}[1]{
\raggedleft{\chaptitlefont ##1}\par\nobreak%
}% end of print chapter title
\else
\chapterstyle{default}% Is done anyway...
\fi
}%end of zfcBook
\makeatother
%---------------------------------------------------------------%
\usepackage{lipsum}

\begin{document}
\chapterstyle{zfcBook}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\frontmatter
\changetext{0pt}{\marginwidth}{-\marginwidth}{0pt}{0pt}
\tableofcontents                                % kazalo
\changetext{0pt}{-\marginwidth}{\marginwidth}{0pt}{0pt}
\mainmatter

\chapter{ena}
\lipsum[11]
\section{ena ena}
\section{ena dva}
\section{ena tri}
\chapter{dva}
\section{dva ena}
\section{dva dva}
\section{dva tri}
\end{document}

• yes, on first i looking exactly for this, so i will accept your answer. but meanwhile i found simple solution (see my comment below question). it seems that due to holidays my brain is not full operational :-). Jan 1, 2018 at 17:43