4

When using the package listing, colorized comments will not yield colorized exotic unicode characters.

exotic unicode characters within a comment are not colorized

This is a minimal working example:

\documentclass{minimal}

    \usepackage{
        listings,
        color,
        fontspec
    }

    \setmainfont{Linux Libertine}

    \lstset{
      commentstyle=\color{green},
    }

\begin{document}
    \begin{lstlisting}[language=Java,showtabs=false]
        // Comments are green, yet ‘•’ and ‘≤’ are not.
    \end{lstlisting}
\end{document}

Colorizing these characters generally works within listing environments:

unicode characters colorized by basicstyle

    \lstset{
      basicstyle=\color{green},
    }

\begin{document}
    \begin{lstlisting}[showtabs=false]
      Everything is green, even ‘•’ and ‘≤’.
    \end{lstlisting}
\end{document}

Is this a bug? How can I colorize the unicode characters within comments? I’m using TeXLive 2013 and lualatex.

8
  • Are you using XeLaTeX or LuaLaTeX?
    – egreg
    Oct 22, 2013 at 8:18
  • 2
    You will have to add the non-ascii letters (this includes the quote characters to \lst@ProcessLetter first. See e.g. tex.stackexchange.com/a/25396/2388. Oct 22, 2013 at 8:22
  • @egreg I’m using LuaLaTeX.
    – k.stm
    Oct 22, 2013 at 9:10
  • 1
    Add more chars in the line starting with ^^^^20ac. This is the input for the euro sign and reflects it unicode (U+20AC). Oct 22, 2013 at 9:17
  • 1
    I tested it: I added ^^^^2022^^^^2264 to the list and it worked fine. The symbols are now green. Oct 22, 2013 at 12:12

1 Answer 1

3

You have to add the the non-ascii letters (this includes the quote characters) to \lst@ProcessLetter (see https://tex.stackexchange.com/a/25396/2388}

\makeatletter
\lst@InputCatcodes
\def\lst@DefEC{%
 \lst@CCECUse \lst@ProcessLetter
  ^^80^^81^^82^^83^^84^^85^^86^^87^^88^^89^^8a^^8b^^8c^^8d^^8e^^8f%
  ^^90^^91^^92^^93^^94^^95^^96^^97^^98^^99^^9a^^9b^^9c^^9d^^9e^^9f%
  ^^a0^^a1^^a2^^a3^^a4^^a5^^a6^^a7^^a8^^a9^^aa^^ab^^ac^^ad^^ae^^af%
  ^^b0^^b1^^b2^^b3^^b4^^b5^^b6^^b7^^b8^^b9^^ba^^bb^^bc^^bd^^be^^bf%
  ^^c0^^c1^^c2^^c3^^c4^^c5^^c6^^c7^^c8^^c9^^ca^^cb^^cc^^cd^^ce^^cf%
  ^^d0^^d1^^d2^^d3^^d4^^d5^^d6^^d7^^d8^^d9^^da^^db^^dc^^dd^^de^^df%
  ^^e0^^e1^^e2^^e3^^e4^^e5^^e6^^e7^^e8^^e9^^ea^^eb^^ec^^ed^^ee^^ef%
  ^^f0^^f1^^f2^^f3^^f4^^f5^^f6^^f7^^f8^^f9^^fa^^fb^^fc^^fd^^fe^^ff%
  ^^^^2022^^^^2264% add more codes here
  ^^00}
\lst@RestoreCatcodes
\makeatother

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.