26

I'm trying to add spanish accents to my document ( my Thesis )

\documentclass[11pt, spanish]{report}
\usepackage[spanish]{babel}
\selectlanguage{spanish}
\usepackage[utf8]{inputenc}
\begin{document}

    Hola! Cómo estás ?

\end{document}

This piece of code doesn't seem to work on my Mac ( OS X Lion ), And I get:

Hola! Cmo ests?

in the pdf output.

Any ideas ?

Mr.Gando
  • 725
  • 1
    When I compile it I get the accents. – N.N. Nov 04 '11 at 08:08
  • Same here, I seem to have no problem compiling this will accents. I'm on Lion too, TeXLive-2011. – qubyte Nov 04 '11 at 08:13
  • 1
    Check the log file for warnings. – Thorsten Donig Nov 04 '11 at 08:30
  • No problem with your code with MikTeX. Look at you .log file and may be will find some clue there. By the way, if you include spanish as option for documentclass, you don't need to include in babel. And if you just use one language, don't need \selectlanguage command. – Ignasi Nov 04 '11 at 08:34
  • 9
    Make sure that the source file is saved with the same encoding as you use for input (UTF-8 here). – Thorsten Donig Nov 04 '11 at 08:39
  • I had the same problem as the OP. When I simply added \usepackage[utf8]{inputenc} solved it for me, which TexShop's "Encoding" preference didn't. – Sridhar Sarnobat Nov 18 '16 at 05:44

8 Answers8

16

You could choose another way of input encoding by the selinput package from the oberdiek bundle. It chooses the right encoding by some glyphs from your language correspondingly to the encoding of the source file.

\documentclass[11pt,spanish]{article}
\usepackage[T1]{fontenc}
\usepackage{selinput}
\SelectInputMappings{%
  aacute={á},
  ntilde={ñ},
  Euro={€}
}
\usepackage{babel}

\begin{document}
  Hola! Cómo estás ?
\end{document}
15

Gando, I just compile this code with pdflatex in an iMac (Mountain Lion OS X):

\documentclass[11pt, spanish]{report}
\usepackage[spanish]{babel}
\selectlanguage{spanish}
\usepackage[utf8]{inputenc}
\begin{document}

¡Hola! ¿Cómo estás?

\end{document}

and got this output:

¡Hola!

But you can get the same result with:

\documentclass[11pt]{report}
\usepackage[spanish]{babel}
\usepackage[utf8]{inputenc}
\begin{document}

¡Hola! ¿Cómo estás?

\end{document}
tatojo
  • 1,331
  • 11
  • 26
5

You can also use escape codes for any accent you want to make. In general, it might be easier to fix the encoding once than have to escape every accented character, but for the occasional foreign name I use the table here http://en.wikibooks.org/wiki/LaTeX/Special_Characters.

Specifically, I would write:

!`Hola!, ?`c\'{o}mo est\'{a}s?

Do note, that with the letter i a dotless version needs to be used, as otherwise in addition to the accent, the regular i dot would be rendered.

S\'{\i}.

Note, to get the initial question mark and exclamation point, you type a backtick character immediately after.

irh
  • 201
3

Try this:

\documentclass[11pt, spanish]{report}

\usepackage[spanish]{babel}

\usepackage[latin1]{inputenc}

\begin{document}

    Hola! Cómo estás ?

\end{document}

It should work with the additional package

egreg
  • 1,121,712
2

If possible, I would \usepackage{fontspec} rather than the legacy 8-bit fonts from the ’90s that you get with \usepackage[T1]{fontenc}, much less the 7-bit fonts from the 1980s that you get by default. This allows you to use any of your system fonts, or any OpenType or TrueType font, in Unicode.

For your input encoding, I would save any new files as UTF-8. This has been the default encoding of LaTeX since 2018.

Compile with either XeLaTeX or LuaLateX. (I personally like to use \usepackage{microtype} with LuaLateX.)

So:

\documentclass[11pt, spanish]{report}
\usepackage{fontspec}
\usepackage[spanish]{babel}

\defaultfontfeatures{ Scale = MatchUppercase, Ligatures = TeX }
% Set your fonts of choice here with either `\setmainfont`,
% `\babelfont`, or an OTF font package.

\begin{document}

¡Hola! ¿Cómo estás?

\end{document}
Davislor
  • 44,045
1

For avoid that problem try this:

\documentclass[11pt]{report}
\usepackage[spanish]{babel}    
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\begin{document}

    ¡Hola! ¿Cómo estás?

\end{document}

If this doesn't compile right then perhaps the problem are not in the packages or the codification.

Aradnix
  • 3,735
  • 2
  • 20
  • 43
1

If you use ConTeXt MKIV, such things work out-of-the-box.

\starttext

¡Hola! ¿Cómo estás?

\stoptext

enter image description here

Henri Menke
  • 109,596
0

1 - apt install tex-lang-european

2 - Same @Thorsten Donig answer with little change

\documentclass[latin]{article}
\usepackage[T1]{fontenc}
\usepackage{selinput}
\SelectInputMappings{%
  aacute={á},
  ntilde={ñ},
  Euro={€}
}
\usepackage{babel}

\begin{document}
  Hola! Cómo estás ?
\end{document}