Skip to content

Latest commit

 

History

History
71 lines (51 loc) · 1.78 KB

syntax_highlight_in_latex.md

File metadata and controls

71 lines (51 loc) · 1.78 KB

We provide a way to syntax-highlight Lean code in LaTeX documents. It requires a Python package Pygments and a LaTeX package minted.

Python Package: Pygments

Checkout Leanprover's Pygments repository and build Pygments:

hg clone https://bitbucket.org/leanprover/pygments-main
cd pygments-main
make mapfiles
sudo ./setup.py install

LaTeX package: minted

Save the latest version of minted.sty at the working directory.

How to use them (example)

Please save the following sample LaTeX file as test.tex:

\documentclass{article}
\usepackage{minted}
\setminted{encoding=utf-8}
\usepackage{fontspec}
\setmainfont{FreeSerif}
\setmonofont{FreeMono}
\usepackage{fullpage}
\begin{document}
\begin{minted}[mathescape,
               linenos,
               numbersep=5pt,
               frame=lines,
               framesep=2mm]{Lean}
theorem mul_cancel_left_or {a b c : ℤ} (H : a * b = a * c) : a = 0 ∨ b = c :=
have H2 : a * (b - c) = 0, by simp,
have H3 : a = 0 ∨ b - c = 0, from mul_eq_zero H2,
or.imp_or_right H3 (assume H4 : b - c = 0, sub_eq_zero H4)
\end{minted}
\end{document}

You can compile test.tex by executing the following command:

xelatex --shell-escape test

Some remarks:

  • xelatex is required to handle unicode in LaTeX.
  • --shell-escape option is needed to allow xelatex to execute pygmentize in a shell.

Contribute

Please fork Leanprover's Pygments repository, improve it, and make a pull-request.