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:

\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


then your document can go

\headertitle{hello world}

and at any point later


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


or some default other than empty.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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