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: ¹²³¼½¢
textcomp
(try\textonehalf
). But LuaLaTeX quite possibly will do the job good.minted
orpythontex
than usinglistings
.{½}{{\sfrac{1}{2}}}1{¼}{{\sfrac{1}{4}}}1{¢}{\textcent}1{¹}{{\textsuperscript{1}}}1{²}{{\textsuperscript{2}}}1{³}{{\textsuperscript{3}}}1