# Changing a boolean in a class file from the main latex file

I'm trying to change a boolean value located in a class file (.cls) from the main latex document (.tex). I've tried to set the boolean in the main latex file using \setboolean{showwatermark}{true/false}.

The class file toad.cls contains:

\ProvidesClass{toad}[2017/09/12 v 0.1 learning about variables]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
\LoadClass[]{article}
\RequirePackage{xifthen}
\usepackage[printwatermark]{xwatermark}
\newboolean{showwatermark}
\setboolean{showwatermark}{false}
\ifthenelse{\boolean{showwatermark}}{%
\newwatermark[allpages,color=black!20,angle=45,scale=3,xpos=0,ypos=0]{IN REVIEW}}{}


The latex file contains:

\documentclass[9pt]{toad}
\setboolean{showwatermark}{true}
\begin{document}
Some text...
\end{document}


I have a feeling this is horrifically wrong. Would the better approach here be to define a newcommand?

• The test in the class doesn't make sense. There is no interface to change the boolean before it is used. Or did you remove some parts of the class? – Ulrike Fischer Sep 12 '17 at 14:51
• Why does the class provide its own boolean rather than using whatever interface xwatermark provides? What is the point of the boolean? – cfr Sep 12 '17 at 14:54
• When the conditional is evaluated, the boolean is false. Later, you set the boolean to true, but no code evaluated later makes any use of that value. Hence, setting the boolean in the document is useless. Why not just pass printwatermark to the class so it is picked up by the package? printwatermark=false or printwatermark (printwatermark=true) can override whatever setting is default in the class. Provided the class processes the options, of course (which you're already doing). – cfr Sep 12 '17 at 15:04
• Off-topic: 9pt is not an option recognised by article.cls. It is equivalent to the default i.e. 10pt as it will be ignored. – cfr Sep 12 '17 at 15:05
• @coatless I'm not familiar with xwatermark so I only looked at the manual quickly but, yes, that would be the idea. The class file would just do whatever is specific to that class (e.g. define a specific watermark). It would let xwatermark handle the switching, which it already provides a user interface for. As written, the class will never produce a watermark as far as I can tell. Because the \newwatermark is never executed since the condition is always false. If you were given this class, don't use it. Whoever wrote it clearly doesn't know what they're doing and didn't test it at all. – cfr Sep 12 '17 at 19:31