5

I'd like to use (or define) an If-statement for pagestyle.
I have no idea :(

Update:
I'm using in my document about 4 pagestyles. Just as a little example I wish to have at the border of my document informations about jobname, date, time, lastsheet and sheetsequence AND size of the actual page. The size of the actual page is not everytime the same. That is why I thought, if I could define easy an if statement, it could be a great solution.

What I mean:

\ifthenelse{\equal{pagestyle}{numberone}}{size: $210 \times 297 $}{size: $420 \times 297$}

I hope it is clear now

2
  • 2
    Looking at the definition of \pagestyle reveals that the page style isn't stored explicitly. The \thispagestyle stores its argument in \@specialstyle, but this isn't very useful in general. Maybe if you are telling us what exactly you want to achieve we might be better able to help you. Every page style is defined by a \ps@<style> macro, e.g. \ps@plain for plain. Depending on your application you could add code to these macros instead of detecting the style. May 9, 2011 at 10:09
  • 2
    Perhaps you could tell us a little more about what you want to achieve? To my admittedly old blinkered way of thinking, "the document commands the pagestyle", yet you are asking that "the pagestyle commands the document". Some of us may find that a bit of a strange new idea; I'm sure we'd all like to understand it better. May 9, 2011 at 10:38

2 Answers 2

9

You can patch the page style declarations \pagestyle and \thispagestyle to record the page style in a macro.

\documentclass{report}
\usepackage{lipsum}
\usepackage{etoolbox}

\makeatletter
\pretocmd{\pagestyle}{%
  \gdef\@regularpagestyle{#1}%
  \gdef\thepagestyle{\if@specialpage\@specialstyle\else\@regularpagestyle\fi}
  }
{\message{(patching of \string\pagestyle\ succeeded)}}
{\message{(patching of \string\pagestyle\ failed)}}
\makeatother

%\pagestyle{empty}

\begin{document}

\chapter{Chapter One}

%\thepagestyle

\lipsum

\ifdef{\thepagestyle}{
  The page style is `\thepagestyle'.%
}{%
  There is no page style declared.
}

\end{document}

The commands \pretocmd and \ifdef require the e-TeX extensions. But not to fear; your TeX engine probably uses them. If not, there are workarounds.

EDIT Fixed to handle @Caramdir's observation. Now \thispagestyle expands to something which evaluates to the string input to \pagestyle or \thispagestyle. Testing against that string is going to be harder because you have to expand one more step.

5
  • 1
    Wouldn't this give the wrong page style, when tested on the page after a \thispagestyle? This means a \chapter would set \thepagestyle to plain.
    – Caramdir
    May 9, 2011 at 16:23
  • @Caramdir -- you are right! I tested it in a minimal example. But your idea, Matthew, is the same I meintioned.
    – Daniel
    May 9, 2011 at 16:31
  • 1
    @Caramdir: I guess you're right. There's nothing to set it back after ‘this page’. \begin{think} May 9, 2011 at 16:36
  • \end{think} @Caramdir I sort of fixed it. May 9, 2011 at 16:55
  • 1
    that's a full solution. It works nice with \ifthenelse. Thank you very much!
    – Daniel
    May 9, 2011 at 17:13
0

Only a test for the empty pagestyle is easy:

\makeatletter
\ifx\@evenfoot\@empty empty \else not empty\fi
\makeatother
3
  • I tried this out, but it didn't work. \documentclass{memoir} \begin{document} \pagestyle{empty} \makeatletter \ifx\@evenfoot\@empty empty \else not empty\fi \makeatother \end{document} it said "not empty"
    – Daniel
    May 9, 2011 at 16:20
  • @Daniel: I suppose that memoir has another definition of the pagestyles. I'll have a look
    – user2478
    May 9, 2011 at 17:53
  • @Daniel memoir redefines \evenfoot
    – user2478
    May 9, 2011 at 20:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .