[LaTeX|翻译]What are .cls and .sty files? How are they different?

什么是.cls.sty文件?它们的区别是什么?

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

通常来讲,.cls.sty文件是用于增强LaTeX功能的附带文件。它们分别通过\documentclass{...}\usepackage{...}命令进行加载。我们通常称.cls文件为“类文件”,.sty文件为“样式文件”(或者“包文件”)。

In general, .cls and .sty files are supplementary files that increases 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’, of often just ‘packages’.

它们(.cls.sty)都可以包含在任意的TEXLATEX代码中,但是它们使用两种不同的方法。加载类文件强制使用\documentclass命令,在一个LATEX文档中只加载一个类文件,通常这个命令出现在文档的开始。另一方面,包含包文件是一个可选的选项,可以根据用户的需求加载任意数量的包文件(在文档本身开始之前加载包文件)。

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).
在理想的样例中,一个类文件定义了整个文档的结构。article类就是一个很好的例子,这个类定义了排版的文章需要的命令,包括\section, \tableofcontents\authorand等等。
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, \authorand so on.

包文件,或者也叫做样式文件,是用来提供任何类文件不能提供的命令的。主要分为两大类:一是对类文件的修正,或者为类文件添加附加功能。例如:graphicx包提供了在文档中添加图片和对文档中各种元素应用各种图形效果的方法。这种包文件将会与任意的类文件搭配生效。

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.

另一类型的包文件,例如sectsty包,提供了一些方法用于自定义化LATEX类中的section样式。例如,假如使用memoir类,然后再使用sectsty包,就会重写memoir中的section样式,这可能会导致文档样式的冲突。

On the other hand, the sectsty package provides methods to customise 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 over writing memoir’s method of creating section headers, and calamity will ensue.

总结来讲,.cls.sty文件是LATEX用来提供或者改进文档功能的文件。通常来讲,类文件提供文档的结构,包文件用于提供适用于任意类的通用功能,或者用于“样式化”特定类中提供的方法。

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.

原文:What are.clsand.styfiles? How are they different?

你可能感兴趣的:(翻译,Latex)