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 ?

6
  • 1
    When I compile it I get the accents.
    – N.N.
    Nov 4, 2011 at 8:08
  • Same here, I seem to have no problem compiling this will accents. I'm on Lion too, TeXLive-2011.
    – qubyte
    Nov 4, 2011 at 8:13
  • 1
    Check the log file for warnings. Nov 4, 2011 at 8: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 4, 2011 at 8:34
  • 9
    Make sure that the source file is saved with the same encoding as you use for input (UTF-8 here). Nov 4, 2011 at 8:39

8 Answers 8

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}
3
  • 2
    \usepackage[utf8]{inputenc} seems to work around more universally.
    – nilon
    Oct 23, 2019 at 21:55
  • 1
    @nilon you may add it as answer. It is the most elegant one! Nov 18, 2019 at 2:02
  • @JoshuaSalazar that's tatojo's answer!
    – nilon
    Nov 19, 2019 at 23:46
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}
0
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.

0
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

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}
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.

1

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

\starttext

¡Hola! ¿Cómo estás?

\stoptext

enter image description here

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}
2
  • 5
    Why do you load article and babel with latin?
    – Werner
    Jan 16, 2019 at 19:06
  • 1
    Thank you for the observation, it was not necessary after all. Jan 17, 2019 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.