LaTeX How to generate a .cls file in latex?

  • Thread starter Thread starter member 428835
  • Start date Start date
  • Tags Tags
    File Latex
AI Thread Summary
To generate a .cls file in LaTeX, one must first understand that writing a class file is not recommended for novices; it is advisable to start with packages (.sty files). A LaTeX document should contain only one class, specified by the \documentclass command, while multiple packages can be included using \usepackage. If a package significantly alters the document's structure and appearance, it might be appropriate to convert it into a class. However, focusing too much on typesetting can lead to difficulties, as LaTeX is designed to prioritize content over appearance. For those ready to write a .cls file, understanding advanced commands and concepts in LaTeX is essential.
member 428835
hey pf!

i was wondering if any of you knew how to generate a .cls file in latex? in other words, what typeset do i select. for example, some i have now are LaTex, Plain Tex, XeLaTex...

i'm using TexShop

thanks!

josh
 
Physics news on Phys.org
First things first: What makes you think you need to write your own LaTeX class (suffix=.cls)? Writing a LaTeX class is not an exercise for a novice. You need to cut your teeth on writing packages (suffix=.sty) first.

A LaTeX document (suffix=.tex) should have one and only one class. This is evinced by the \documentclass[option,option,option,...]{classname} macro at the start of the .tex file. A LaTeX document can use a large number of packages. For example, \usepackage{amsmath,amssymb,amsfonts}, followed by even more usepackage directives.

If you're package completely takes over the look and feel of the document such as producing a cover page (complete with the fancy company logo), an inside cover page, a signature page, strongly distinguishes between front matter, main matter, and back matter, and redefines things like \chapter and \section, then you might want to think about turning your package into a class. On the other hand, if your package just does those fancy cover pages, it's probably best to leave it as a package.

If you are trying to take over typesetting, that's generally not a good idea. One of the main points of LaTeX is to separate what you see and what you say. LaTeX is a "What You See Is What You Mean" system rather than a "What You See Is What You Get" system. From what I've seen, the people who struggle most with LaTeX are overly concerned with how things look. Just don't worry about how things look!Finally, some suggested reading: LaTeX2ε for class and package writers.
 
When you can understand the magic of \expandafter, \unexpanded, and \noexpand is when you are ready to write a .cls file. For example,
Code:
\def\my@elet#1#2#3{%
  \expandafter\expandafter\expandafter\let
  \expandafter\expandafter\expandafter#1%
  \my@csname{#2}{#3}}

\def\expandsecondarg#1#2#3{%
  \edef\reserved@a{\noexpand#1\noexpand{#2}{#3}}\reserved@a}
 
  • Like
Likes 1 person

Similar threads

Replies
23
Views
3K
Replies
5
Views
2K
Replies
12
Views
3K
Replies
1
Views
2K
Replies
9
Views
5K
Replies
4
Views
3K
Back
Top