Typeset directly in Spanish

I am typesetting in emacs with AucTeX. I generally write in English and Spanish, and, therefore, use the following in my preamble:

\usepackage[english,spanish]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tipa}
\usepackage{t1enc}
\usepackage{amssymb}
\usepackage{soul}
\usepackage{graphicx}
\usepackage{colortbl}
\usepackage{times}
\usepackage{url}
\usepackage{qtree}

\begin{document}
óáéí
\end{document


I can typeset accent marks with no problems in Textmate, but I get the following error in emacs:

ERROR: Package inputenc Error: Unicode char \u8:óáéí not set up for use with LaTeX


There was a very similar question reported here, however, I have not been able to solve my problem the same way. Does anybody know how to set this up?

-
–  Javier Bezos Apr 30 '12 at 16:45

I can reproduce the error by saving that code as Latin-1.

Add the "magic line" for Emacs:

% -*- coding: utf-8 -*-
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english,spanish]{babel}
\usepackage{tipa}
\usepackage{amssymb}
\usepackage{soul}
\usepackage{graphicx}
\usepackage{colortbl}
\usepackage{times}
\usepackage{url}
\usepackage{qtree}

\begin{document}
óáéí
\end{document}


and all will be well.

Notice also that the t1enc package is obsolete and is still in the distributions for backwards compatibility.

-

It appears that emacs or some file copying program has translated your document from utf-8 to latin1. If I change

\usepackage[utf8]{inputenc}


to

\usepackage[latin1]{inputenc}


in your document it all works.

-
It works for me as well if I make the same change. Do you have any idea what would translate the document to latin1? And/or how to make it stop? –  jvcasill Apr 30 '12 at 19:01
was it the same document, or did you start with a fresh one? emacs will normally keep documents in the same encoding but for new documents it will use what it thinks is your preferred encoding which may be latin 1 rather than utf8. egreg's answer showed a way of setting the default per file or auctex may have a setting or the basic emacs setting is file-coding-system-alist which says what default encoding to use for each file extension try C-h v file-coding-system-alist –  David Carlisle Apr 30 '12 at 19:38
Strangely enough, the original code works fine for me but if I change to \usepackage[latin1]{inputenc} I get a Missing \$ inserted`error. –  Ricardo May 1 '12 at 16:56
@Ricardo this web page is served as utf8, so the characters are in utf8 as seen on the web page, but that doesn't mean that they began life in that encoding. –  David Carlisle May 1 '12 at 18:46
@DavidCarlisle, I have an awkward setup so I didn't copy paste them. Instead I retyped it. Troubleshooting an unrelated error yesterday I learned that my system is configured to UTF-8, which would explain why the code works for me, but when I change to Latin-1 it fails. –  Ricardo May 2 '12 at 18:35