Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
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 9 '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 9 '11 at 10:38

2 Answers 2

up vote 8 down vote accepted

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.

share|improve this answer
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 '11 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 '11 at 16:31
1  
@Caramdir: I guess you're right. There's nothing to set it back after ‘this page’. \begin{think} –  Matthew Leingang May 9 '11 at 16:36
    
\end{think} @Caramdir I sort of fixed it. –  Matthew Leingang May 9 '11 at 16:55
1  
that's a full solution. It works nice with \ifthenelse. Thank you very much! –  Daniel May 9 '11 at 17:13

Only a test for the empty pagestyle is easy:

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.