LaTeX: .cls vs .sty files (by Robertson)

What are .cls and .sty files? How are they different? 

Will Robertson July 15, 2005

In general, .cls and .sty files are supplementary files that increase the functionality of LATEX. They are the files loaded with the \documentclass{...} and \usepackage{...} commands, respectively. We generally call .cls files ‘classes’, and .sty files ‘style files’, or often just ‘packages’.

They both may contain arbitrary TEX and LATEX code, but they are used in separate ways. Loading a class via \documentclass is mandatory, and may only appear once in a LATEX document; usually, it is the very first command. On the other hand, packages are optional and as many of them may be loaded as one could wish (prior to the beginning of the document itself).

In the ideal case, a class file will completely define the structure of the document. The familiar article class is a good example: it provides commands for typesetting articles, such as \section, \tableofcontents, \author and so on.

Packages, or style files, are then used to provide anything else that the class doesn’t accommodate. These fall into two broad categories: amendments to the class file, or additional functionality. For example, the graphicx package provides methods to include images and apply all manner of graphical effects to elements in a document. This package will work with essentially any class file.

On the other hand, the sectsty package provides methods to customize the section headers in the default LATEX classes (article, report, or book). So, trying to use it with the memoir class, say, will result in it overwriting memoir’s method of creating section headers, and calamity will ensue.

To summarise, .cls and .sty files are loaded by LATEX to provide and improve methods that are used to create documents. Generally speaking, class files implement the specific structure of the document, whereas packages are used to provide either generic functionality to any document, or to ‘style’ the methods provided by a specific class. 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值