> 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/15-spanish.md).

# 西班牙文

## 簡介

本文說明如何排版西班牙文文字：啟用正確排版帶重音字元，例如 ñ，並提供對語言特定功能的支援，例如斷字。

### 使用 pdfLaTeX 的西班牙文文字範例

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

```latex
\documentclass{article}

% 設定字型（輸出）編碼
\usepackage[T1]{fontenc}

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

% 西班牙文專用命令
\usepackage[spanish]{babel}
\begin{document}
\tableofcontents

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

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

\section{導言章節}
這是第一節，我們可以加入
一些額外元素，而且一切都會
正確排版。更進一步地，如果某個字
太長而必須截斷，
babel 會嘗試依照
語言正確地截斷它。

\section{含定理的章節}
這一節是用來看看指令會發生什麼情況
用來定義文字的
\end{document}
```

[在 Overleaf 中開啟這個 pdfLaTeX 範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Spanish+text+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%0A%25+Set+the+font+%28output%29+encodings%0A%5Cusepackage%5BT1%5D%7Bfontenc%7D%0A%0A%25+%5Cusepackage%5Butf8%5D%7Binputenc%7D+is+no+longer+required+%28since+2018%29%0A%0A%25+Spanish-specific+commands%0A%5Cusepackage%5Bspanish%5D%7Bbabel%7D%0A%5Cbegin%7Bdocument%7D%0A%5Ctableofcontents%0A%0A%5Cvspace%7B2cm%7D+%25Add+a+2cm+space%0A%0A%5Cbegin%7Babstract%7D%0AEste+es+un+breve+resumen+del+contenido+del+%0Adocumento+escrito+en+espa%C3%B1ol.%0A%5Cend%7Babstract%7D%0A%0A%5Csection%7BSecci%C3%B3n+introductoria%7D%0AEsta+es+la+primera+secci%C3%B3n%2C+podemos+agregar+%0Aalgunos+elementos+adicionales+y+todo+ser%C3%A1+%0Aescrito+correctamente.+M%C3%A1s+a%C3%BAn%2C+si+una+palabra+%0Aes+demasiado+larga+y+tiene+que+ser+truncada%2C+%0Ababel+tratar%C3%A1+de+truncarla+correctamente+%0Adependiendo+del+idioma.%0A%0A%5Csection%7BSecci%C3%B3n+con+teoremas%7D%0AEsta+secci%C3%B3n+es+para+ver+qu%C3%A9+pasa+con+los+comandos+%0Aque+definen+texto%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![OL2spanish1.png](/files/16602c5d8bb9e2061efc21b48a45188ee01ac037)

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

任何文字檔，例如 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)

## 語言專用套件與指令

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

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

如您在 [pdfLaTeX 範例](#spanish-text-example-using-pdflatex)中所見，西班牙文版本的「Resumen」與「Índice」取代了「Abstract」與「Contents」。

Babel 透過參數 `mexico` 以及 `mexico-com`為西班牙文提供額外的在地化支援，後者會在數學模式中以逗號取代小數點作為小數標記。這些選項可以與西班牙文支援一起傳遞給 `babel` 套件：

```latex
\usepackage[spanish, mexico]{babel}
```

某些數學指令也會針對西班牙文在地化，如下例所示，該例也示範了西班牙文引號（`<<` 以及 `>>`):

```latex
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[spanish]{babel}
\begin{document}
\section{含定理的章節}
本節是用來看看指令會發生什麼情況

\[ \lim x =  \tg {\theta} + \max \{3.52, 4.22\} \]

該套件也會對 <<這些引號標記>> 加入特殊行為，以進行文字引用，正如 RAE 規範所指示。
\end{document}
```

[在 Overleaf 中開啟這個 pdfLaTeX 範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+math+localization+for+Spanish\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5BT1%5D%7Bfontenc%7D%0A%5Cusepackage%5Bspanish%5D%7Bbabel%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csection%7BSecci%C3%B3n+con+teoremas%7D%0AEsta+secci%C3%B3n+es+para+ver+que+pasa+con+los+comandos+que+definen+texto%0A%0A%5C%5B+%5Clim+x+%3D++%5Ctg+%7B%5Ctheta%7D+%2B+%5Cmax+%5C%7B3.52%2C+4.22%5C%7D+%5C%5D%0A%0AEl+paquete+tambi%C3%A9n+agrega+un+comportamiento+especial+a+%3C%3C%C3%A9stas+m%C3%A1rcas+para+hacer+citas+textuales%3E%3E+tal+como+lo+indican+las+relgas+de+la+RAE.%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![OL2spanish2.png](/files/bd4791919356cd5b858b3cf5cf3d9bca500f274c)

在這裡，您可以看到 `\max` 以及 `\lim` 會以帶重音字元顯示。若要查看西班牙文數學符號的完整列表，請參閱 [參考指南](#reference-guide)。有關數學指令在地化額外功能的詳細資訊，可參閱 [`babel-spanish` 套件](https://ctan.org/pkg/babel-spanish?lang=en).

字元序列 `<<` 以及 `>>` 用來產生西班牙文引號，這可能會與某些套件衝突。請參閱 [`babel-spanish` 套件](https://ctan.org/pkg/babel-spanish?lang=en) 的（西班牙文）文件，以取得引號使用的進一步細節。

## 斷字

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

```latex
 \usepackage{hyphenat}
 \hyphenation{mate-máti-cas recu-perar}
```

第一個指令會匯入套件 `hyphenat` ，而第二行是一份以空格分隔、已定義斷字規則的字清單。另一方面，如果您希望某個 *字* 不要自動斷行，請在文件中使用 `{\nobreak word}` 指令。

## 參考指南

**西班牙文 LaTeX 指令在數學模式中**

| LaTeX 指令  | 輸出      |
| --------- | ------- |
| `\sen`    | sen     |
| `\tg`     | tg      |
| `\arcsen` | arc sen |
| `\arccos` | arc cos |
| `\arctg`  | arc tg  |
| `\lim`    | lím     |
| `\limsup` | lím sup |
| `\liminf` | lím inf |
| `\max`    | máx     |
| `\inf`    | ínf     |
| `\min`    | mín     |

## 延伸閱讀

更多資訊請參見

* [該主題的說明文件 `babel-spanish` 套件](https://ctan.org/pkg/babel-spanish?lang=en)
* [以 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/07-french.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/05-arabic.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/15-spanish.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.
