Paket minted
Voraussetzungen: das Python-Paket Pygments
--shell-escape Flag hinzufügen (TeXstudio: Options > Configure TeXstudio > Commands "pdflatex -syntex=1 -interaction=nonstopmode %.tex" in "pdflatex -syntex=1 -interaction=nonstopmode --shell-escape %.tex" ändern)
\begin{minted}{java}
public class Duck {
public static void main(String[] args) {
System.out.println("Hallo,Welt!");
}
}
\end{minted}
\begin{minted}{python}
def printHello:
print("Hallo, Welt!")
\end{minted}