> 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/yu-yan/07-french.md).

# 法文

## 簡介

本文說明如何排版法語文字：啟用帶重音字元的正確排版，例如 â、ê、î、ô、û 等，並提供對語言特定功能的支援，例如斷字。如果你正在尋找如何在單一文件中使用多種語言的說明，例如英文與法文，請參見 [國際語言支援](/latex/zh-tw/yu-yan/03-international-language-support.md) 文章。

## 使用 pdfLaTeX 的法文範例

我們先從以下 pdfLaTeX 範例開始，你可以透過程式碼下方的連結在 Overleaf 中開啟它。

```latex
\documentclass{article}
% \usepackage[utf8]{inputenc} 已不再需要（自 2018 起）

%設定字型（輸出）編碼
%--------------------------------------
\usepackage[T1]{fontenc} %LuaLaTeX 或 XeLaTeX 不需要

%法文專用指令
%--------------------------------------
\usepackage[french]{babel}
\usepackage[autolanguage]{numprint} % 用於 \nombre 指令

%斷字規則
%--------------------------------------
\usepackage{hyphenat}
\hyphenation{mate-mática recu-perar}
%--------------------------------------

\begin{document}
\tableofcontents

\vspace{2cm} %新增 2 公分間距

\begin{abstract}
這是以法語撰寫的文件內容的簡短摘要。
\end{abstract}

\section{導言章節}
這是第一節，我們加入一些額外的元素，所有內容都將正確拼寫。此外，如果一個字過長而需要截斷，babel 會嘗試根據語言正確截斷。

\section{定理章節}
本節是要看看使用定義文字的指令會發生什麼情況。

\begin{itemize}
\item 第一項
\item 第二項
\end{itemize}

\[ \lim x =  \theta + \nombre{152383.52} \]
\end{document}
```

