4

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: ¹²³¼½¢

3
  • 2
    I am not sure, but i think there mitght be a glyph available through package textcomp (try \textonehalf). But LuaLaTeX quite possibly will do the job good.
    – Johannes_B
    Commented Dec 1, 2014 at 15:24
  • If your listings contain Unicode, you would be better off using minted or pythontex than using listings.
    – jub0bs
    Commented Dec 1, 2014 at 17:22
  • now I found a solution {½}{{\sfrac{1}{2}}}1{¼}{{\sfrac{1}{4}}}1{¢}{\textcent}1{¹}{{\textsuperscript{1}}}1{²}{{\textsuperscript{2}}}1{³}{{\textsuperscript{3}}}1
    – Micha
    Commented Dec 1, 2014 at 17:25

1 Answer 1

4

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

2
  • 1
    Semi off-topic (will remove this comment): why is a second pair of braces needed sometimes? E.g., {{\"o}}.
    – Manuel
    Commented Dec 1, 2014 at 22:21
  • @Manuel Ah, knowing why would be interesting indeed!
    – egreg
    Commented Dec 1, 2014 at 22:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .