# Is it possible to extract a .cls from a .dtx and avoid the Two \LoadClass commands error?

I have tried to adapt Joseph Wright's model dtx file for a class that I'm writing based on the article class (a reduced working example is below, which I have named democlass.dtx). But when I run pdflatex democlass.dtx I get the error ! LaTeX Error: Two \LoadClass commands. Clearly, there is only one \LoadClass statement, so it must be getting loaded a second time somewhere.

So, is it possible to extract a .cls file from a .dtx file when the .cls file is based on the article class? I've searched high and low for a solution, and I'm stumped.

% \iffalse meta-comment
% !TEX program  = pdfLaTeX
%<*internal>
\iffalse
%</internal>
demopkg --- readme text and license (truncated for this example)
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
\expandafter\begingroup
\fi
%</internal>
%<*install>
\input docstrip.tex
\keepsilent
\preamble
demopkg --- readme text and license (truncated for this example)

\endpreamble
\postamble

Copyright, maintenance, and included files (truncated for this example)

\endpostamble
\usedir{tex/latex/demopkg}
\generate{
\file{\jobname.cls}{\from{\jobname.dtx}{class}}
}
%</install>
%<install>\endbatchfile
%<*internal>
\usedir{source/latex/demopkg}
\generate{
\file{\jobname.ins}{\from{\jobname.dtx}{install}}
}
\nopreamble\nopostamble
\usedir{doc/latex/demopkg}
\generate{
}
\ifx\fmtname\nameofplainTeX
\expandafter\endbatchfile
\else
\expandafter\endgroup
\fi
%</internal>
%<*class>
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{demopkg}[2009/10/06 v1.0 description text]
%</class>
%<*driver>
\documentclass{ltxdoc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{\jobname}
\usepackage[numbered]{hypdoc}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
%\GetFileInfo{\jobname.cls}
%
%\title{^^A
%  \textsf{demopkg} --- description text\thanks{^^A
%    This file describes version \fileversion, last revised \filedate.^^A
%  }^^A
%}
%\author{^^A
%  You\thanks{E-mail: you@your.domain}^^A
%}
%\date{Released \filedate}
%
%\maketitle
%
%\changes{v1.0}{2009/10/06}{First public release}
%
%\DescribeMacro{\examplemacro}
% Some text about an example macro called \cs{examplemacro}, which
% might have an optional argument \oarg{arg1} and mandatory one
% \marg{arg2}.
%
%\StopEventually{^^A
%  \PrintChanges
%  \PrintIndex
%}
%
%    \begin{macrocode}
%<*class>
%    \end{macrocode}
%
%    \begin{macrocode}
%    \end{macrocode}
%\end{macro}
%
%    \begin{macrocode}
%</class>
%    \end{macrocode}
%\Finale

-
There seems to be some problem with your example. You are trying to generate a class file, but you are trying include it with \usepackage{jobname}, which will not work, and complain that democlass.sty is not found. –  Jan Hlavacek Oct 5 '11 at 3:35
After disabling the \usepackage{\jobname} which should only be included for packages, not classes, your example compiles fine for me. I don't get any error. However, I guess the cause of trouble is the \ProvidesClass line before the \documentclass. It should be there, at least not in this form, because it is taken as part of the driver document. There are some \iffalse .. \fi missing or use %<class>\ProvidesClass instead. In Joseph's original it is the same for a package but this might not cause this much trouble. –  Martin Scharrer Oct 5 '11 at 8:26
Thank you -- this helps a great deal. I had typed in democlass.cls at the prompt for democlass.sty; I'm guessing that is what caused the second \LoadClass. However, now that I have deleted \usepackage{\jobname} from the dtx, my pdf documentation displays ? for the \fileversion and \filedate. I suspect this has to do with \GetFileInfo{\jobname.cls}. Is there some other value that I can use for \GetFileInfo so that the file version and date are displayed correctly in my documentation? –  Brian Oct 5 '11 at 11:24
Never mind -- I figured out that I can use a \def at the top of my .dtx file and fill in the values that way. Martin, can you submit your response as an answer so I can accept it? –  Brian Oct 6 '11 at 2:21
@lockstep: Done –  Martin Scharrer Nov 6 '11 at 0:27
After disabling the \usepackage{\jobname} which should only be included for packages, not classes, your example compiles fine for me. I don't get any error. However, I guess the cause of trouble is the \ProvidesClass line before the \documentclass. It should be there, at least not in this form, because it is taken as part of the driver document. There are some \iffalse .. \fi missing or use %<class>\ProvidesClass instead. In Joseph's original it is the same for a package but this might not cause this much trouble.