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

lockstep
  • 250,273
Daniel
  • 449
  • 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. – Martin Scharrer May 09 '11 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. – Brent.Longborough May 09 '11 at 10:38

2 Answers2

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.

Matthew Leingang
  • 44,937
  • 14
  • 131
  • 195
0

Only a test for the empty pagestyle is easy:

\makeatletter
\ifx\@evenfoot\@empty empty \else not empty\fi
\makeatother
  • 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 09 '11 at 16:20
  • @Daniel: I suppose that memoir has another definition of the pagestyles. I'll have a look –  May 09 '11 at 17:53
  • @Daniel memoir redefines \evenfoot –  May 09 '11 at 20:52