4

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{

     %------------------Колонтитули---------------------
     %------------------Верхні--------------------------
     \renewcommand{\@evenhead}%
     {\raisebox{0pt}[\headheight][0pt]{% начало блока
            \vbox{\hbox to\textwidth{\strut
                    \small{\thepage\hfil\MakeUppercase{BlaBla}\hfil{GL}. \thechapter}}\hrule}}% конец блока
     }% конец макроопределения

     \renewcommand{\@oddhead}%
     {\raisebox{0pt}[\headheight][0pt]{% начало блока
            \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
{
\@ifclassloaded{book}{\@LLview}{}
\@ifclassloaded{extbook}{\@LLview}{}
}

\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?

sergiokapone
  • 5,578
  • 1
  • 16
  • 39

1 Answers1

4

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.

egreg
  • 1,121,712
  • 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