2

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

  • 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 Dec 1 '14 at 15:24
  • If your listings contain Unicode, you would be better off using minted or pythontex than using listings. – jub0bs Dec 1 '14 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 Dec 1 '14 at 17:25
2

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

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

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.