# How to pass title (or other parameter) to class file

I know LaTeX just to the point of making simple documents and modifying simple characteristics of a document's layout. Now I'm creating a class for a kind of document in order not to have to copy a huge preamble in every document, and I don't know to achieve what I want to do. First of all, the class inherits from the article class, uses otf fonts so I'm compiling with XeLaTeX, and uses the fancyhdr package.

I want to specify the fancyhdr headers inside the .cls file because they're all going to have the same style, so I would like to include in the .cls file the lines:

\lhead[<even output>]{<odd output>}


What's inside, though, would have to be parameters that would be specified in the .tex file, like the document's title, or the author's name, or other stuff. How could I pass this kinds of arguments to the .cls file. If a general solution is given (in order to learn LaTeX besides being able to do what I want), I would very much appreciate it too.

Thank you very much.

EDIT:

As it can be seen in the article class file article.cls the above parameters can be called via \@author, \@title and so on. The below answer by Christian answers what I asked in the comments, and shows how to create different parameters in the class file that could be defined from the .tex file.

• Did you look into article.cls as a starter? – user31729 Jun 14 '15 at 8:31
• @ChristianHupfer Well, I feel very embarrased to say I didn't. I saw it uses \@author and so on. Is that general? How could I define in the class a "parameter" (I don't know how to call it) so I could access it from the cls via that method? Because the article class doesn't define author and title (I guess they're standard TeX parameters). – MyUserIsThis Jun 14 '15 at 8:39
• @ChristianHupfer Should I add those questions to the original question? – MyUserIsThis Jun 14 '15 at 8:40
• I'll try to provide a solution, give me some minutes ;-) – user31729 Jun 14 '15 at 8:41
• the \@author etc commands are defined using \author etc. They are no class options – user31729 Jun 14 '15 at 9:08

The class

\ProvidesClass{mysuperclass}

\RequirePackage{xkeyval}%

\def\docauthorname{A. U. Thor}%
\def\docname{\jobname.tex}%
\def\docdate{\today}%

\define@key{mysuperclass.cls}{docdate}[\today]{%
\def\docdate{#1}%
}

\define@key{mysuperclass.cls}{author}[A. U. Thor]{%
\def\docauthorname{#1}%
}
\define@key{mysuperclass.cls}{docname}[]{%
\def\docname{#1}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\ExecuteOptionsX{author,docdate}
\ProcessOptionsX%

\RequirePackage{fancyhdr}

\AtBeginDocument{%
\pagestyle{fancy}%
}
\endinput


The class driver file:

\documentclass[docdate=1/1/2016,author=Me,docname=yelostfile]{mysuperclass}

\usepackage{blindtext}
\begin{document}
\blindtext[15]
\end{document}

• I will add the second question to the original post to make it coherent with this answer. Thank you again. – MyUserIsThis Jun 14 '15 at 8:53
• @MyUserIsThis: Please wait, there is an error! – user31729 Jun 14 '15 at 8:53
• No problem. I will not use it right away. Thank you again for the help. – MyUserIsThis Jun 14 '15 at 8:55
• @MyUserIsThis: Well, I corrected the solution – user31729 Jun 14 '15 at 9:07