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

# 法语

## 引言

本文介绍如何排版法语文本：使带重音字符（如 â、ê、î、ô、û 等）能够正确排版，并提供对语言特定功能（如断字）的支持。如果您想了解如何在同一文档中使用一种以上的语言，例如英语和法语，请参见 [国际语言支持](/latex/zh-cn/yu-yan/03-international-language-support.md) 文章。

## 使用 pdfLaTeX 的法语示例

我们先从下面这个 pdfLaTeX 示例开始，你可以通过代码下方的链接在 Overleaf 中打开它。

```latex
\documentclass{article}
% \usepackage[utf8]{inputenc} is no longer required (since 2018)

%设置字体（输出）编码
%--------------------------------------
\usepackage[T1]{fontenc} %LuaLaTeX 或 XeLaTeX 不需要

%French-specific commands
%--------------------------------------
\usepackage[french]{babel}
\usepackage[autolanguage]{numprint} % for the \nombre command

%断字规则
%--------------------------------------
\usepackage{hyphenat}
\hyphenation{mate-mática recu-perar}
%--------------------------------------

\begin{document}
\tableofcontents

\vspace{2cm} %添加 2cm 空白

\begin{abstract}
这是一篇用法语撰写的文档内容的简短摘要。
\end{abstract}

\section{Section d'introduction}
这是第一节，我们添加一些额外的元素，一切都会被正确拼写。此外，如果一个单词太长而需要截断，babel 会尝试根据语言正确地截断。

\section{Section théorèmes}
本节用于查看使用定义文本命令时会发生什么。

\begin{itemize}
\item premier élément
\item deuxième élément
\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/8643d3c96bead04d12bfb498aecaf25420033a0e)

### 文本文件：整数和字符

任何文本文件，例如 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}` 在文档导言区：为什么会这样？这是由于 2018 年 LaTeX 引入的一项重要变化：将 UTF-8 作为默认 *输入* 编码。使用 pdfLaTeX 排版并采用 UTF-8 编码文本的文档，包括在 Overleaf 上创建和排版的文档，不再 *需要* 需要包含 `\usepackage[utf8]{inputenc}` 但 [这样做也无妨](https://www.latex-project.org/news/2018/04/10/issue28-of-latex2e-news-released/)。更多信息请参见 [2018 年 4 月的 LaTeX News 期](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 宏包

为了正确排版输入文件中的字符，这些字符需要被映射到相应的 *输出字形* （glyphs）中，这些字形包含在用于排版文档的字体里。这种“输出编码”由另一个名为 `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/ae2a0f637da90dbdbe806876941dbb701d996043)

### 复制和粘贴示例

下面这个最小示例没有使用 `fontenc`，展示了包含重音字符的文本在复制/粘贴时的问题。

```latex
\documentclass{article}
\begin{document}
定理部分（OT1 编码）

{
\fontencoding{T1}\selectfont Section théorèmes (T1 encoding)
}
\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 并从中复制/粘贴带重音字符文本的应用程序。

## 特定语言的宏包和命令

为了扩展 LaTeX 的默认功能，提供正确的断字以及文档元素名称的翻译，请导入 `babel` 宏包，并使用 `french` 语言选项。

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

正如你在 [pdfLaTeX 示例](#french-example-using-pdflatex)，French 版本“Résumé”和“Table des matières”被用来代替“Abstract”和“Contents”。

请注意，导言区还加载了 `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-cn/zi-ti/03-xelatex.md)
* [引号和引号符号的排版](/latex/zh-cn/yu-yan/04-typesetting-quotations.md)
* [国际语言支持](/latex/zh-cn/yu-yan/03-international-language-support.md)
* [中文](/latex/zh-cn/yu-yan/06-chinese.md)
* [阿拉伯语](/latex/zh-cn/yu-yan/05-arabic.md)
* [德语](/latex/zh-cn/yu-yan/08-german.md)
* [希腊语](/latex/zh-cn/yu-yan/09-greek.md)
* [意大利语](/latex/zh-cn/yu-yan/10-italian.md)
* [日语](/latex/zh-cn/yu-yan/11-japanese.md)
* [韩语](/latex/zh-cn/yu-yan/12-korean.md)
* [葡萄牙语](/latex/zh-cn/yu-yan/13-portuguese.md)
* [俄语](/latex/zh-cn/yu-yan/14-russian.md)
* [西班牙语](/latex/zh-cn/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://ayakaleaf-pro.ayaka.space/latex/zh-cn/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.
