[texhax] class file vs style file

Niall Mansfield texhax at uit.co.uk
Wed Jun 20 12:04:41 CEST 2007


Brian,

   Brian Papa wrote:
   > In developing a template for a journal article, I'm
   > wondering if there is a significant advantage to creating an
   > entirely new class file as opposed to using the existing
   > article.cls and then making any necessary modifications
   > though the .sty file? The general consensus seems to be to
   > create a new class file

 From our own experience, we'd disagree: writing your own class
file is very hard.  We've found it's much easier to use a standard
class file, and apply the changes we need via our own xxx.sty file.
Here's why:

1. Changing only the bits that need to be changed is a lot less work.

2. It's usually people who are relatively inexperienced in
    LaTeX who ask this question.  (That's not a put down,
    just objective.)  But if you're a LaTeX newbie you won't
    know what you have to include in a class file to get a
    professional result.  You'll face a lot of trial and error.

3. The standard class files have had years of debugging and are
    very robust.

4. Lots of very useful packages assume that certain actions
    are performed by certain named functions ("hooks") and change the
    behavior by re-defining these functions.  If you write your
    own class file, you won't know which names you have to
    preserve.

5. Most class files use TeX code in addition to LaTeX code.
    (We have found that) TeX code is much harder to write and
    understand, or at least requires much more effort up
    front to become proficient with.

Some facts and figures: our standard style file now uses the
following 25 packages:
	babel
	caption			
	chngpage
	color
	colortbl
	courier
	crop
	endnotes
	fancyvrb
	framed
	framed
	geometry
	graphicx
	helvet
	ifthen
	latexsym
	layout
	makeidx
	mathpazo
	nextpage
	relsize
	sidecap	
	ulem
	url
	wrapfig

Ignoring comments, our additional style file contains 300
lines.  The old class file that it replaces had 850 lines,
ignoring comments.  But these figures don't tell the full story:

* The new style file has more functionality and is more
   sophisticated.

* The old class file was very difficult to maintain, not
   least because it uses lots of TeX code.

* The new style file is much simpler: most of it uses
   standard LaTeX, and a lot of that is very simple stuff
   such as:
	\newenvironment{...}
	\newcommand{...}
   to impose a consistent style, but which we could live
   without by typing a lot more in the documents being
   typeset, plus a few lines to set options for the various
   packages used.

* The new style file lets us use all the standard packages,
   which the old class file didn't.

Whichever route you go, we've found the following invaluable:

* CTAN online catalog: http://www.ctan.org/tex-archive/help/Catalogue/alpha.html

* "The LaTeX Companion" book, published by Addison-Wesley.

We've have got nowhere without them.


	Niall Mansfield
	UIT Cambridge Ltd.


More information about the texhax mailing list