In my preamble, I have:


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?

  • @Jubobs, I've now implemented your first suggestion, using \@ifclasswith, and it's just what I need for now. – JosephHarriott Apr 15 '14 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.

enter image description here


\usepackage{lipsum} % for filler text

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




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.


\usepackage{lipsum} % for filler text


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

  • 1
    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 '14 at 17:31
  • @daleif You're right! That's a much simpler approach. I'll edit my answer. – jub0bs Apr 11 '14 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:

\DeclareOption{a5paper}{% do stuff
\DeclareOption{a4paper}{% do other stuff
% rest of your header goes here

Then your actual document just starts with

  • Hmmm... what if the OP already has many documents using the memoir class that he wants to refactor? Changing to MyClass might be tedious. – jub0bs Apr 11 '14 at 15:15
  • 1
    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. – JosephHarriott Apr 15 '14 at 18:54
  • The most significant difference between the two approaches is that in the one case you're directly checking if a specific option was used while in the other you use an indirect test. Also, I was assuming that you in essence do want to implement your own document class in which case my solution would have been conceptually nicer. It is slightly more complicated though. – Christian Apr 15 '14 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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