# Is there a way to query the page size that I have set in the memoir class?

In my preamble, I have:

\documentclass[a5paper,10pt,oneside,onecolumn,openany]{memoir}


I would like to later define some layout options based on the value of the page size, which in this case is a5paper. I've looked a little at pgfkeys, and discovered that it can't be called before \documentclass, while keyreader could be, but maybe there's infact a stock size or page size value that I'm effectively setting while calling memoir, that I could use as a trigger for subsequent conditional actions.

Or maybe I should try defining a key after calling memoir, and then later use the geometry package to set the page size (and other things) accordingly?

-
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Jubobs Apr 15 at 16:28
@Jubobs, I've now implemented your first suggestion, using \@ifclasswith, and it's just what I need for now. –  Joseph Harriott Apr 15 at 18:46

You can (see daleif's comment) use the LaTeX kernel macro called \@ifclasswith to test whether or not the a5paper option was passed to memoir, and do different things accordingly. One potential downside of this approach is that using \@ifclasswith is only allowed in the preamble, not in the body of the document.

\documentclass[a5paper,10pt,oneside,onecolumn,openany]{memoir}

\usepackage{lipsum} % for filler text

\makeatletter
\@ifclasswith{memoir}{a5paper}
{%
% If the a5paper option was passed to memoir...
% do something interesting; for instance:
\AtBeginDocument{The pagesize is \texttt{a5paper}.\par}
}{%
% Otherwise...
% do something else.
}
\makeatother

\begin{document}

\lipsum[1]

\end{document}


## Alternative solution

According to the memoir source code, passing the a5paper class option merely triggers

\newcommand*{\stockav}{\stockheight=210mm \stockwidth=148mm}


Therefore, if an alternative approach is needed, you can perform tests on the values of \stockheight and \stockwidth instead.

\documentclass[a5paper,10pt,oneside,onecolumn,openany]{memoir}

\usepackage{lipsum} % for filler text

\begin{document}

% test for a5paper
\ifdim\stockheight=210mm\relax
\ifdim\stockwidth=148mm\relax
% Put here what should only be applied only if the page size corresponds to A5 paper.
% For instance...
The pagesize is \texttt{a5paper}.\par
\fi
\fi
\lipsum[1] % for filler text

\end{document}

-
Untested but can't you use ifclassloadedwith, or what ever it is called. There is a macro to test class or package options –  daleif Apr 11 at 17:31
@daleif You're right! That's a much simpler approach. I'll edit my answer. –  Jubobs Apr 11 at 17:45

It sounds to me what you're actually trying to do is write your own document class. So put the part of your current header that should be part of that class in MyClass.cls and make it look like this:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{MyClass}
\DeclareOption∗{\PassOptionsToClass\CurrentOption}{memoir}%
}
\DeclareOption{a5paper}{% do stuff
}
\DeclareOption{a4paper}{% do other stuff
}
\ProcessOptions\relax

\documentclass{MyClass}

Hmmm... what if the OP already has many documents using the memoir class that he wants to refactor? Changing to MyClass might be tedious. –  Jubobs Apr 11 at 15:15
I only have one, and @Jubobs' \@ifclasswith{memoir}{a5paper} test was simple to implement. For the moment, I'm only needing paper-size-based geometry settings, but if I need more, MyClass might be useful. –  Joseph Harriott Apr 15 at 18:54