# Automatic provision of title making through class file

I have written a class file for my 3rd year project students (despite my lack of expertise!), and I wanted to avoid them having to use the maketitle command.

Here is a minimal example:

The class file:

%\section{Class declaration}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{test}[13/06/2012 PC]
% Base this class on KOMA script article class file
% A 5mm binding is added to margin
%
\AtBeginDocument{%
\maketitle
}


A tex test example:

\documentclass{test}
%\usepackage{color}
\usepackage{wasysym}
\usepackage{rotating}
\usepackage{framed}
\title{my title}
\begin{document}
A test
\end{document}


This works with the above, but if I uncomment the second line (\usepackage{color}) I get an error:

! Undefined control sequence.
\set@color ...\@pdfcolorstack push{\current@color
}\aftergroup \reset@color
l.10 \begin{document}


I am using the latest installation of TeXLive (installed today). Any explanation as to what is happening, and if there is a way of solving the problem?

-

use

\AtBeginDocument{%
\let\default@color\current@color
\maketitle
}


color package uses \AtBeginDocument to set this but as the package is loaded after the class it gets set too late, so just set it a bit earlier.

-
So would another option be to \RequirePackage{color} in the class file, before \maketitle is thrown in there? (Just for my continuing education.) –  Sean Allred Jun 20 '13 at 16:46
@SeanAllred yes except that would force colour in to the document and (might?) create option class errors if the document wants to use xcolor or something. –  David Carlisle Jun 20 '13 at 17:01
@DavidCarlisle Thank you for your answer. There is something that puzzles me. If the color package uses \AtBeginDocument to set some parameters, then what happens if some other packages also use the \AtBeginDocument in the same way? –  Pierre Jun 20 '13 at 20:39
@Pierre It doesn't set "some" parameters it just sets the default color \AtBeginDocument{\let\default@color\current@color} to be the color in force at that point. You made it fail by inserting a box saving command earlier in the begin document hook, which is unfortunate but in 20 years of the color package it's the first time I've seen that happen:) –  David Carlisle Jun 20 '13 at 20:44
@DavidCarlisle Thank you David. The solution you provided does indeed work. If I don't use it but I load the class "article" instead of the class "scrartcl" in my little cls file the problem does not occur. So I am not sure as why it fails in the first place. scartcl uses \normalcolor but this should not cause a problem (?). –  Pierre Jun 21 '13 at 0:32