Change header from class file depending on whether or not a variable is declared in the document

I am trying to edit my class file to either have a header or not depending on whether or not a variable (\cv{}) is set in the document. I have scoured the internet for answers and based my initial code on an similar working example, but nothing has worked. The only thing that seems to make a difference is whether or not I define the variable within the class file; changing it in the document itself has no affect. I've also tried to use explicit \ifthenelse statements instead of \@ifundefined, but I can't get it to find equality (I am sure this is a string/int issue, but I'm not familiar enough with latex to solve it). My MWE has a class file:

\ProvidesClass{resume}[2010/07/10 v0.9 Resume class]

\LoadClass[11pt,letterpaper]{article} % Font size and paper type

\usepackage{ifthen}
\usepackage{fancyhdr}

%\def \@cv {} %uncommenting this is the only thing that changes the outcome, regardless of what is in the main document
\def \cv#1{\def\@cv{#1}}

\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt} %clear the default lines; the footer one has 0 width automatically, but the header one doesn't
\renewcommand{\footrulewidth}{0pt}

\@ifundefined{@cv}{


and document:

\documentclass{resume-mwe} % Use the custom resume.cls style

\usepackage[left=0.75in,top=0.6in,right=0.75in,bottom=0.6in]{geometry} % Document margins

%\cv{true}

\begin{document}

there is text in here

\end{document}


You are testing

\@ifundefined{@cv}


while loading the class file at a point that you know it is not defined unless (as you note in comments) you have defined it.

You want to test after the user has had a chance to define this in the preamble so

\AtBeginDocument{
\@ifundefined...

}

• Thanks, @David. I'd wondered early on if the variable wasn't being defined, but I'm novice enough at generating class files for tex that I couldn't get anything to work. \AtBeginDocument did the trick for my MWE, but it failed as soon as I put it into a larger document (which is multiple pages and should ultimately have a header of {\fancyhead{\ifthenelse{\value{page}=1}{}{\makebox[\textwidth][c]{\textcolor{black!75}{\textsc{header text}}}}} and footer of \@ifundefined{@cv}{}{\fancyfoot{\makebox[\textwidth][c]{\textcolor{black!75}{Page \thepage\ of \pageref{LastPage}}}}). Thoughts? – Jessica Apr 12 '19 at 2:22
• It looks like if I use \AtBeginDocument {} but rearrange the \ifthenelse part within it to be \@ifundefined{@cv}{}{\fancyhead{\ifthenelse{\value{page}>1}{\makebox[\textwidth][c]{\textcolor{black!75}{\textsc{header text}}}} (so use page>1 instead of page=1 as my condition and switch the true/false values) it works. Can somebody please explain why this is the case? What's happening automatically that I'm not aware of? Thanks! – Jessica Apr 12 '19 at 2:53
• @Jessica perhaps your class file has set it to 0, hard to guess, stick [\the\value{page}] into your heading to debug what value it has (it's anyway not really related to the question in the title so feel free to ask a new question if needed) – David Carlisle Apr 12 '19 at 7:21
• Thanks - I checked the page number and it was correct. I was able to get it to work with the page=1 condition, so I'm guessing I may have had some {} out of place I didn't catch. Sorry for the slightly off topic comment, but wanted to follow up on my previous one. – Jessica Apr 12 '19 at 13:32