The inputenc package
Tells pdfLaTeX in which encoding the source file is saved. \usepackage[utf8]{inputenc} has been the default since 2018 and is no longer needed.
Loading the package
\usepackage[utf8]{inputenc}Since the LaTeX release of April 2018, pdfLaTeX reads source files as UTF-8 without any package. The line \usepackage[utf8]{inputenc} in older templates does no harm and matters only when the document has to compile on an installation from before 2018.
The package is still needed for a file saved in an older 8-bit encoding such as latin1 (ISO 8859-1) or cp1252 (Windows). Name that encoding in the option, or convert the file to UTF-8 and drop the package.
LuaLaTeX and XeLaTeX read UTF-8 themselves. They ignore the package with a warning.
Main commands
\usepackage[utf8]{inputenc} | Source file in UTF-8; the default since 2018. |
\usepackage[latin1]{inputenc} | Source file in ISO 8859-1. |
\inputencoding{latin1} | Changes the encoding inside the document, for example before an \input of an old file. |
\DeclareUnicodeCharacter{2264}{\ensuremath{\leq}} | Defines what a Unicode character prints, given by its hexadecimal code point. It belongs to the LaTeX kernel and works without the package. |
Complete example
\documentclass{article}
\usepackage[utf8]{inputenc} % only needed for LaTeX before 2018
\usepackage[T1]{fontenc}
\DeclareUnicodeCharacter{2264}{\ensuremath{\leq}}
\begin{document}
Umlauts and accents are typed directly: ä, ö, ü, ß, é, ñ, ç.
A character that LaTeX does not know needs a definition: 3 ≤ 5.
\end{document}Compiled with pdfLaTeX from TeX Live 2023.
Pitfalls
- A Unicode character without a definition stops with Unicode character α (U+03B1) not set up for use with LaTeX. Define it with
\DeclareUnicodeCharacteror replace it by a command. - A file saved as Latin-1 but read as UTF-8 stops at the first umlaut with
Invalid UTF-8 byte. Save the file as UTF-8 in the editor. inputenconly decides how the input is read. Whether an umlaut is a single glyph in the font, and whether the word is hyphenated, depends onfontenc.
Related pages
- How-to Umlauts and accents in LaTeX
- Error Unicode character α (U+03B1) not set up for use with LaTeX
- Package
fontenc - Package
fontspec