Skip to main content

minted

Source-code listings with Pygments-powered syntax highlighting (requires shell-escape and Python).

Rendered LaTeX output
% After a period, LaTeX sets the wider sentence space by default. The exception: a period after a capital letter
% is taken for an abbreviation or initial ("T. Scientist", "NASA") and gets the narrow inter-word space.
% "XML." ends a sentence, so \@ before the period restores the sentence space.
% (The other way round, "e.g.\ details" forces the narrow space after a lowercase abbreviation; ~ is a
% non-breaking inter-word space, as in "Prof.~Dr.~Eike Kraft".)
% An abbreviation set with \gls{xml} needs no \@: glossaries ends it with a non-letter, so the period after it
% gets the sentence space. The plain "XML" here is for documents without the glossaries package.
\Zcref{lst:XML} shows source code written in XML\@.
\Zcref{line:comment} contains a comment.

\begin{listing}[htbp]
\begin{minted}[linenos=true,escapeinside=||]{xml}
<listing name="example">
<!-- comment --> |\label{line:comment}|
<content>not interesting</content>
</listing>
\end{minted}
\caption{Example XML listing using minted}
\label{lst:XML}
\end{listing}
Rendered LaTeX output
\begin{listing}[htbp]
\begin{minted}[linenos=true,escapeinside=||]{json}
{
key: "value"
}
\end{minted}
\caption{Example JSON listing using minted}
\label{lst:flJSON}
\end{listing}
Rendered LaTeX output
\begin{listing}[htbp]
\begin{minted}[linenos=true,escapeinside=||]{java}
public class Hello {
public static void main (String[] args) {
System.out.println("Hello World!");
}
}
\end{minted}
\caption{Java code rendered using minted}
\label{lst:flJava}
\end{listing}