> For the complete documentation index, see [llms.txt](https://ayakaleaf-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://ayakaleaf-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 编码。UTF-8 是当今网络上使用最广泛的字符编码。你可以用它表示任何 Unicode 字符，其中包括种类极其丰富的字母、数字和符号，包括希腊字母和带重音符号的字母。

UTF-8 取代了许多较旧的编码，如 latin1、latin9，这些编码经常出现在 LaTeX 文件和模板中。TeX 和 LaTeX 比 UTF-8 早了几十年，因此 LaTeX 对 UTF-8 的支持有些不一致，这取决于你使用的 [TeX 引擎](/latex/zh-cn/shen-du-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
inputenc 宏包错误：Unicode 字符 \u8:��� 尚未设置为可与 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 数学符号。

最好的变通方法是将非 BMP 字符替换为等效的 LaTeX 命令，例如，不要键入或粘贴 [𝛼 (U+1D6FC MATHEMATICAL ITALIC SMALL 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 中使用表情符号的更多信息可参见文章 [在 Overleaf 上的 LaTeX 文档中插入表情符号](/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-du-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-du-wen-zhang/05-an-introduction-to-endlinechar-how-tex-reads-lines-from-text-files.md)
* [在 Overleaf 上的 LaTeX 文档中插入表情符号](/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://ayakaleaf-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.
