Accented characters in LaTeX
Updated:
For accented letters to display, copy and hyphenate correctly, add input encoding, the T1 font encoding and the babel package with your document language to the preamble. Babel also translates captions such as "Figure", "Table" and "Contents".
\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{lmodern}Since 2018 LaTeX reads files as UTF-8 by default, so the inputenc line is no longer needed, but it does no harm and protects older installations. The parts that matter are T1 fontenc and babel; lmodern gives a crisp font with the full set of accented glyphs.
Putting a lab report together? In CamteX you draw formulas and tables, then send the finished document to Overleaf or download it as a PDF. Try it free
\documentclass[a4paper,12pt]{article}
\usepackage{fontspec}
\usepackage[english]{babel}With XeLaTeX and LuaLaTeX you load neither inputenc nor fontenc: fontspec handles Unicode directly and lets you use any font installed on the system. On Overleaf the compiler is chosen in the project settings.
Schr\"odinger, Fran\c{c}ois, Espa\~na, \AA ngstr\"om, Malm\"oIn a UTF-8 file you can type the letters directly. The commands are the fallback for old files or a keyboard without them: \" for an umlaut, \' for an acute, \~ for a tilde, \c for a cedilla, \AA for the Scandinavian ring.
\usepackage[french,english]{babel}
% ...
\foreignlanguage{french}{la mesure de la p\'eriode}The last language in the babel options is the main one. \foreignlanguage switches hyphenation and typographic rules for a single phrase, so a quoted French title breaks correctly at the end of a line.
\hyphenation{elec-tro-mag-net-ic}Babel loads hyphenation patterns for every language you list. When a technical term breaks badly or sticks out into the margin, give the allowed break points once in the preamble and LaTeX applies them throughout.
\usepackage{csquotes}
% ...
The setup was called \enquote{stable} in the notes.csquotes picks the right quotation marks for the current babel language: curly English quotes here, guillemets inside a French passage. Typing the straight " key gives neither.
caf\'e, d\'ej\`a vu, h\^otel, M\"uller, Espa\~na, gar\c{c}on\par
Dvo\v{r}\'ak, Erd\H{o}s, Mi\k{e}dzyzdroje, D\r{u}m, Erdo\u{g}an, T\={o}ky\={o}\par
\O rsted, \AA ngstr\"om, Stra\ss e, Wis\l{}a, \ae ther, \oe uvreMost accents are a backslash plus a sign that looks like the mark: \' acute, \` grave, \^ circumflex, \" umlaut, \~ tilde, \= macron. The rest use letters: \c cedilla, \v caron, \H Hungarian double acute, \k ogonek, \r ring, \u breve. \o, \aa, \ae, \ss and \l are letters of their own, and \k fails without T1 fontenc.
the r\^ole of the estimate $\hat{\theta}$, na\"ive versus $\ddot{x}$,
and $T_{\text{\'eb}}$ for the boiling point in a French table\^ and \" are text commands: in math LaTeX only warns that they are invalid and drops the whole accented letter. The other way round, \hat, \bar, \tilde and \ddot work only in math and stop with Missing $ inserted in text. For an accented word inside a formula, wrap it in \text so the text accent works again.
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[ngerman,english]{babel}
\hyphenation{electro-mag-net-ic}
\babelhyphenation[ngerman]{Mess-un-sicher-heit}
\begin{document}
The German summary keeps its own rules:
\begin{otherlanguage*}{ngerman}
Die Messunsicherheit der Pendell\"ange betrug zwei Millimeter.
\end{otherlanguage*}
\end{document}\hyphenation stores exceptions for the language active at that moment, in the preamble the main one, so they never reach the German paragraph. \babelhyphenation[ngerman] targets German, and without the bracket it applies to every language. otherlanguage* switches hyphenation but keeps English captions and dates, unlike otherlanguage without the star.
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\input{glyphtounicode}
\pdfgentounicode=1
\begin{document}
M\"uller measured the fjord near Troms\o{} with a fine offset.
\end{document}With T1 each accented letter is one glyph, so a search for Müller finds the name and copying gives the real letter instead of a u followed by a loose diaeresis. glyphtounicode and \pdfgentounicode add a Unicode table to the fonts, so ligatures such as fi and ff copy as two plain letters in every viewer. Test by pasting a line from your PDF.
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[unicode]{hyperref}
\hypersetup{pdftitle={Mesure de la p\'eriode}, pdfauthor={Fran\c{c}ois M\"uller}}
\begin{document}
\section{Estimating \texorpdfstring{$\hat{\theta}$}{theta} near Malm\"o}
\end{document}Bookmarks and the title in the document properties are plain Unicode text outside the page. Recent hyperref writes them as Unicode anyway; the unicode option protects older installations from broken accents there. A formula cannot go into a bookmark, so \texorpdfstring gives a text version and the Token not allowed warning disappears.
\documentclass{article}
\usepackage[T1]{fontenc}
\DeclareUnicodeCharacter{2264}{\ensuremath{\leq}}
\DeclareUnicodeCharacter{03B1}{\ensuremath{\alpha}}
\begin{document}
Pasted from a spreadsheet: tolerance ≤ 0.5 mm, angle α = 12 degrees.
\end{document}pdflatex stops with this error when a pasted character has no definition, typically the less-or-equal sign, a Greek letter typed directly, the Unicode minus or a thin space. \DeclareUnicodeCharacter with the code point from the message maps it to a LaTeX command. Retyping it as $\leq$ is cleaner; XeLaTeX and LuaLaTeX need neither when the font has the glyph.
Common mistakes and fixes
| Wrong | Right | Why |
|---|---|---|
Stra\sse | Stra\ss e | The letters after \ss become part of the command name, and there is no command \sse. |
h\hat{o}tel | h\^otel | \hat is a math accent; in running text it stops the compilation with Missing $ inserted. |
$T_{caf\'e}$ | $T_{\text{caf\'e}}$ | A text accent in math is dropped together with its letter, and only a warning in the log says so. |
\usepackage{fontspec} \usepackage[T1]{fontenc} | \usepackage{fontspec} | T1 switches XeLaTeX back to an 8-bit font, and letters outside it vanish with only a Missing character line in the log. |
\section{$\alpha$ decay} | \section{\texorpdfstring{$\alpha$}{alpha} decay} | hyperref removes the formula from the bookmark with a Token not allowed warning, so the entry reads only decay. |
- No T1 fontenc: accented letters are built from two glyphs and cannot be searched or copied from the PDF.
- Captions in the wrong language: babel is missing or set to a different language than the document.
- A file saved in a legacy encoding such as Windows-1252: compilation stops with an Invalid UTF-8 byte error. Save the file as UTF-8 in your editor.
See also
- Title page in LaTeX
- Bibliography in LaTeX
- SI units in LaTeX
- Cross-references in LaTeX
- Figure in LaTeX
- Table in LaTeX
Don't want to memorize commands?
Draw a formula or paste a screenshot, and CamteX turns it into ready LaTeX.