[在 Overleaf 中開啟這個 pdfLaTeX 範例。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Sample+document+in+French\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+%5Cusepackage%5Butf8%5D%7Binputenc%7D+is+no+longer+required+%28since+2018%29%0A%0A%25Set+the+font+%28output%29+encoding%0A%25--------------------------------------%0A%5Cusepackage%5BT1%5D%7Bfontenc%7D+%25Not+needed+by+LuaLaTeX+or+XeLaTeX%0A%0A%25French-specific+commands%0A%25--------------------------------------%0A%5Cusepackage%5Bfrench%5D%7Bbabel%7D%0A%5Cusepackage%5Bautolanguage%5D%7Bnumprint%7D+%25+for+the+%5Cnombre+command%0A%0A%25Hyphenation+rules%0A%25--------------------------------------%0A%5Cusepackage%7Bhyphenat%7D%0A%5Chyphenation%7Bmate-m%C3%A1tica+recu-perar%7D%0A%25--------------------------------------%0A%0A%5Cbegin%7Bdocument%7D%0A%5Ctableofcontents%0A%0A%5Cvspace%7B2cm%7D+%25Add+a+2cm+space%0A%0A%5Cbegin%7Babstract%7D%0ACeci+est+un+bref+r%C3%A9sum%C3%A9+du+contenu+du+document+%C3%A9crit+en+fran%C3%A7ais.%0A%5Cend%7Babstract%7D%0A%0A%5Csection%7BSection+d%27introduction%7D%0AIl+s%27agit+de+la+premi%C3%A8re+section%2C+nous+ajoutons+des+%C3%A9l%C3%A9ments+suppl%C3%A9mentaires+et+tout+sera+correctement+orthographi%C3%A9s.+En+outre%2C+si+un+mot+est+trop+long+et+doit+%C3%AAtre+tronqu%C3%A9%2C+babel+va+essayer+de+tronquer+correctement+en+fonction+de+la+langue.%0A%0A%5Csection%7BSection+th%C3%A9or%C3%A8mes%7D%0ACette+section+est+de+voir+ce+qui+se+passe+avec+les+commandes+de+texte+qui+d%C3%A9finissent.%0A%0A%5Cbegin%7Bitemize%7D%0A%5Citem+premier+%C3%A9l%C3%A9ment%0A%5Citem+deuxi%C3%A8me+%C3%A9l%C3%A9ment%0A%5Cend%7Bitemize%7D%0A%0A%5C%5B+%5Clim+x+%3D++%5Ctheta+%2B+%5Cnombre%7B152383.52%7D+%5C%5D%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![OL2french1.png](/files/afb13c570256096f0ac84cb014a57cd785caf275)

### 文字檔：整數與字元

任何文字檔，例如 LaTeX 輸入 `.tex` 檔，都不過是由數值（整數）組成的串流，這些數值被用作一種機制來 *表示* 文字的字元；因此，處理文字檔涉及掃描（讀取／處理）一連串整數值。然而，會出現一個重要問題： *哪一組字元* 實際上是由特定文字檔中所包含的整數值所表示？換句話說，這些整數值是如何被 *編碼*的：從文字檔中的整數到其應該對應的字元之間，正確（預期）的「對映」（編碼）是什麼？ *表示*?

文字檔可在無數的運算環境中產生：跨越不同國家／洲，使用各式各樣的裝置、作業系統與編輯工具。文字檔的產生者可能會依照本地需求，例如語言，在產生與儲存用來表示文字檔中各個字元的整數值序列時，使用或套用不同的文字編碼。如果產生出來的文字檔一直停留在使用相同編碼的相容技術生態系中，這或許運作良好，但當這些檔案被轉移到完全不同的環境時會發生什麼事——畢竟許多文字檔並不包含任何資訊來指出其產生時所使用的編碼。

很明顯地，文字資料的產生者（來源者）與消費者（使用者）必須以某種方式就所使用的編碼（對映）達成一致，否則 *編碼錯誤* 很可能會因檔案中的整數資料與其被假定表示的字元集合不一致而產生。除了將文字檔中的整數值正確對映到字元之外，之後要視覺顯示這些字元，還需要某種形式的字型，能夠提供資料（形狀，甚至點陣圖）來輸出所需字元的視覺表示。

### 輸入編碼：inputenc、UTF-8 與 2018 年 LaTeX 的變更

歷史上，曾使用多種 8 位元編碼來產生／處理文字檔，包括 LaTeX 輸入。長話短說，LaTeX 的開發者建立了 `inputenc` 套件以解決編碼問題——讓以各種編碼建立的文字檔能在不同的 LaTeX 安裝之間傳輸。

然而，隨著時間推移，使用者／軟體開發者從多種 8 位元編碼轉向使用 Unicode 及其 UTF-8 編碼方案，後者成為文字檔編碼的事實標準。2018 年以前，為了處理以 UTF-8 編碼的檔案，LaTeX 文件前言會包含這一行

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

讀者或許會注意到，上面的範例並未包含這一行 `\usepackage[utf8]{inputenc}` 於文件前言中：為什麼呢？這是因為 LaTeX 在 2018 年引入了一項重要變更：將 UTF-8 切換為預設的 *輸入* 編碼。以 pdfLaTeX 排版且使用 UTF-8 編碼文字的文件，包括在 Overleaf 上建立並排版的文件，已不再 *需要* 納入 `\usepackage[utf8]{inputenc}` 但它 [這樣做也沒有壞處](https://www.latex-project.org/news/2018/04/10/issue28-of-latex2e-news-released/)。欲進一步了解，請參閱 [LaTeX News 2018 年 4 月號](https://www.latex-project.org/news/2018/04/10/issue28-of-latex2e-news-released/) 以及 Overleaf 部落格文章 [*TeX Live 升級——2019 年 9 月*](https://www.overleaf.com/blog/tex-live-upgrade-september-2019)。Overleaf 上建立的所有文字檔都使用 UTF-8 編碼。

### 輸出編碼：fontenc 套件

為了正確排版輸入檔中的字元，這些字元需要對映到文件排版所使用字型中的適當 *輸出形狀* （字形）。這種「輸出編碼」由另一個稱為 `fontenc`.

的套件處理 `fontenc` 若要使用 [T1 編碼](http://mirrors.ctan.org/macros/latex/base/encguide.pdf)，請在文件前言中加入下列這一行，使用例如

```latex
\usepackage[T1]{fontenc}
```

使用 `T1` 字型編碼，透過 `\usepackage[T1]{fontenc}`，還有其他優點：

* LaTeX 預設的 OT1 字型（「輸出」）編碼是 7 位元，這表示它只能編碼 128 個字元，且不包含（也不支援）字型中真正帶重音字元的形狀（字形）。 `OT1` 編碼會使 TeX 引擎透過排版（組合）基底字元與一個疊加且位移過的重音字元，來「假造」帶重音字元。
* 如果 TeX 引擎必須退而求其次採用 *構造* 帶重音字元，這會影響從 PDF 複製／貼上文字：複製含有構造式帶重音字元的文字，結果會貼上 *兩個獨立字元* ：基底字元與重音字元。使用 `T1` 編碼可避免這點。
* 使用 `T1` 編碼以存取真正的帶重音字元，能改善斷字。

### LaTeX T1 字型編碼

下圖列出了 `T1` 字型編碼。這張圖重製自文件第 22 頁 *LaTeX 字型編碼* ，其 [可於 CTAN 取得](http://mirrors.ctan.org/macros/latex/base/encguide.pdf).

![](/files/32ac4093a985476c44fb0a464aca86adcff8de94)

### 複製與貼上範例

以下這個不使用 `fontenc`的最小範例，展示了含有重音字元文字在複製／貼上時的問題。

```latex
\documentclass{article}
\begin{document}
定理章節（OT1 編碼）

{
\fontencoding{T1}\selectfont 定理章節（T1 編碼）
}
\end{document}
```

[在 Overleaf 中開啟此範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Demonstrating+copy+and+paste+with+font+encodings\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0ASection+th%C3%A9or%C3%A8mes+%28OT1+encoding%29%0A%0A%7B%0A%5Cfontencoding%7BT1%7D%5Cselectfont+Section+th%C3%A9or%C3%A8mes+%28T1+encoding%29%0A%7D%0A%5Cend%7Bdocument%7D)

第一段文字是使用 LaTeX 的預設 `OT1` 編碼排版，因此產生「假」的重音字元。以下這段 LaTeX 程式碼：

```latex
\fontencoding{T1}\selectfont
```

會切換為使用 `T1` 編碼，這會讓 LaTeX 排版出帶重音的字元字形。如果你從上方範例產生的 PDF 中複製文字，應該會看到類似這樣的結果：

定理章節（OT1 編碼） 定理章節（T1 編碼）

請觀察 `OT1` 編碼後的文字並不包含真正的重音字元，而使用 `T1` 編碼的文字則包含它們。複製／貼上的結果也可能取決於你用來檢視 PDF 的應用程式；你正是從該 PDF 中複製／貼上含有重音字元的文字。

## 語言專用套件與指令

若要擴充 LaTeX 的預設功能，提供正確的斷字以及文件元素名稱的翻譯，請匯入 `babel` 套件並使用 `法文` 語言選項。

```latex
\usepackage[french]{babel}
```

如你在 [pdfLaTeX 範例](#french-example-using-pdflatex)，不是使用「Abstract」和「Contents」，而是使用法文版本「Résumé」和「Table des matières」。

請注意，導言區也會載入 `numprint` 套件

```latex
\usepackage[autolanguage]{numprint}
```

它會變更寫在該指令大括號內的數字格式 `\nombre{}` 來完成的。

## 斷字

該 `babel` 套件通常能很好地提供語言專用的斷字功能，但如果某個特定字無法正確斷字，還有其他套件可協助。例如，您可以在前言中加入 `hyphenat` 套件：

```latex
 \usepackage{hyphenat}
 \hyphenation{mathéma-tiques récu-pérer}
```

第二行是一串以空格分隔、已定義斷字規則的單字清單。如果你想避免某個特定 *字*，請寫上 `{\nobreak word}` 於文件中，或將其包含在 `\mbox{word}`.

## 延伸閱讀

更多資訊請參見

* [以 XƎLaTeX 支援現代字型](/latex/zh-tw/zi-xing/03-xelatex.md)
* [引文與引號的排版](/latex/zh-tw/yu-yan/04-typesetting-quotations.md)
* [國際語言支援](/latex/zh-tw/yu-yan/03-international-language-support.md)
* [中文](/latex/zh-tw/yu-yan/06-chinese.md)
* [阿拉伯文](/latex/zh-tw/yu-yan/05-arabic.md)
* [德文](/latex/zh-tw/yu-yan/08-german.md)
* [希臘文](/latex/zh-tw/yu-yan/09-greek.md)
* [義大利文](/latex/zh-tw/yu-yan/10-italian.md)
* [日文](/latex/zh-tw/yu-yan/11-japanese.md)
* [韓文](/latex/zh-tw/yu-yan/12-korean.md)
* [葡萄牙文](/latex/zh-tw/yu-yan/13-portuguese.md)
* [俄文](/latex/zh-tw/yu-yan/14-russian.md)
* [西班牙文](/latex/zh-tw/yu-yan/15-spanish.md)
* [LaTeX2ε 的不算太短的入門介紹](http://www.ctan.org/tex-archive/info/lshort/)
* [WikiBooks 上的 LaTeX/國際化](http://en.wikibooks.org/wiki/LaTeX/Internationalization)
* [WikiBooks 上的 LaTeX/特殊字元](http://en.wikibooks.org/wiki/LaTeX/Special_Characters)


---

# 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/yu-yan/07-french.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.
