A syntax highlighting package that supports over 500 programming languages and text formats with extensive output format options
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
The pygmentize command-line tool provides syntax highlighting functionality directly from the terminal, supporting all lexers, formatters, and styles available in Pygments.
pygmentize [options] [file]The main entry point for command-line syntax highlighting.
# Specify lexer (language)
pygmentize -l <lexer> [file]
pygmentize --lexer=<lexer> [file]
# Specify formatter (output format)
pygmentize -f <formatter> [file]
pygmentize --formatter=<formatter> [file]
# Specify style (color scheme)
pygmentize -S <style> -f <formatter>
pygmentize --style=<style> --formatter=<formatter>
# Guess lexer from content
pygmentize -g [file]
pygmentize --guess-lexer [file]
# Output to file
pygmentize -o <output> [options] [file]
pygmentize --outfile=<output> [options] [file]# Pass options to lexer
pygmentize -l python -P stripall=true -P tabsize=4 file.py
# Pass options to formatter
pygmentize -f html -O linenos=true -O cssclass=highlight file.py
# Multiple options
pygmentize -l python -f html -O linenos=true,cssclass=code file.py# List all lexers
pygmentize -L lexers
# List all formatters
pygmentize -L formatters
# List all styles
pygmentize -L styles
# List all filters
pygmentize -L filters
# Get help for specific component
pygmentize -H lexer python
pygmentize -H formatter html
pygmentize -H filter codetagfilter# Highlight Python file to HTML
pygmentize -l python -f html script.py
# Highlight with guessed lexer
pygmentize -g -f html script.py
# Highlight to terminal with colors
pygmentize -l python -f terminal script.py# Save HTML output
pygmentize -l python -f html -o output.html script.py
# Generate LaTeX
pygmentize -l python -f latex -o document.tex script.py
# Create PNG image (requires Pillow)
pygmentize -l python -f png -o code.png script.py# Use different color schemes
pygmentize -l python -f html -S monokai script.py
pygmentize -l python -f html -S github script.py
pygmentize -l python -f html -S vim script.py
# Terminal with color schemes
pygmentize -l python -f terminal256 -S monokai script.py# HTML with line numbers and custom CSS class
pygmentize -l python -f html -O linenos=true,cssclass=highlight script.py
# HTML with inline styles (no external CSS)
pygmentize -l python -f html -O noclasses=true script.py
# Full HTML document
pygmentize -l python -f html -O full=true,title="My Code" script.py
# LaTeX with line numbers
pygmentize -l python -f latex -O linenos=true script.py# Apply filters
pygmentize -l python -f html -F codetagfilter script.py
pygmentize -l python -f html -F keywordcase:case=upper script.py
# Multiple filters
pygmentize -l python -f html -F codetagfilter -F visiblewhitespace script.py# Read from stdin
echo "print('Hello')" | pygmentize -l python -f html
# Pipe output
pygmentize -l python -f html script.py | less
# Chain with other tools
cat script.py | pygmentize -g -f terminal | grep -A5 -B5 "function"# Basic HTML
pygmentize -l python -f html script.py
# HTML with options
pygmentize -l python -f html -O linenos=true,cssclass=code,title="Code" script.py# Basic terminal colors (16 colors)
pygmentize -l python -f terminal script.py
# 256-color terminal
pygmentize -l python -f terminal256 script.py
# True color terminal (24-bit)
pygmentize -l python -f terminal16m script.py# LaTeX
pygmentize -l python -f latex script.py
# RTF (Rich Text Format)
pygmentize -l python -f rtf script.py
# SVG vector graphics
pygmentize -l python -f svg script.py# PNG image (requires Pillow)
pygmentize -l python -f png -O font_size=14 script.py
# JPEG image
pygmentize -l python -f jpeg script.py
# GIF image
pygmentize -l python -f gif script.pyGenerate CSS for HTML output:
# Generate CSS for a style
pygmentize -S default -f html > style.css
pygmentize -S monokai -f html > dark.css
# Use generated CSS with HTML
pygmentize -l python -f html -O cssfile=style.css script.py# Process multiple files
for file in *.py; do
pygmentize -l python -f html -o "${file%.py}.html" "$file"
done
# Using find
find . -name "*.py" -exec pygmentize -l python -f html -o {}.html {} \;# Git diff with syntax highlighting
git show | pygmentize -l diff -f terminal
# Highlight code in README
pygmentize -l python -f html code_sample.py > code.html
# Generate documentation
pygmentize -l python -f latex -O full=true,title="API Reference" api.py > api.texCommon command-line errors:
# Unknown lexer
pygmentize -l nonexistent file.py
# Error: no lexer for alias 'nonexistent' found
# Unknown formatter
pygmentize -l python -f badformat file.py
# Error: no formatter found for name 'badformat'
# File not found
pygmentize -l python nonexistent.py
# Error: cannot read file
# Invalid options
pygmentize -l python -f html -O badoption=true file.py
# Error: unknown option 'badoption'# Default options
export PYGMENTIZE_STYLE=monokai
export PYGMENTIZE_FORMATTER=terminal256
# Use in scripts
pygmentize -l python file.py # Uses environment defaults# In .vimrc
command! -range=% Highlight :<line1>,<line2>w !pygmentize -l python -f html# Use as LESSOPEN processor
export LESSOPEN="| pygmentize -g %s"
less script.py # Automatically highlighted# Bash function for quick highlighting
highlight() {
pygmentize -g -f terminal256 "$1" | less -R
}
# Usage: highlight script.pyInstall with Tessl CLI
npx tessl i tessl/pypi-pygments