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

# Spanish

## Introduction

This article explains how to typeset Spanish text: enabling correct typesetting of accented characters, such as ñ, and providing support for language-specific features such as hyphenation.

### Spanish text example using pdfLaTeX

We’ll start with the following pdfLaTeX example which you can open in Overleaf using the link below the code.

```latex
\documentclass{article}

% Set the font (output) encodings
\usepackage[T1]{fontenc}

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

% Spanish-specific commands
\usepackage[spanish]{babel}
\begin{document}
\tableofcontents

\vspace{2cm} %Add a 2cm space

\begin{abstract}
Este es un breve resumen del contenido del
documento escrito en español.
\end{abstract}

\section{Sección introductoria}
Esta es la primera sección, podemos agregar
algunos elementos adicionales y todo será
escrito correctamente. Más aún, si una palabra
es demasiado larga y tiene que ser truncada,
babel tratará de truncarla correctamente
dependiendo del idioma.

\section{Sección con teoremas}
Esta sección es para ver qué pasa con los comandos
que definen texto
\end{document}
```

[Open this pdfLaTeX example in Overleaf](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)

This example produces the following output:

![OL2spanish1.png](/files/CtThG7XCqDHX529DVSSy)

### Text files: integers and characters

Any text file, such as a LaTeX input `.tex` file, is nothing more than a stream of numeric (integer) values which are being used as a mechanism to *represent* characters of text; consequently, processing a text file involves scanning (reading/processing) a series of integer values. However, an important question arises: *which set of characters* is actually represented by the integer values contained in a particular text file? In other words, how have those integer values been *encoded*: what is the correct (intended) "mapping" (encoding) from integers in the text file to the corresponding characters they are supposed to *represent*?

Text files can be generated within innumerable computing environments: across different countries/continents, using a multitude of different devices, operating systems and editing tools. Originators of text files could, potentially, use or apply different text encodings according to local requirements, such as language, when generating and storing the sequence of integer values chosen to represent the individual characters contained in a text file. This may work well if the generated text files stayed within compatible technical ecosystems, which use the same encoding, but what would happen when those files are transferred to completely different environments—because many text files do not contain any information which indicates the encoding used to generate them.

Clearly, the producer (originator) and consumer (user) of textual data must, somehow, agree on the encoding (mapping) being used, otherwise *encoding errors* are likely to arise due to mismatches between the integer data in the file and the set of characters it is assumed to represent. In addition to correctly mapping text file integer values to characters, any subsequent visual display of those characters requires some form of font that is capable of providing the data (shapes, or even bitmaps) to output a visual representation of the desired characters.

### Input encoding: inputenc, UTF-8 and a change to LaTeX in 2018

Historically, a variety of 8-bit encodings were used to generate/process text files, including LaTeX inputs. To cut short a very long story, the developers of LaTeX created the `inputenc` package to address encoding issues—allowing text files, created using various encodings, to be transferred between disparate LaTeX installations.

However, over time, users/software developers moved away from multiple 8-bit encodings to using Unicode and its UTF-8 encoding scheme, which became the de facto option for encoding text files. Prior to 2018, to process UTF-8 encoded files LaTeX document preambles included the line

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

