> 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/zhi-shi-ku/151-what-file-encodings-and-line-endings-should-i-use.md).

# 我应该使用什么文件编码和行尾格式？

## 编码

Overleaf 使用 [UTF-8](https://en.wikipedia.org/wiki/UTF-8) 所有文本文件所使用的编码。UTF-8 是当今网络上使用最广泛的字符编码。你可以用它来表示任何 Unicode 字符，其中包括种类极其丰富的字母、数字和符号，包括希腊字母以及带重音的字母。

UTF-8 取代了许多旧编码，例如 latin1、latin9，这些编码经常出现在 LaTeX 文件和模板中。TeX 和 LaTeX 早于 UTF-8 几十年，因此 LaTeX 对 UTF-8 的支持有些不一致，并且取决于你 [TeX 引擎](/latex/zh-cn/shen-ru-wen-zhang/55-what-s-in-a-name-a-guide-to-the-many-flavours-of-tex.md) 正在使用的。

### LaTeX 和 pdfLaTeX 支持

如果你使用的是 pdfLaTeX（即使用 pdfTeX 引擎运行 LaTeX），这是 Overleaf 的默认设置，那么如果你在文档导言区中包含以下 \usepackage 命令，你就可以直接排版大多数字母重音字符和某些符号：

```latex
\usepackage[utf8]{inputenc}
```

这应该是导言区中唯一的一行 inputenc，因此它应当替换所有使用其他编码的行。

不过，TeX 并不知道如何排版所有 UTF-8 字符。如果它不知道如何排版你的字符，你可能会看到类似这样的错误：

```latex
Package inputenc Error: Unicode char \u8:��� not set up for use with LaTeX.
```

更现代的 TeX 引擎，例如 XeLaTeX 或 LuaLaTeX，可以原生支持这类 Unicode 字符。

### XeLaTeX 或 LuaLaTeX 支持

如果你使用的是这些更现代的 LaTeX 引擎之一，你可以直接使用更多的 UTF-8。你可以 [在 Overleaf 上选择引擎](/latex/zh-cn/geng-duo-zhu-ti/08-choosing-a-latex-compiler.md) 方法是点击项目文件列表面板上方的 Overleaf 菜单图标。

### 无效/不受支持的字符

出于技术原因，Overleaf 不能存储包含 [NUL 字符](https://en.wikipedia.org/wiki/Null_character) 或包含来自 Unicode [基本多文种平面](https://en.wikipedia.org/wiki/Plane_\(Unicode\))（BMP）之外的字符的文件。BMP 只包含前 65,536 个 Unicode 码位。一些 Unicode 数学符号以及一些东亚语言中的符号位于 BMP 之外。当从 PDF 复制到网页时，有时会出现非 BMP 数学符号。

最好的解决方法是用等效的 LaTeX 命令替换非 BMP 字符，例如，不要输入或粘贴 [𝛼（U+1D6FC 数学斜体小写 alpha）](https://www.fileformat.info/info/unicode/char/1d6fc/index.htm)，而应改写为 `$\alpha$`. [Detexify](http://detexify.kirelabs.org/classify.html) 是一个有用的工具，可用于查找与给定符号对应的 LaTeX 命令。

对于表情符号，你可以将 `\symbol` 命令与 `fontspec`、XeLaTeX 以及合适的字体配合使用。例如：

```latex
飘落的叶子：{\fontspec{Symbola}\symbol{"1F343}}
```

![Emoji-symbola-falling-leaves.png](/files/44cf0159ce509f0ed9badf8219359d5d81654a05)

如果你想使用彩色表情符号，可以看看 [emoji](http://texdoc.net/pkg/emoji) 包。你需要 [将项目的编译器更改](/latex/zh-cn/zhi-shi-ku/026-changing-compiler.md) 为 LuaLaTeX。然后你可以加载 `emoji` 包，并写入 `\emoji{leaves}`.

![Colour-emojis.png](/files/e56b9f9fdf2d814cf1351bc0169aa710c8d1e27f)

关于在 LaTeX 中使用 emoji 的更多信息，可参见文章 [在 Overleaf 文档中插入 emoji](/latex/zh-cn/wen-da/75-inserting-emojis-in-latex-documents-on-overleaf.md).

## 行尾

Overleaf 使用 Unix 风格的换行符 \n（LF），而不是 Microsoft Windows 风格的行尾 \r\n（CRLF）。

如果你使用 [git 接口](https://www.overleaf.com/blog/195) 在 Overleaf 上编辑项目，那么你可以使用你系统本地的行尾，并通过以下方式让 git 为你将它们转换为 Unix 行尾： [启用 git 的 autocrlf 设置](https://help.github.com/articles/dealing-with-line-endings).

你也可能会对以下内容感兴趣 [本文](/latex/zh-cn/shen-ru-wen-zhang/05-an-introduction-to-endlinechar-how-tex-reads-lines-from-text-files.md) 关于 TeX 处理器如何处理行尾。

## 相关帮助文章

* [我该如何使用带重音的字母（例如在法语或葡萄牙语中）？](/latex/zh-cn/wen-da/37-how-do-i-use-letters-with-accents-e.g.-in-french-or-portuguese.md)
* [在 Overleaf 上使用 polyglossia 和 fontspec 进行多语言排版](/latex/zh-cn/yu-yan/01-multilingual-typesetting-on-overleaf-using-polyglossia-and-fontspec.md)
* [《\endlinechar 简介：TeX 如何从文本文件读取行》](/latex/zh-cn/shen-ru-wen-zhang/05-an-introduction-to-endlinechar-how-tex-reads-lines-from-text-files.md)
* [在 Overleaf 文档中插入 emoji](/latex/zh-cn/wen-da/75-inserting-emojis-in-latex-documents-on-overleaf.md)


---

# 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/zhi-shi-ku/151-what-file-encodings-and-line-endings-should-i-use.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.
