##  Class files

LaTeX supports many worldwide languages by means of some special packages. In this article is explained how to import and use those packages to create documents in Spanish.

##  Introduction

Spanish language has some special characters, such as the ñ and some accentuated words. For this reason the preamble of your document must be modified accordingly to support these characters and some other features.

\documentclass{article}
\usepackage[utf8]{inputenc}
\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}

There are two packages in this document related to the encoding and the special characters. These packages will be explained in the next sections.

##  Input encoding

Modern computer systems allow you to input letters of national alphabets directly from the keyboard. In order to handle a variety of input encodings used for different groups of languages and/or on different computer platforms LaTeX employs the inputenc package to set up input encoding. In this case the package properly displays characters in the Spanish alphabet. To use this package add the next line to the preamble of your document:

\usepackage[utf8]{inputenc}

The recommended input encoding is utf-8. You can use other encodings depending on your operating system.

##  Font encoding

To proper LaTeX document generation you must also choose a font encoding which has to support specific characters for Spanish language, this is accomplished by the fontenc package:

\usepackage[T1]{fontenc}

Even though the default encoding works well in Spanish, using this specific encoding will avoid glitches with some specific characters. The default LaTeX encoding is OT1.

##  Language-specific packages and commands

To extended the default LaTeX capabilities, for proper hyphenation and translating the names of the document elements, import the babel package for the Spanish language.

\usepackage[spanish]{babel}

As you may see in the example at the introduction, instead of "abstract" and "Contents" the Spanish words "Resumen" and "Índice" are used. An extra parameter can be passed when importing the babel package with spanish support:

\usepackage[spanish, mexico]{babel}

This will set a localization for the language. By now only mexico and mexico-com are available, the latter will use a comma instead of a dot as the decimal marker in mathematical mode.

Mathematical commands can also be imported specifically for the Spanish language.

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

$\lim x = \sen{\theta} + \max \{3.52, 4.22\}$

El paquete también agrega un comportamiento especial
a <<estas marcas para hacer citas textuales>> tal como
lo indican las reglas de la RAE.

You can see that \sen, \max and \lim are properly displayed. For a complete list of mathematical symbols in Spanish see the reference guide. For this commands to be available you must add the next line to the preamble of your document:

\def\spanishoperators{}

Notice also that  <<  and  >>  have a special format in Spanish, this can conflict with some packages. If you don't need these or you want to use the direct keyboard input « » set the parameter es-noquotes, comma separated inside the brackets of the babel statement.

##  Hyphenation

Sometimes for formatting reasons some words have to be broken up in syllables separated by a - (hyphen) to continue the word in a new line. For example, matemáticas could become mate-máticas. The package babel, whose usage was described in the previous section, usually does a good job breaking up the words correctly, but if this is not the case you can use a couple of commands in your preamble.

 \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