> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/zh-cn/lei-wen-jian/01-understanding-packages-and-class-files.md).

# 理解宏包和类文件

LaTeX 文档中的默认格式由……决定 **类** 该文档所使用的。此默认外观可以通过一种……来更改，并且可以通过一种……添加更多功能 **宏包**。类文件名具有 **.cls** 扩展名，宏包文件名具有 **.sty** 扩展名。

## 类与宏包之间的区别

有时候，在选择是编写宏包还是类时，很难做决定。基本规则是：如果你的文件包含用于控制某种特殊类型文档的逻辑结构外观的命令，那么它就是一个类。否则，如果你的文件添加的是独立于文档类型的功能，即可用于书籍、报告、文章等；那么它就是一个宏包。

例如，如果一家公司需要带有品牌标识的报告，这些报告使用一种特殊字体，并且在页脚中带有公司的标志；那么你需要一个新的类。

如果公司需要一个新的命令，使在文档中突出显示重要句子更容易，那么在这种情况下，一个新的宏包就可以。

## 延伸阅读

更多信息请参见

* [编写你自己的宏包](/latex/zh-cn/lei-wen-jian/03-writing-your-own-package.md)
* [编写你自己的类](/latex/zh-cn/lei-wen-jian/04-writing-your-own-class.md)
* [面向类和宏包编写者的 LaTeX2ε](http://www.latex-project.org/guides/clsguide.pdf)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/zh-cn/lei-wen-jian/01-understanding-packages-and-class-files.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
