# Checking the mainmatter

I need to check where the text (from package .sty), if it is in the mainmatter section, then include some headers \pagestyle{LL}, if the other then \pagestyle{plain} or some other. Construction \ifx\@mainmattertrue\pagestyle{LL}\else\pagestyle{plain}\fi in:

    \NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{New}[2014/12/12]

\DeclareOption{LL}{\AtEndOfPackage{\llstyle}}
\ProcessOptions\relax

\RequirePackage{textcase}

\def\ps@LL{

%------------------Колонтитули---------------------
%------------------Верхні--------------------------
\vbox{\hbox to\textwidth{\strut
\small{\thepage\hfil\MakeUppercase{BlaBla}\hfil{GL}. \thechapter}}\hrule}}% конец блока
}% конец макроопределения

\vbox{\hbox to\textwidth{\strut
\small{{\S\hspace{1ex}}\thesection\hfil\MakeUppercase{Bla1}\hfil\thepage}}\hrule}}% конец блока
}% конец макроопределения

}

\def\@LLview{
\ifx\@mainmattertrue\pagestyle{LL}\else\pagestyle{plain}\fi
}

\def\llstyle
{
}

\endinput


does not work in

\documentclass[12pt,twoside]{book}
\usepackage[cp1251]{inputenc}
\usepackage[english]{babel}
\usepackage[LL]{New}
\usepackage{lipsum}

\begin{document}
\frontmatter
\chapter{Intro}
\lipsum[1-6]

\mainmatter
\chapter{One}

\lipsum[1-10]

\end{document}


Why?

• The standard book class makes that test for chapters, you can have a look at it. – Johannes_B Dec 18 '14 at 8:25
• Please add a little detail so we have something to test. – Johannes_B Dec 18 '14 at 8:25
• @Johannes_B I have done MWE in my post – sergiokapone Dec 18 '14 at 9:04
• If you want to activate the pagestyle with the start of mainmatter, redefine or patch mainmatter. When the package is executed, you cannot be in mainmatter. Next topic: Difference between \if and \ifx – Johannes_B Dec 18 '14 at 9:15

The book class defines the \if@mainmatter conditional. So

\if@mainmatter
<we are in the main matter>
\else
<we aren't in the main matter>
\fi


is the scheme for the code you need. For instance

\def\@LLview{%
\if@mainmatter
\pagestyle{LL}%
\else
\pagestyle{plain}%
\fi
}


This indentation style is not mandatory, but I find it convenient. With your style it could be

\def\@LLview{%
\if@mainmatter\pagestyle{LL}\else\pagestyle{plain}\fi
}


(the % at the end of the first line is needed).

Note that \if@mainmatter is initially set to true. The commands \frontmatter and \backmatter set it to false, while \mainmatter resets it to true.

The \@mainmattertrue command is used for setting the conditional to return true, and there's the similar \@mainmatterfalse.

• I try for code pointed in topic above. But again it does not work. \pagestyle{LL} is applied for \chapter{Intro} which is in frontmatter too. – sergiokapone Dec 18 '14 at 16:01
• @sergiokapone Of course: you just execute the command \@LLview once. It's probably better adding the page style declaration directly to the code for \frontmatter and \mainmatter. – egreg Dec 18 '14 at 16:05
• @egref Yes, you right. It is bertter to redefine \mainmatter – sergiokapone Dec 18 '14 at 16:13