2

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.
\newcommand{\ifdraft}[1]{
  \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
      #1
    }
  } 
}

% ========================================== 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.
\pagestyle{fancy}
\fancyhf{}
\fancyfoot{}
\IfStrEq{\draftver}{FINAL}{}{%
  % If version is anything but FINAL (or omitted):
  \fancyfoot[c]{\textit{ DRAFT \draftver \hspace{0.4em}- last edited \today} }
}
\fancyhead{}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[R]{\thepage}

% Set page number to top right. Plain is used by default.
\fancypagestyle{plain}{\fancyhf{}
\fancyfoot{}
\IfStrEq{\draftver}{FINAL}{}{%
  % If version is anything but FINAL (or omitted):
  \fancyfoot[c]{\textit{ DRAFT \draftver \hspace{0.4em}- last edited \today} }
}
\fancyhead{}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[R]{\thepage}}
1
  • 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 '18 at 22:05
2

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:

\newcommand\leftMargin{1.2in}
\newcommand\rightMargin{1.0in}
\newcommand\bottomMargin{1.0in}
\geometry{letterpaper, 
  left= \leftMargin,
  right=\rightMargin,
  bottom=\bottomMargin
}

Main.tex:

\renewcommand{\draftver}{1.0}
% Uncomment this line to show boxes around margins for positioning
%\newgeometry{left=\leftMargin,right=\rightMargin,bottom=\bottomMargin,showframe}

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!

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.