I guess there are two possible ways to add the header automatically and use user definable values. The first and easier way is to force the user to provide the information before typesetting the header, i.e. use \schoolname{My School} in the preamble:
\documentclass{myclass}
\schoolname{My School}% OK
\begin{document}
%\schoolname{My School}% ERR
Document content
\end{document}
This can be done by redefine \schoolname to caus en error when it is used after \begin{document}:
\ProvidesClass{myclass}
% base class
\LoadClassWithOptions{article}
% define the value macros
\newcommand{\@schoolname}{}
\newcommand{\schoolname}[1]{\gdef\@schoolname{#1}}
% ... etc ...
% provide the error message
\newcommand{\mycls@headerror}{%
\ClassError{myclass}{Must be in preamble}{...}%
}
% define the hook
\AtBeginDocument{%
{\centering\bfseries\sffamily
\@schoolname
\par}
\vspace{\baselineskip}
\hrule
\vspace{\baselineskip}
\let\schoolname\mycls@headerror
}
Prerequisites: none
Steps to create a new command:
Define the macro to store the value \@<name>, e.g.
\newcommand{\@schoolname}{}
Define the macro to set the value \<name>, e.g.
\newcommand{\schoolname}[1]{\gdef\@schoolname{#1}}
Add the value (via \@<name>) to your header, e.g.
{\centering\bfseries\sffamily
\@schoolname
\par}
Redirect the setting macro (\<name>) to cause an error, after the header is typeset
\let\schoolname\mycls@headerror
The second way is to give the values as class options. I used kvoptions to realize class options with values. The use must define the values via class options:
\documentclass[%
schoolname={My School}
]{myclass}
\begin{document}
Document content
\end{document}
And thats how you can process it:
\ProvidesClass{myclass}
% load package and set it up
\RequirePackage{kvoptions}
\SetupKeyvalOptions{
family=MC,% MC = my class
prefix=my@% prefix to macros holding the values
}
% define the keys
\DeclareStringOption{schoolname}
% ... etc. ...
% Process the options
\ProcessKeyvalOptions*
% base class
\LoadClass{article}
% define the hook
\AtBeginDocument{%
{\centering\bfseries\sffamily
\my@schoolname% acces values by \<prefix>@<keyname>
\par}
\vspace{\baselineskip}
\hrule
\vspace{\baselineskip}
}
Prerequisites:
Load kvoptions
Define the <family> for the options an a <prefix> that is used for the value storing macros, e.g.
\SetupKeyvalOptions{
family=MC,
prefix=my@
}
The names doesn’t matter but it is common to name the family in two or three upper case letters and to use an @ at the end of the prefix.
Steps to create a new command:
Declare the option <name> (type: string), e.g.
\DeclareStringOption{schoolname}
Process all options with \ProcessOptionsX
Use the values with \<prefix><name>, e.g.
{\centering\bfseries\sffamily
\my@schoolname
\par}
For more information about kvoptions see it’s documentation …
myclass. A.clsfile actually. Since this is a class file. I would like to know a way on how will i change the automated printing of school name, the college name, dept name to the pdf file by my code i had posted. What I think could be possible solution was make these things into command. So creating a command from\AtbeginDocumentis I dont know. Could you guide me with this? – Kayla Feb 12 '13 at 16:24\schoolname(see my edit) … if it doesn’t work please add a MWE, showing the new problems, to your questions. Without its hard to answer. | The space before “My School” is the page margin, so you may want to change them with the geometry package … – Tobi Feb 13 '13 at 12:57and these are the commands i added to my .cls \newcommand{@schoolname}{} \newcommand{\schoolname}[1]{\gdef@schoolname{#1}} \newcommand{@colname}{} \newcommand{\colname}[1]{\gdef@colname{#1}} \newcommand{@deptname}{} \newcommand{\deptname}[1]{\gdef@deptname{#1}}
when i compiled it, deptname and colname does not appear on the pdf file.
– Kayla Feb 13 '13 at 13:11.clsfile (or parts of it!) and a better description of the error. Pleas edit your qeustion, since code in the comment section is not really readable. – Tobi Feb 13 '13 at 13:13\AtBeginDocumentpart too ;-) – Tobi Feb 13 '13 at 13:27