2

This question already has an answer here:

I have a Spanish character not working in 'listings' package.

In the code example below, the first occurrence of the word 'ignorará' works. The second generates the error:

! Package inputenc Error: Unicode char \u8:├\expandafter not set up for use with LaTeX.

I believe it is because I'm in the lstlisting block. How do I fix this?

\documentclass[paper=8in:10in,pagesize=pdftex,
               headinclude=on,footinclude=on,12pt]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[spanish,english]{babel}
\usepackage{listings}

\lstset{ language=Python }

\lstloadlanguages{ Python }

\begin{document}

y el compilador lo ignorará.

\begin{lstlisting}[language=python]
# Esto es un comentario, comienza con el signo #
# y el compilador lo ignorará.

print("Esto no es un comentario, el ordenador")
print("ejecutará esto y lo imprimirá.")
\end{lstlisting}

\end{document}

marked as duplicate by Jesse, ChrisS, Masroor, Werner, Mico May 31 '14 at 4:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

Thanks to lead from dartbith I came up with adding this to get Spanish characters to work in the code listings:

\lstset{
    language=Python,
    literate={á}{{\'a}}1
        {ã}{{\~a}}1
        {é}{{\'e}}1
        {ó}{{\'o}}1
        {í}{{\'i}}1
        {ñ}{{\~n}}1
        {¡}{{!`}}1
        {¿}{{?`}}1
        {ú}{{\'u}}1
        {Í}{{\'I}}1
        {Ó}{{\'O}}1
}
  • 2
    Missing some char... for completeness: literate={á}{{\'a}}1 {é}{{\'e}}1 {í}{{\'{\i}}}1 {ó}{{\'o}}1 {ú}{{\'u}}1 {Á}{{\'A}}1 {É}{{\'E}}1 {Í}{{\'I}}1 {Ó}{{\'O}}1 {Ú}{{\'U}}1 {ü}{{\"u}}1 {Ü}{{\"U}}1 {ñ}{{\~n}}1 {Ñ}{{\~N}}1 {¿}{{?``}}1 {¡}{{!``}}1 (wrong backticks on the last two, but well...) – Rmano Sep 24 '14 at 16:06

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