Fonts and Text Formatting

Writing Spanish Documents in LaTeX with Babel

Set up Spanish in LaTeX with the babel package: language option, accents and inverted punctuation, Spanish captions, quotation marks, and dates.

On this page
  1. Load Spanish with babel
  2. Accents and inverted punctuation
  3. Captions, tables, and dates
  4. Quotation marks
  5. Decimal commas in text and math
  6. Spanish with XeLaTeX or LuaLaTeX
  7. Switching languages inside a document
  8. Frequently asked questions

Spanish documents in LaTeX need three things: the babel language option, correct input of accented letters, and the Spanish names for captions and dates. With those in place, LaTeX hyphenates Spanish words correctly and formats quotation marks and dates the Spanish way.

Load Spanish with babel

Add the spanish option to the babel package in the preamble:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[spanish]{babel}

\begin{document}
\section{Introducción}
Este documento está escrito en español.
\end{document}

The spanish option sets the Spanish captions, the hyphenation patterns, and several typographic rules. The T1 font encoding makes accented letters come from the font as single glyphs, so accented words hyphenate properly.

Babel also offers regional variants, such as Mexican Spanish with the mexican option. Check the babel documentation for the full list of names.

Accents and inverted punctuation

Current LaTeX reads UTF-8 by default, so you can type á, é, í, ó, ú, ñ, ü, ¿, and ¡ directly in the source file. Older guides load \usepackage[utf8]{inputenc} for this. That line is no longer needed with LaTeX releases from 2018 onward.

¿Dónde está la biblioteca? ¡Qué bien!

Save the file as UTF-8 in your editor. If the editor saves in another encoding, the accents will not compile correctly.

Captions, tables, and dates

With the spanish option, figure captions use “Figura”. Babel’s Spanish table captions use “Cuadro” by default. To use “Tabla” instead, add the es-tabla option (for other ways to rename it, see how to change the table caption name in LaTeX):

\usepackage[spanish,es-tabla]{babel}

Babel also sets \today to the Spanish form of the date, such as “22 de noviembre de 2026”.

Quotation marks

The Spanish module adds shorthands for guillemets. Typing "< produces « and "> produces ». For example:

Ella dijo "<hola">.

Shorthands can clash with code, with other packages, or with the way you type quotes. The es-noquoting option turns them off:

\usepackage[spanish,es-noquoting]{babel}

With the shorthands off, type the guillemets directly, or use \guillemotleft and \guillemotright.

Decimal commas in text and math

Spanish writes a decimal comma: “3,5 kilómetros”. Babel does not change how numbers are formatted in math. In math mode, a comma is treated as punctuation and gets extra space after it. To write a decimal comma without that space, wrap it in braces:

Son $3{,}5$ kilómetros.

Spanish with XeLaTeX or LuaLaTeX

XeLaTeX and LuaLaTeX work with the polyglossia package, which plays the role of babel for these engines:

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage{spanish}

\begin{document}
\section{Introducción}
¿Qué tal? Este documento usa polyglossia.
\end{document}

Compile the file with XeLaTeX or LuaLaTeX, not pdfLaTeX. For choosing a font with these engines, see LaTeX fonts and font families explained.

Switching languages inside a document

Most documents are in one language, but a Spanish paper often quotes English terms. Wrap a short phrase in \foreignlanguage:

Un término técnico es \foreignlanguage{english}{deadlock}.

For a longer passage, use the otherlanguage environment:

\begin{otherlanguage}{english}
This whole paragraph is in English.
\end{otherlanguage}

To switch the language for the rest of a group, use \selectlanguage{english}.

Hyphenation follows the language you switch to, so the words in the English passage hyphenate by English rules. For more on how hyphenation works, see controlling hyphenation in LaTeX.

Frequently asked questions

What does Babel mean in Spanish?

“Babel” is the same word in Spanish and English. It refers to the Tower of Babel from the Bible, and it is also used for a state of confusion or a jumble of voices. The LaTeX package takes its name from that story about many languages, which fits its job of handling several languages in one document.

What is the Spanish word for LaTeX?

LaTeX has no Spanish translation. It is a name, so Spanish-language documentation and forums use it as written: LaTeX.

The complete guide to fonts and text formatting

LaTeX Fonts and Font Families Explained
Read the guide

Keep exploring

Guides from other topics

All topics →