# Define variable in a class

I am trying to figure out how to use a variable in a class.

From another question (Macro for Declaring Variables in Class Files) I got started. However, I find myself in need of using four lines or rather unclear code. This is what I have:

\let\@headertitle\relax
\printheadertitle{} % This will print the string in the variable


It works, but doesn't look good. I simply want to use \headertitle{string} in my document, and be able to somehow call it (e.g. \headertitle{} within my class. Can I simplify this?

The first and fourth lines are not doing anything very useful, so you can simplify by removing them, then:

If your class or package code has

\def\headertitle#1{\def\@headertitle{#1}}


\headertitle{hello world}


and at any point later

\printheadertitle


will produce hello world

This will mean that you get an error if \printheadertitle is used without defining a title. If you want a default title to be silently accepted add in your class code

\headertitle{}


or some default other than empty.