# Why are my variables getting erased?

I'm making a custom document class and I've noticed that after my custom variables get typeset on the title page, they somehow get reset to nothing. They show up on the title page, but then my header isn't working.

Nevermind the assignment part - that's something I just didn't change yet. It's supposed to be lecture.

Here is my code to make this simple document:

\documentclass{notes}

\coursenumber{Course 101}
\semester{Winter 2013}
\lecture{1}
\studentname{My Name}
\studentid{My ID}

\begin{document}
\maketitle

asdf
\end{document}


And here's my notes.cls file:

\ProvidesClass{notes}

\RequirePackage{ifthen}
\RequirePackage[left=1.25in,right=1.25in,top=1.25in,bottom=1.25in]{geometry}
\RequirePackage{setspace}
\RequirePackage{amsmath}
\RequirePackage{titling}
\RequirePackage{fancyhdr}
\RequirePackage{amsfonts}

\newcommand{\@coursenumber}{{\em No \textbackslash coursenumber specified}}
\newcommand{\@semester}{{\em No \textbackslash semester specified}}
\newcommand{\@studentname}{{\em \textbackslash studentname unknown}}
\newcommand{\@studentid}{{\em \textbackslash studentid unknown}}
\newcommand{\@school}{{\em \textbackslash school unknown}}
\newcommand{\@department}{{\em \textbackslash department unknown}}
\newcommand{\@lecture}{\textbackslash lecture}
\newcommand{\solutionstext}{\bfseries (Solutions)}

\renewcommand{\maketitle}{
\begin{titlepage}
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}} % Defines a new command for the horizontal lines, change thickness here
\center
\leavevmode\\[4cm] % Center everything on the page
\HRule \\[0.4cm]
{ \huge \bfseries \@coursenumber}\\[0.0cm] % Title of your document
\HRule \\[1.5cm]
\textsc{\Large \@semester}\\[0.5cm] % Semester
\textsc{\Large \today}\\[0.5cm] % Date
\textsc{\Large Lecture \#\@lecture}\\[1.0cm] % Lecture
\HRule \\[1.0cm]
\Large \emph{Author:} \\ \@studentname \\
\@studentid \\[3cm]
\vfill % Fill the rest of the page with whitespace
\end{titlepage}
}

\makeatletter
% These commands follow the titling package format for titles
% They define user commands to format the subtitle
\newcommand\presubtitle[1]{\gdef\@presubtitle{#1}}
\newcommand\postsubtitle[1]{\gdef\@postsubtitle{#1}}
% This command takes the subtitle as its argument, and uses the titling command
% \maketitlehookb plus the previously defined formatting commands to insert
% the subtitle into the titlepage. It also generates \thesubtitle for subsequent use
\newcommand\subtitle[1]{%
\renewcommand{\maketitlehookb}{\@presubtitle#1\@postsubtitle}
\newcommand\thesubtitle{#1}}
\makeatother
% Now we define the formatting for the subtitle
\presubtitle{\begin{center}\Large} % change this as needed
\postsubtitle{\end{center}}

% These commands set up the headers. They are set up for even and odd pages the same
% Check the fancyhdr documentation for information on how to set them differently
% for odd and even pages
\lfoot{}
\cfoot{\thepage}
\rfoot{}
% Set the width of the header rule. Make 0pt to remove the rule.
\renewcommand{\footrulewidth}{0pt}
\pagestyle{fancy}
% Remove "Chapter" from the marks
%\renewcommand{\chaptermark}[1]{%
%  \markboth{\thechapter.\ #1}{}}

-
Don’t use \makeatletter and \makeatother (around the subtitle stuff) in a class file, especially if you use macros with @ in it. \@coursenumber will be \@ and then just text “coursenumber”. –  Qrrbrbirlbel Jan 24 '13 at 1:59

While using \makeatletter is harmless inside a style (.sty) or class (.cls) file, \makeatother would unnecessarily change the category code of @ to other (12) (see What are category codes?), making subsequent use of @ in control sequences problematic. As such, remove (the pair \makeatletter and) \makeatother.