21

I assume this is really basic question, I'm new to LaTeX, I read a first step tutorial to get ready to write some documents but I couldn't answer my own question at this time and I really don't know where to search.

When I try to write é and compile my document, this character is not shown. I know the sequence is \'e to make it happen in the document but that is really disturbing to write.

Is there someway to write a paragraph "normally" and convert all the special chars into the LaTeX syntax? Or is there a way to allow é, à, ... writing so the compilation includes them into the document?

lockstep
  • 250,273
vdegenne
  • 822

1 Answers1

32

With the following setup, you can just type these characters normally, and the copy-paste text in the pdf (the OCR layer) will be correct, too. Your source .tex document should be encoded in UTF8, of course, or you could use latin1, or some other input encoding that includes the characters you desire and is listed in the inputenc documentation.

% !TEX encoding = UTF-8 Unicode
\documentclass{article}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\begin{document}
áéíóú àìèòù âêîôû
\end{document}

output

I think this setup should work for all languages with Latin script when using pdfLaTeX. Another option would be XeLaTeX or LuaLaTeX, which support Unicode natively.

pdfLaTeX’s UTF8 isn’t actually the full Unicode set, but here’s a more expansive collection of lower case letters that work:

áćéíĺńóŕśúýź àèìòù
âêîôû äëïöüÿ ąę ăğ
ãñõ æœ åů čěňřšž çşţ
ð đłø ďľť ı ij ŋ őű ß þ ż

output

The line

% !TEX encoding = UTF-8 Unicode

is supposed to stress the fact that your .tex file needs to be encoded in UTF8. It is automatically read and understood by a few editors, including TeXworks and TeXShop; un other editors, it doesn’t do any harm since it’s just a comment. See When and why should I use % !TEX TS-program and % !TEX encoding?.

lmodern loads the Latin Modern fonts, which look mostly the same as the standard TeX Computer Modern fonts, but has some minor advantages in my opinion, including the placement of the acute and grave accents. See Latin Modern vs cm-super? (my answer there demonstrates the accents).

Further reading

inputenc and fontenc

XeLaTeX and LuaLaTeX

doncherry
  • 54,637
  • 1
    I'm sure I read somewhere on TeX.sx that one should load fontenc before inputenc but I can't find it any more and have forgotten what the reason was... – cgnieder Feb 07 '13 at 18:54
  • 1
    Provided the file is UTF-8 encoded. I believe it's better to give some more information about input encodings. – egreg Feb 07 '13 at 18:54
  • 2
    @cgnieder I usually recommend it; it's not really necessary, but it makes inputenc immediately aware about the used output encodings. – egreg Feb 07 '13 at 18:55
  • @cgnieder Thanks for the hint, I changed it. There’s some discussion about this in the comments to best practice international template, but I think if I don’t find a dedicated question about this, I’ll ask one. – doncherry Feb 07 '13 at 19:27
  • @doncherry This is a very good answer; will you please add % !TEX encoding = UTF-8 Unicode or similar that tells an editor about the encoding? This is a problem area as many early documents have been written using ISO encodings rather than utf-8. – yannisl Feb 07 '13 at 19:39
  • @YiannisLazarides Done – even though I’m not really convinced to advertise something as best practice that only two of the really popular editors support. But since it doesn’t break anything anything otherwise, so be it. @ everybody In which order should I load inputenc and fontenc? – doncherry Feb 07 '13 at 19:58
  • @doncherry I use the menemonic input/output i.e, \inputenc, fontenc. First deals with input and latter with output. – yannisl Feb 07 '13 at 21:02
  • @YiannisLazarides But that’s just the opposite of what egreg says‽ It’d be interesting to see your reasonings in the separate question I linked to. – doncherry Feb 07 '13 at 22:05