4

This question already has an answer here:

I'm trying to highlight a couple of keywords which contain non-ASCII characters using the listingsutf8 package. This is the relevant part of my document:

\usepackage[brazilian]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage{listingsutf8}
\lstset{
    extendedchars=true,
    inputencoding=utf8x,
    keywords={Funcionalidade, Para, Como, Eu, Contexto, Cenário, Dado, Quando, Então},
    literate=%
{á}{{\'a}}1
{ã}{{\~a}}1
{ç}{{\c{c}}}1
{é}{{\'e}}1
{ê}{{\^e}}1
{õ}{{\~o}}1
{ó}{{\'o}}1
}

The ASCII only keywords are being highlighted correctly, but the Cenário and Então keywords are not. I have also tried with emph and changing inputencoding, but it doesn't work either:

\lstset{
    inputencoding=utf8/latin1,
    emph={Cenário, Cen\'ario, Cenario},emphstyle={\bfseries}
}

If it's relevant, the listing I'm trying to highlight comes from a separate file, using the \lstinputlisting command. If I had to guess, I would say that it has something to do with the literate params.

marked as duplicate by jub0bs, Sean Allred, Speravir, Jesse, ChrisS Mar 11 '14 at 2:09

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.

  • 1
    The highlight for Cenário will work just fine if you use XeLaTeX -- if it's suitable for your workflow, that is. – LianTze Lim Dec 9 '11 at 15:53
  • The detection of keywords in listings doesn't work well with UTF-8 encoded files. With latin1 encoding, specifying Cenário as keyword does what you want. Please, try providing a minimal example. – egreg Dec 9 '11 at 16:23
  • Unfortunately, I cannot use XeLaTeX right now. I have updated the question with a more concrete example. – Tomas Mattia Dec 10 '11 at 20:26
2

Try the listingsutf8 package from the oberdiek bundle. It offers a workaround exactly for the \lstinputlisting command.

  • I have tried (and edited the question to reflect the changes I have made), but even with the listingsutf8 package the keyword is not being highlighted. – Tomas Mattia Dec 10 '11 at 20:25
  • Too bad. And I have no other idea. – Thorsten Donig Dec 11 '11 at 10:44

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