CTAN Comprehensive TeX Archive Network

Directory macros/latex/contrib/xlistings

README.md

xlistings

made-with-latex LPPL 1.3c PR's Welcome

This package extends on the listings package, providing an easier front-end to create code blocks of selected languages, support for number highlighting, highlighting, non-selectable line numbers,^1 and more. While it is not compatible with the minted package, it provides a similar interface for code highlighting that can be used as a partial drop-in replacement (see the documentation).

The following describes a list of improvements over the listings package:

  • Highlighting of numbers in code blocks: 10_234 + x1 * 0x34 - x2, including hexadecimal digits, exponents, and language sensitive type suffixes (0xdeadBEEF, 1e10, 10L in Java, 3j in Python, 10n in TypeScript)
  • Support for the \begin{minted}{<lang>} . . . \end{minted} environment
  • Wrapper macros like \bjava{int i} and \cjava{int i} and environments like \begin{plainjava}
  • \xlstb{<lang>}{<code>} for languages whose name cannot be part of a command name, e.g. \xlstb{x86}{mov eax, 0x10}
  • Language sensitive override: \xlstlangoverride{latex}{morekeywords=[5]{\\xlstsetstyle}}
  • Support for (accsupp based) non-selectable line numbers and characters
  • Support for blacklisting line numbers with \xlstblacklistlinenumbers
  • Support for umlauts and UTF-8 encoding (with the listingsutf8 package)
  • Provides autogobble to remove leading spaces (with the lstautogobble package)
  • Comfort key add to literate to add elements to the literate list
  • \LoadLanguages{<lang>} to load a language or multiple languages on demand
  • Opinionated language overwrites (see the langs/ folder)
  • Opinionated default literates such as :ldots:, :lan:, :to:, and :c:

The package is set up for l3build: l3build check runs the tests in tests/ and fails if a highlight changes unexpectedly. Each test states the sequence of styles it expects, and the resulting build/test/<name>.pdf shows the verdict together with the typeset sample, so the highlighting can also be inspected visually. A colour that leaks past its segment is invisible to such a trace, so tests/colorbleed.pvt additionally compares the pdf, reduced to the colour every piece of text is drawn in.

The manual is xlistings-doc. How this repository releases its packages is described in RELEASING.md.

Related packages

These packages build on xlistings or complement it:

  • code-link links the code in your listings to the place where it is defined or documented. It is a separate package that works with or without xlistings, developed in the same repository.
  • magic-haskell makes Haskell listings link to Hackage and to your own definitions, built on the styles, environments, and minted emulation of xlistings.
  • code-animation animates and highlights code snippets step by step, and is being made compatible with xlistings.
  • lc-visualizer typesets and reduces λ-terms. The lc language of xlistings (\begin{lc}, \blc{...}, with colored brackets and λ literates) highlights such terms in listings.

a number is truly non-selectable depends on the viewer used. To ensure that they can not be selected would require images, which we currently do not create/use.

Download the contents of this package in one zip archive (316.4k).

Xlistings – Opinionated extensions to the listings package

This package extends listings with an easier front-end for code blocks: language-sensitive highlighting of numbers (including hexadecimal literals, exponents and type suffixes), a drop-in minted environment, per-language wrapper macros and environments, non-selectable line numbers based on accsupp, language badges, and opinionated definitions for a set of common languages that are loaded on demand.

The separate package code-link links the code in xlistings blocks to where it is defined or documented.

PackageXlistings
Support
Bug tracker
Repository
Version1.1.1 2026-11-11
LicensesThe Project Public License 1.3c
Copyright2024–2026 Florian Sihler
MaintainerFlorian Sihler
Contained inTeX Live as xlistings
MiKTeX as xlistings
TopicsSyntax highlight
Verbatim
Listing
...
Guest Book Sitemap Contact Contact Author