Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

enter image description here

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}

\LoadClass[10pt,letterpaper]{article}

\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)}
\newcommand{\coursenumber}[1]{\renewcommand{\@coursenumber}{#1}}
\newcommand{\semester}[1]{\renewcommand{\@semester}{#1}}
\newcommand{\studentname}[1]{\renewcommand{\@studentname}{#1}}
\newcommand{\studentid}[1]{\renewcommand{\@studentid}{#1}}
\newcommand{\school}[1]{\renewcommand{\@school}{#1}}
\newcommand{\department}[1]{\renewcommand{\@department}{#1}}
\newcommand{\lecture}[1]{\renewcommand{\@lecture}{#1}}

\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
\lhead{\begin{tabular}{@{}l}\@coursenumber\ (\@semester)\\\@studentname\ (\@studentid)\end{tabular}}
\chead{}
\rhead{\begin{tabular}{r@{}}Assignment \#\@assignment\\\today\end{tabular}}
\lfoot{}
\cfoot{\thepage}
\rfoot{}
% Set the width of the header rule. Make 0pt to remove the rule.
\renewcommand{\headrulewidth}{.5pt}
\renewcommand{\footrulewidth}{0pt}
% Make the head height match the size of the header
\setlength{\headheight}{24pt}
\pagestyle{fancy}
% Remove "Chapter" from the marks
%\renewcommand{\chaptermark}[1]{%
%  \markboth{\thechapter.\ #1}{}}
share|improve this question
    
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
add comment

1 Answer

up vote 5 down vote accepted

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.

As a reference, see Is it really bad to use \makeatletter and \makeatother in a package or class file?

share|improve this answer
    
I'll look into that. I honestly had no idea what that command did; I just copied it from another source to make my header. I'm now just taking the time to learn how to make my own class proper, and trying to learn what everything does. –  agent154 Jan 24 '13 at 2:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.