Verzeichnis macros/latex/contrib/pygmentex
PygmenTeX
A Python-based LaTeX package for typesetting code listings using Pygments.
Pygments is a generic syntax highlighter for general use in all kinds of software such as forum systems, wikis or other applications that need to prettify source code.
Requirements: You need to have Python and Pygments installed. For instructions, please refer to the Pygments home page.
The PygmenTeX Difference: Efficiency through Batching
Unlike other packages that call Pygments for each code snippet (a slow process), PygmenTeX collects all snippets and processes them in a single batch. This can lead to a significant reduction in compilation time for documents with many listings.
Quick Start
- Installation: Place the
pygmentex.styfile in a directory where LaTeX can find it. Ensure thepygmentex.pyscript is executable and located in a directory in yourPATH.
- Use it in your LaTeX document:
\documentclass{article} \usepackage{pygmentex} % Uses the 'default' style by default
\begin{document}
% Highlight a code snippet
\begin{pygmented}[lang=c]
#include <stdio.h>
int main(void)
{
int a, b, c;
printf("Enter two numbers to add: ");
scanf("%d%d", &a, &b);
c = a + b;
printf("Sum of entered numbers = %d\n", c);
return 0;
}
\end{pygmented}
% Highlight in line In this program, \pyginline[lang=c]|int| is a type and \pyginline[lang=c]|"Enter two numbers to add: "| is a literal string.
% Highlight an external file
\inputpygmented[lang=java, style=monokai]{Factorial.java}
\end{document}
```
- Compile the document with LaTeX (first run): Snippets are collected into a
.snippetsfile. - Run the Python Script: Process the snippets with
pygmentex.pyto generate a.pygmentedfile. - Compile the document with LaTeX (second run): The final document is produced using the pre-formatted output.
pygmentex.py your_document.snippets
Note: Shell escape (--shell-escape) is not required. The processing is a separate, explicit step. However, if shell escape is enabled, thepygmentex.pyscript may be executed automatically.
For full documentation and examples, see the compiled manual.
License
This project is licensed under the LaTeX Project Public License (LPPL), version v1.3c or later.
Herunterladen des vollständigen Inhalts dieses Pakets in einem Zip-Archiv (755.8k).
pygmentex – Use Pygments to format code listings in documents
PygmenTeX is a Python-based LaTeX package that can be used for typesetting code listings in a LaTeX document using Pygments.
Pygments is a generic syntax highlighter for general use in all kinds of software such as forum systems, wikis or other applications that need to prettify source code.
| Paket | pygmentex |
| Version | 0.12.1 2026-03-19 |
| Lizenzen | The LaTeX Project Public License 1.3 |
| Copyright | 2014–2026 José Romildo Malaquias |
| Betreuer | José Romildo Malaquias |
| Enthalten in | TeX Live als pygmentex MiKTeX als pygmentex |
| Themen | Listings Syntax-Highlighting |