# Custom topmatter variable

In a simple documentclass for homework assignments, how should I go about specifying a few attributes in addition to title and author in the topmatter?

\begin{document}
\psetnum{2}
\title{Some Title}
\author{Joe Shmoe}


I would like this to render stuff like "Linear Algebra - Pset 2" in the header by evaluating \@acadclass - Pset \@psetnum. How can I declare these variables in the documentclass such that I could access them from \@acadclass?

-
May I ask which document class do you use? If it is not a standard class can you give us a link? BTW: Welcome to TeX.SX! –  Kurt Sep 8 '13 at 1:06
Thanks :) It's a work in progress based on some other hw class I found on the net. Here's a gist of the current draft. It's pretty messy though. gist.github.com/mlsteele/6487153 –  Miles Sep 8 '13 at 18:21

You can look for inspiration in the definition of \author in the LaTeX kernel:

\def\author#1{\gdef\@author{#1}}


An example with your commands:

\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{fancy}

\makeatletter
\newcommand\psetnum[1]{\def\@psetnum{#1}}
\makeatother

\psetnum{2}

\psetnum{2}
\title{Some Title}
\author{Joe Shmoe}

\begin{document}

test
\end{document}


An image of the resulting page showing the header:

To have also the header if \maketitle is used, add

\let\ps@plain\ps@fancy


inside

\makeatletter, \makeatother.

If these definitions are going to be used in a .cls file, you can do

\@ifpackageloaded{fancyhdr}{}{}{\RequirePackage{fancyhdr}}
\pagestyle{fancy}


(in particular, in a .cls file, you do not use \makeatletter, \makeatother).
@Miles if you are talking about a .cls file, that indicates that you are using \makeatletter somewhere; if that is so, delete that command from your .cls file (and any possible \makeatother). \makeatletter, \makeatother inside a .cls file are dangerous. –  Gonzalo Medina Sep 8 '13 at 2:05
Yep, I'm talking about a .cls. Is it true then that .cls files are already in a scope where @ is a letter, and that in a .tex file the scope is automatically switched so that @ is an other? –  Miles Sep 8 '13 at 2:10
@Miles yes; with the deafult settings, in a .cls (or a .sty) file @ is a letter (has catcode 11); in a .tex file @ is an other (has catcode 12). –  Gonzalo Medina Sep 8 '13 at 2:22