[Tex/LaTex] UTF characters in listings

input-encodingslistingsunicode

I use lstlistings for code and a lot of special characters can be displayed with literate. See my MWE

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{listings,textcomp,eurosym}
\begin{document}
\lstset{extendedchars=true,language=java,basicstyle=\ttfamily,showspaces=false,showstringspaces=false,literate=%
{€}{\euro}1%
{§}{\S}1%
{°}{\textdegree{}}1%
{ä}{{\"a}}1%
{ö}{{\"o}}1%
{ü}{{\"u}}1%
{ß}{{\ss}}1%
{Ä}{{\"A}}1%
{Ö}{{\"O}}1%
{Ü}{{\"U}}1%
{µ}{\textmu}1%
} 

\begin{lstlisting}[language=Java]
// only for demonstration purposes
  public class keystrokes {
    public static void main(String[] args) {
      System.out.println("keystrokes on a German keyboard: €§°äöüßÄÖܵ");
    }
  }
\end{lstlisting}
\end{document}

But I don't know, how I can literate the following characters: ¹²³¼½¢

Best Answer

I see nothing strange with

\lstset{
  extendedchars=true,
  language=java,
  basicstyle=\ttfamily,
  showspaces=false,
  showstringspaces=false,
  literate=%
    {€}{\euro}1%
    {§}{\S}1%
    {°}{\textdegree{}}1%
    {ä}{{\"a}}1%
    {ö}{{\"o}}1%
    {ü}{{\"u}}1%
    {ß}{{\ss}}1%
    {Ä}{{\"A}}1%
    {Ö}{{\"O}}1%
    {Ü}{{\"U}}1%
    {µ}{\textmu}1%
    {¹}{{\textsuperscript{1}}}1%
    {²}{{\textsuperscript{2}}}1%
    {³}{{\textsuperscript{3}}}1%
    {¼}{\textonequarter}1%
    {½}{\textonehalf}1%
    {¢}{\textcent}1%
}

The input

\begin{lstlisting}[language=Java]
// only for demonstration purposes
  public class keystrokes {
    public static void main(String[] args) {
      System.out.println("keystrokes on a German
        keyboard: €§°äöüßÄÖܵ¹²³¼½¢");
    }
  }     
\end{lstlisting}     

produces

enter image description here

Related Question