Readers might observe that the example above does not include the line `\usepackage[utf8]{inputenc}` in the document preamble: why is that? This is due to an important change to LaTeX introduced in 2018: a switch to UTF-8 as the default *input* encoding. Documents typeset with pdfLaTeX, and using UTF-8 encoded text, including those created and typeset on Overleaf, no longer *need* to include `\usepackage[utf8]{inputenc}` but is [does no harm to do so](https://www.latex-project.org/news/2018/04/10/issue28-of-latex2e-news-released/). For further information see the [April 2018 issue of LaTeX News](https://www.latex-project.org/news/2018/04/10/issue28-of-latex2e-news-released/) and the Overleaf blog post [*TeX Live upgrade—September 2019*](https://www.overleaf.com/blog/tex-live-upgrade-september-2019). All text files created on Overleaf are encoded using UTF-8.

### Output encoding: the fontenc package

To correctly typeset characters contained within input files, those characters need to be mapped to the appropriate *output shapes* (glyphs) contained in fonts used to typeset the document. This “output encoding” is handled by another package called `fontenc`.

To use `fontenc` include the following line in your document preamble, using an encoding, such as the [T1 encoding](http://mirrors.ctan.org/macros/latex/base/encguide.pdf), which supports accented characters contained in Latin-based languages:

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

Using the `T1` font encoding, via `\usepackage[T1]{fontenc}`, has other benefits:

* The default OT1 LaTeX font (“output”) encoding is 7-bit, meaning it can only encode 128 characters and does not include (enable) access to genuine accented character shapes (glyphs) contained in fonts. The `OT1` encoding causes TeX engines to “fake” accented characters by typesetting (combining) a base character with an overlaid, and shifted, accent character.
* If the TeX engine has to resort to *construction* of accented characters, this has implications for copy/paste of text from PDFs: copying text containing constructed accented characters will result in *two separate characters* being pasted: the base character and the accent character. Using the `T1` encoding avoids this.
* Using the `T1` encoding, to access genuine accented characters, improves hyphenation.

### LaTeX T1 font encoding

The following chart lists the `T1` font encoding. It is reproduced from page 22 of the document *LaTeX font encodings* which is [available on CTAN](http://mirrors.ctan.org/macros/latex/base/encguide.pdf).

![](/files/sK9HVhSps8YV8wxbFlRZ)

## Language-specific packages and commands

To extend the default capabilities of LaTeX, providing proper hyphenation and translation of the names of document elements, import the `babel` package using the `spanish` language option.

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

As you may see in the [example using pdfLaTeX](#spanish-text-example-using-pdflatex), instead of “Abstract” and “Contents” the Spanish versions “Resumen” and “Índice” are used.

Babel provides additional localization support for Spanish via the parameters `mexico` and `mexico-com`, the latter will use a comma instead of a dot as the decimal marker in mathematical mode. These options can be passed to the `babel` package along with Spanish support:

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

Some mathematical commands are also localized for Spanish, as shown in the following example which also demonstrates Spanish quotation marks (`<<` and `>>`):

```latex
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[spanish]{babel}
\begin{document}
\section{Sección con teoremas}
Esta sección es para ver que pasa con los comandos que definen texto

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

El paquete también agrega un comportamiento especial a <<éstas márcas para hacer citas textuales>> tal como lo indican las relgas de la RAE.
\end{document}
```

[Open this pdfLaTeX example in Overleaf](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)

This example produces the following output:

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

Here, you can see that `\max` and `\lim` are displayed using accented characters. For a complete list of mathematical symbols in Spanish see the [reference guide](#reference-guide). Details of additional features for localization of math commands can be found in the (Spanish) documentation for the [`babel-spanish` package](https://ctan.org/pkg/babel-spanish?lang=en).

The character sequences `<<` and `>>` are used to produce Spanish quotation marks, which can conflict with some packages. See the (Spanish) documentation of the [`babel-spanish` package](https://ctan.org/pkg/babel-spanish?lang=en) for further details on use of quotation marks.

## Hyphenation

The `babel` package usually does a good job of providing language-specific hyphenation capabilities, but if a particular word does not hyphenate correctly there are packages to assist. For example, you can add the `hyphenat` package in your preamble:

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

The first command will import the package `hyphenat` and the second line is a list of space-separated words with defined hyphenation rules. On the other side, if you want a *word* not to be broken automatically, use the `{\nobreak word}` command within your document.

## Reference guide

**Spanish LaTeX commands in mathematical mode**

| LaTeX command | Output  |
| ------------- | ------- |
| `\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     |

## Further reading

For more information see

* [Documentation for the `babel-spanish` package](https://ctan.org/pkg/babel-spanish?lang=en)
* [Supporting modern fonts with XƎLaTeX](/latex/fonts/03-xelatex.md)
* [Typesetting quotations and quotation marks](/latex/languages/04-typesetting-quotations.md)
* [International language support](/latex/languages/03-international-language-support.md)
* [Chinese](/latex/languages/06-chinese.md)
* [French](/latex/languages/07-french.md)
* [German](/latex/languages/08-german.md)
* [Greek](/latex/languages/09-greek.md)
* [Italian](/latex/languages/10-italian.md)
* [Japanese](/latex/languages/11-japanese.md)
* [Korean](/latex/languages/12-korean.md)
* [Portuguese](/latex/languages/13-portuguese.md)
* [Russian](/latex/languages/14-russian.md)
* [Arabic](/latex/languages/05-arabic.md)
* [The not so short introduction to LaTeX2ε](http://www.ctan.org/tex-archive/info/lshort/)
* [LaTeX/Internationalization on WikiBooks](http://en.wikibooks.org/wiki/LaTeX/Internationalization)
* [LaTeX/Special\_Characters on WikiBooks](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/languages/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.
