I've never done any coding in Latex than involves anything too complex (anything more than just writing and customizing a few stuff here and there), so I'm having troubles finding what I need to do this.

I need my project to compile in two size, a4paper and a5paper, passed as an option to the \documentclass[]{article} command.

I just select and option, produce a pdf, then change it to a5 and compile again. Now there are some parts of the document that should be different if it's on a5 or a4 mode, and I don't know how to do it.

How could I do so? Something like

\if @pagesize=a4paper
    do stuff

that works?

Thank you in advance.

EDIT: I've read that the old PlainTeX conditionals can lead to unexpected behaviour in some cases, but what I would do inside would be really simple, like putting \hspaces and things like that, so if it's simple with those conditional, I'd like to use them. Obviously if it can be better done any other way, I would like to know it too.

2 Answers 2


As far as I know, the paper size options are not directly stored in a macro, but this could work.

I've introduced a plain \newif\ifafourpaper which defaults to false and is set to true, if the a4paper option is used.

From article.cls, I stole the \DeclareOption for a4paper and a5paper respectively, where the boolean macro \ifafourpaper is set accordingly.


It's necessary to use \ProcessOptions explicitly, since the options declarations has changed!





   {\setlength\paperheight {297mm}%
    \setlength\paperwidth  {210mm}%
   {\setlength\paperheight {210mm}%
    \setlength\paperwidth  {148mm}%



  • @MyUserIsThis: You're welcome! Happy TeXing.
    – user31729
    May 31, 2015 at 22:12
  • I'm sorry, but it always considers \afourpapertrue, also in a5paper mode. I've included de \ProcessOptions line May 31, 2015 at 22:13
  • @MyUserIsThis: Yes, there was a small typo in my code. I updated already some 5 minutes ago
    – user31729
    May 31, 2015 at 22:14
  • @MyUserIsThis: No problem, my typo caused your distraction ;-)
    – user31729
    Jun 1, 2015 at 1:10
  • 1
    I suggest using \DeclareOption{a4paper}{\afourpapertrue\DeclareOption{a4paper}\PassOptionsToClass{a4paper}{article}} and \DeclareOption{a5paper}{\afourpaperfalse\DeclareOption{a5paper}\PassOptionsToClass{a5paper}{article}} as there may be other things that the document class does with the a4/a5 options. In fact, this doesn't seem to be the case with the article class but it might be for other document classes.
    – user30471
    Jun 1, 2015 at 10:10

Assuming you aren't using landscape mode, you can base your decision on the paper height as stored by the class.


  \uppercase{\ifdim\csname #1@PAPER\endcsname}=\paperheight


  We're using A4 paper
  We're not using A4 paper

  We're using A5 paper
  We're not using A5 paper


enter image description here

The output changes to

enter image description here

if \documentclass[a5paper]{article} is used.

Note that you're free to use either A5 or a5; I defined values for the arguments corresponding to a4, a5, b5, letter, legal and executive, which are all the sizes known to article and the other standard classes. Other values can be added at will.

  • Thank you for your answer. I will surely use it in the future, as it extends a little bit the first answer. Is there any reason you define all of them in capital letters? Does LaTeX differentiate between capital and small letters? Jun 1, 2015 at 13:56
  • @MyUserIsThis I decided to support both uppercase and lowercase letters because the “official” names for ISO paper formats are A0, A1, A2, A3, A4 and so on. With that definition, which however has the defect of not being fully expandable, you need not worry about the capitalization. If you need a fully expandable version, the \uppercase trick must be removed.
    – egreg
    Jun 1, 2015 at 14:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .