julia-mono-listings
February 3, 2023 ยท View on GitHub
A custom Julia language style for the LaTeX listings package, and Unicode support for the JuliaMono font in a lstlisting environment.
- JuliaMono: https://github.com/cormullion/juliamono
- Julia Unicode: https://docs.julialang.org/en/v1/manual/unicode-input
- Julia pygments: https://github.com/sisl/pygments-julia
Note, we use
lualatexfor compilation.
Example
Typesetting the Thompson sampling algorithm from BeautifulAlgorithms.jl.
- See template on Overleaf (go to "Menu" โถ "Copy Project", must be logged in).
The LaTeX document:
\documentclass[11pt]{article}
\usepackage{julia-mono-listings}
\lstdefinelanguage{JuliaLocal}{
language = Julia, % inherit Julia lang. to add keywords
morekeywords = [3]{thompson_sampling}, % define more functions
morekeywords = [2]{Beta, Distributions}, % define more types and modules
}
\begin{document}
\begin{lstlisting}[language=JuliaLocal, style=julia]
using Distributions
function thompson_sampling(๐, ๐, apply; T=100)
for t in 1:T
๐ = rand.(Beta.(๐, ๐))
x = argmax(๐)
r = apply(x)
๐[x], ๐[x] = (๐[x] + r, ๐[x] + 1 - r)
end
return Beta.(๐, ๐)
end
\end{lstlisting}
\end{document}
Output PDF:
License
The font license is located here, and the license for this repo is located at LICENSE.md.