tags:

views:

35

answers:

1

I have some initialization code in a XeLaTeX file which I would like to put into a separate file so that I can reuse it in future texts. What is the fastest way to convert my XeLaTeX code to a LaTeX class file?

+1  A: 

You can put your preamble code into a .cls file and then use \documentclass{mydocstyle} to load it. Your .cls file will look like this:

% Declare that this document class file requires at least LaTeX version 2e.
\NeedsTeXFormat{LaTeX2e}

% Provide the name of your document class, the date it was last updated, and a comment about what it's used for
\ProvidesClass{mydocstyle}[2010/09/13 Bluetulip's custom LaTeX document style]

% We'll pass any document class options along to the underlying class
\DeclareOption*{%
  \PassOptionsToClass{\CurrentOption}{article}% or book or whatever
}

% Now we'll execute any options passed in
\ProcessOptions\relax

% Instead of defining each and every little detail required to create a new document class,
% you can base your class on an existing document class.
\LoadClass{article}% or book or whatever you class is closest to

% Now paste your code from the preamble here.
% Replace \usepackage with \RequirePackage. (The syntax for both commands is the same.)

% Finally, we'll use \endinput to indicate that LaTeX can stop reading this file. LaTeX will ignore anything after this line.
\endinput

Note that document class files can get much more complicated (if you want to include options like \documentclass[option]{mydocstyle}, etc.), but this basic format should get you started.

Save your file as mydocstyle.cls and put it in the current directory with your .tex file.

You can also take a look at the LaTeX2e for class and package writers guide. It'll walk you through this in more detail.

godbyk
Thanks for your pointer, it was enough to get me started. In this context, mentioning the command \LoadClass[options]{article} would have also been helpful.
Bluetulip
Whoops! I meant to and forgot. I've added that into my answer so it's more helpful to others. I've also added some code to handle options passed to the document class.
godbyk