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>
%<*readme>
demopkg --- readme text and license (truncated for this example)
%</readme>
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
\expandafter\begingroup
\fi
%</internal>
%<*install>
\input docstrip.tex
\keepsilent
\askforoverwritefalse
\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{
\file{README.txt}{\from{\jobname.dtx}{readme}}
}
\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{macro}{\LoadClass}
% \begin{macrocode}
\LoadClass{article}
% \end{macrocode}
%\end{macro}
%
% \begin{macrocode}
%</class>
% \end{macrocode}
%\Finale
\usepackage{jobname}, which will not work, and complain thatdemoclass.styis not found. – Jan Hlavacek Oct 05 '11 at 03:35\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\ProvidesClassline 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..\fimissing or use%<class>\ProvidesClassinstead. In Joseph's original it is the same for a package but this might not cause this much trouble. – Martin Scharrer Oct 05 '11 at 08:26democlass.clsat the prompt fordemoclass.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\fileversionand\filedate. I suspect this has to do with\GetFileInfo{\jobname.cls}. Is there some other value that I can use for\GetFileInfoso that the file version and date are displayed correctly in my documentation? – Brian Oct 05 '11 at 11:24\defat 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 06 '11 at 02:21