> 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-tw/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-tw/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
套件 inputenc 錯誤：Unicode 字元 \\u8:��� 尚未設置供 LaTeX 使用。
```

較現代的 TeX 引擎，例如 XeLaTeX 或 LuaLaTeX，可以原生支援這類 Unicode 字元。

### XeLaTeX 或 LuaLaTeX 的支援

如果你使用這些較現代的 LaTeX 引擎之一，就可以直接使用更多 UTF-8。你可以 [在 Overleaf 上選擇引擎](/latex/zh-tw/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 數學斜體小寫 alpha）](https://www.fileformat.info/info/unicode/char/1d6fc/index.htm)，請改寫為 `$\alpha$`. [Detexify](http://detexify.kirelabs.org/classify.html) 是尋找與指定符號對應之 LaTeX 指令的實用工具。

至於 emoji，你可以使用 `\symbol` 指令搭配 `fontspec`，XeLaTeX，以及合適的字型。例如：

```latex
落葉：{\fontspec{Symbola}\symbol{"1F343}}
```

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

如果你想使用彩色 emoji，可以看看 [emoji](http://texdoc.net/pkg/emoji) 套件。你需要 [將你專案的編譯器](/latex/zh-tw/zhi-shi-ku/026-changing-compiler.md) 改為 LuaLaTeX。接著你就可以載入 `emoji` 套件，並撰寫 `\emoji{leaves}`.

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

關於在 LaTeX 中使用 emoji 的更多資訊，可參見文章 [在 Overleaf 的 LaTeX 文件中插入 emoji](/latex/zh-tw/wen-yu-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-tw/shen-ru-wen-zhang/05-an-introduction-to-endlinechar-how-tex-reads-lines-from-text-files.md) 關於 TeX 處理器如何處理換行結尾。

## 相關說明文章

* [我該如何使用帶重音符號的字母（例如法文或葡萄牙文）？](/latex/zh-tw/wen-yu-da/37-how-do-i-use-letters-with-accents-e.g.-in-french-or-portuguese.md)
* [在 Overleaf 上使用 polyglossia 和 fontspec 進行多語言排版](/latex/zh-tw/yu-yan/01-multilingual-typesetting-on-overleaf-using-polyglossia-and-fontspec.md)
* [\endlinechar 入門：TeX 如何從文字檔讀取各行](/latex/zh-tw/shen-ru-wen-zhang/05-an-introduction-to-endlinechar-how-tex-reads-lines-from-text-files.md)
* [在 Overleaf 的 LaTeX 文件中插入 emoji](/latex/zh-tw/wen-yu-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-tw/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.
