# How to decide for the format of exam in (the beginning of) preamble

I use the exam class to produce exams with Latex. The exam can be in A3 format for small ones (Mid-Term's and so), or in A4 format. I can decide this, using the geometry package. I use some packages and own commands, where a part of these commands must be placed before the geometry package, and another part after.

I use the "toggle" commands, from the etoolbox package, to decide whether I'm in A4 format or not. This command must be putted, of course, before the geometry package.

I give a MWE, where you can try the effect of the two commands \toggletrue{A4Exam} and \togglefalse{A4Exam}

\documentclass[12pt]{exam}

%%\usepackage{PreCommands}    %%% Packages and Commands before geometry

\usepackage{etoolbox}
\newtoggle{A4Exam}
\toggletrue{A4Exam}
\togglefalse{A4Exam}

\setlength{\columnseprule}{3pt}

%%% The geometry
\iftoggle{A4Exam}
{\usepackage[a3paper,landscape,twocolumn,margin=2cm]{geometry}}

%%\usepackage{PostCommands}   %%% Packages and Commands after geometry

\begin{document}
First page
\newpage
second page
\end{document}


My question is: How can I put all this in one package, and decide there wheather I'm in one case or the other? So, how can the commands, \toggletrue{A4Exam} or \togglefalse{A4Exam}, can be effective before the geometry commands, even if it's written after the package (with some command like \AtBeginDocument, what I've tried without any result)?

More precisely, I want to obtain a file like this one:

\documentclass[12pt]{exam}

\usepackage{MyExamCommands}

\toggletrue{A4Exam}
%\togglefalse{A4Exam}       %%  These commands must be effective in the beginning of the package MyExamCommands

\begin{document}
First page
\newpage
second page
\end{document}


where the package 'MyExamCommands' contains these commands:

%%\usepackage{PreCommands}    %%% Packages and Commands before geometry

\usepackage{etoolbox}
\newtoggle{A4Exam}

\setlength{\columnseprule}{3pt}

%%% The geometry
\iftoggle{A4Exam}
{\usepackage[a3paper,landscape,twocolumn,margin=2cm]{geometry}}

%%\usepackage{PostCommands}   %%% Packages and Commands after geometry


and where the commands \toggletrue{A4Exam}... has effects on geometry commands !

I'm not sure that I understand your question. But do you want to use this definition again for other documents? I make similar things that I save in MyExamCommands.sty document and then I load:

\input{../../0latextemplates/MyExamCommands.sty}


(If you put the file in the same directory, then you have:

\input{MyExamCommands.sty}

• You can highlight code in your post using back-ticks. To highlight code-blocks, either indent them by four spaces or use the {} on the gui. – Andrew Mar 3 '18 at 9:42
• If I understand well your answer, you're talking about how you make your own package ! I can do this and It's not the subject of my question. My question is how can I put all the packages \usepackage{PreCommands} \usepackage{etoolbox} \newtoggle{A4Exam} \toggletrue{A4Exam} %\togglefalse{A4Exam} \iftoggle{A4Exam} {\usepackage[total={180mm,255mm},includefoot,includehead,centering,twoside,top=10pt]{geometry}} {\usepackage[a3paper,landscape,twocolumn,margin=2cm]{geometry}} \usepackage{PostCommands}  in one package (MyExamCommands.sty) – Faouzi Bellalouna Mar 3 '18 at 9:51
• I think that I'll ad an MWE for my problem ! – Faouzi Bellalouna Mar 3 '18 at 9:53
• I've edited my question and inserted an MWE. Thanks – Faouzi Bellalouna Mar 3 '18 at 11:46
• To put al this in one document. Open your tex editor, paste al the things you named in the document and save it as balblabla.sty in the main directory of your exam.tex document. ok? Or misunderstood by me (again :) ) – Arne Timperman Mar 3 '18 at 12:37