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.

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?

share|improve this question
    
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
add comment

2 Answers 2

up vote 4 down vote accepted

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

\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}
share|improve this answer
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 at 17:31
    
@daleif You're right! That's a much simpler approach. I'll edit my answer. –  Jubobs Apr 11 at 17:45
add comment

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}%
}
\LoadClass{memoir}
\DeclareOption{a5paper}{% do stuff
}
\DeclareOption{a4paper}{% do other stuff
}
\ProcessOptions\relax
% rest of your header goes here

Then your actual document just starts with

\documentclass{MyClass}
share|improve this answer
    
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
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. –  Joseph Harriott Apr 15 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 at 20:42
add comment

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.