Skip to content

listings in Scissor LaTeX

The listings package works partly in Scissor LaTeX: lstlisting keeps the code exactly as typed and colours it when you give language= on the environment, and \lstinline works; \lstset, line numbers, frames, captions and labels are ignored, and \lstinputlisting is skipped.

What the package does

listings typesets source code. The lstlisting environment keeps line breaks and spaces, and with language=Python (or C, Java, SQL ...) it sets keywords, comments and strings in different styles. Options add line numbers, frames, captions and colours, either per listing or for the whole document with \lstset. \lstinline is the inline form, and \lstinputlisting reads code from a file.

What works here

FeatureIn Scissor LaTeXNotes
\begin{lstlisting} ... \end{lstlisting}WorksMonospaced, exactly as typed.
[language=Python] on the environmentWorksSyntax colours from a fixed scheme.
[language={[Sharp]C}] and other dialectsWorksThe dialect in brackets is read along with the name.
\lstinline|code|, \lstinline{code}WorksMonospaced, without colours.
numbers=left, frame=single, basicstyle, keywordstyle, backgroundcolorLeft outIgnored without a message.
caption=, label=Left outNo caption is printed, and a \ref to the label shows "??".
\lstset{...}, \lstdefinestyle, style=Left outIgnored, including a language= set there.
\lstinputlisting{file}Not supportedSkipped with a message.
\lstlistoflistings, \lstnewenvironmentNot supportedSkipped with a message.

Language names are not case-sensitive. Colours are available for common languages such as Python, C, C++, C#, Java, JavaScript, Rust, Go, R, MATLAB, SQL, Bash, HTML and TeX. A name that is not recognised, such as Fortran, gives plain monospaced code without a message.

Examples

Give the language on each listing:

lstlisting with language=Python

LaTeXPreamble: \usepackage{listings}Open in editor (opens in a new tab)
\begin{lstlisting}[language=Python]
def mean(values):
    # average of a list of numbers
    return sum(values) / len(values)

print(mean([40, 44, 48]))
\end{lstlisting}
Rendered by Scissor LaTeX: lstlisting with language=Python

A language set with \lstset is not used, so this listing has no colours. Layout options such as numbers and frame are ignored too:

\lstset is ignored

\documentclass{article}
\usepackage{listings}
\lstset{language=SQL, numbers=left, frame=single}
\begin{document}
\begin{lstlisting}
SELECT name FROM staff WHERE id = 44;
\end{lstlisting}
\begin{lstlisting}[language=SQL]
SELECT name FROM staff WHERE id = 44;
\end{lstlisting}
\end{document}

Inline code with \lstinline takes any delimiter, like \verb:

\lstinline in a sentence

LaTeXPreamble: \usepackage{listings}Open in editor (opens in a new tab)
The loop \lstinline|for i in range(44):| runs 44 times, and
\lstinline{total += i} adds up the numbers.
Rendered by Scissor LaTeX: \lstinline in a sentence

A captioned listing inside a figure

LaTeXPreamble: \usepackage{listings}Open in editor (opens in a new tab)
\begin{figure}[h]
\begin{lstlisting}[language=Python]
print(sum(range(44)))
\end{lstlisting}
\caption{Adding the numbers below 44}
\label{lst:sum}
\end{figure}
The code in Listing~\ref{lst:sum} prints 946.
Rendered by Scissor LaTeX: A captioned listing inside a figure

Compatibility

  • From a TeX installation to here: the code of every lstlisting is shown. Move language= from \lstset onto each listing to get colours, and paste code from \lstinputlisting files into the document.
  • From here to a TeX installation: documents compile there unchanged, and your options then apply.

The full manual is on CTAN: ctan.org/pkg/listings. See also Code listings in LaTeX and minted.

Questions and answers

Why are my listings not coloured?

The language is probably set with \lstset, which is ignored here. Write [language=Python] (or your language) after \begin{lstlisting}.

Can I show line numbers?

Not yet. numbers=left is accepted and ignored.

Every example on this page is typeset by Scissor LaTeX when the site is built. Last updated 2026-11-06.