I'm trying to make a template where I can specify a draft version, and some text will appear in the footer noting that it's a draft, with today's date. I also define a function that allows text to be wrapped in \isdraft{stuff}, and "stuff" will only be rendered if in draft. I got that to work using the code below. My question is that I'm trying to allow for a special draft version "POS" that loads the geometry package with the argument showframe. This doesn't work, I assume because the default value of draftver is evaluated first, and when TeX goes to correct it, it's already loaded geometry.

My question: is there a way to catch the change in \draftver before \geometry is loaded without moving geometry out of the class file?

Secondary question: I might be able to get it to work by defining \draftver above the class call in my main document, but the class will break if draftver is not defined. How do I figure out if it's defined and define it if not? Thanks!

In my main file, I have the following at the top: \documentclass[12pt]{MyClass} \renewcommand{\draftver}{POS}

In the class file, I have the following:

% ========================================== SET DRAFT =========================================== %
% This section defines the logic for making a draft. We do this in two parts:
% 1. Create a "variable" called draftver (as in draft version). If the user sets it to something,
  % then the footers will contain the text "DRAFT \draftver - Last edited \today". Note that it's
  % important to call this the same thing the user can \renewcommand in the preamble, otherwise any
  % change to it won't be picked up in this class file (to make heading appear, for example).
% 2. Create a "function" checker for whether it's a draft, and then put whatever they specify it it
  % is. This "anything" is the argument to the command.
% https://tex.stackexchange.com/questions/239305, https://stackoverflow.com/questions/2144176
  % http://ctan.math.utah.edu/ctan/tex-archive/macros/generic/xstring/xstring_doc_en.pdf

\newcommand\draftver{FINAL}  % Sets the "default" value to "FINAL"

% Print whatever they feed into argument 1 if it is a draft (meaning not omitted, FINAL, or REVIEW);
  % otherwise put nothing. The code below checks first whether the draft version is FINAL (if the
  % draft line is omitted, the line above sets the version to FINAL) or REVIEW. I tried to account 
  % for changes in capitalization, but \lowercase{\draftver} and \uppercase{\draftver} were not 
  % reliable, even when I did the same casing to the word to compare. I tried a few other things,
  % but all were too unreliable, so you're forced to just type FINAL or REVIEW in all caps. Sorry.
  \IfStrEq{\draftver}{FINAL} {%
    % If yes, we return nothing where this was called
  } {%
    % If not, check whether they specified a draft version or we are in REVIEW
    \IfStrEq{\draftver}{REVIEW} {%
      % If review, we return nothing where this was called
    } {%
      % If not FINAL or REVIEW versions, then we print whatever they specified

% ========================================== DOC SETUP =========================================== %
% This section defines some basic things about the document, including margins, paper size, header
  % and footer, table of contents, etc.

% Allow user to show the boxes around margins and things to help in positioning images and tables and so forth. To do this, we check for the substring "show" in the draft name.
\IfStrEq{\draftver}{POS} {%
  % If yes, we set the geometry (margins) of the page such that it draws the boxes
  \geometry{letterpaper, left= 1.2in, right=1in, bottom=1in, showframe}
} {%
  % If not we simply set the margins
  \geometry{letterpaper, left= 1.2in, right=1in, bottom=1in}

% ==------------------------------------- Header / Footer --------------------------------------== %
% Set page number to top right. Fancy is not used currently.
  % If version is anything but FINAL (or omitted):
  \fancyfoot[c]{\textit{ DRAFT \draftver \hspace{0.4em}- last edited \today} }

% Set page number to top right. Plain is used by default.
  % If version is anything but FINAL (or omitted):
  \fancyfoot[c]{\textit{ DRAFT \draftver \hspace{0.4em}- last edited \today} }
  • Welcome to TeX.SE! Your secondary question can be addressed with \ifdefined, see for example texfaq.org/FAQ-isdef. However, you can avoid the problem by specifying the variable as a class option, see for example tex.stackexchange.com/questions/61487/…. Your primary question is a bit less clear. The class is loaded in the preamble (before \begin{document}) so you should be able to use \geometry commands. What exactly is the problem? Do you get an error, or are the settings ignored, or something else?
    – Marijn
    Oct 27, 2018 at 22:05

1 Answer 1


My guess is that the packages are loaded before \draftver is read in main. The simplest solution is to just load geometry using variables, and then add a switch for \newgeometry just under the draftver that users can comment or uncomment to see the boxes. I ended up using this.

Class file:

  left= \leftMargin,


% Uncomment this line to show boxes around margins for positioning

That way, it doesn't matter what visual changes the draft makes, and I still have one location for changing margins. While that doesn't directly answer my question, it gets the job done!

You must log in to answer this question.

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