Skip to content

LaTeX code for syntax highlighting the Racket programming language with the listings package.

License

Notifications You must be signed in to change notification settings

GitMew/LaTeX-Listings-Racket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

LaTeX listings style for Racket programs

LaTeX code for (simple) syntax highlighting of the Racket programming language using the listings package.

Usage

Download the only LaTeX file in this repository. In your preamble, include it with \input{racket-lang.tex}. You can now use \begin{lstlisting}[language=racket] to typeset Racket code. The LaTeX file also defines a command \ir{...} for inline Racket code.

Example

This is a screenshot of the PDF generated by the LaTeX/Racket code below it.

Example of Racket code with syntax highlighting by the LaTeX package listings

The Racket code defines an abstract datatype for lambda expressions, and a procedure to check whether a variable occurs free in one. This example is copied from p. 46 of the book Essentials of Programming Languages (3rd ed.) by Friedman & Wand.

\documentclass{article}
\input{racket-lang.tex}

\begin{document}
\begin{lstlisting}[language=racket]
	;; Lambda calculus expressions
	(define-datatype lc-exp lc-exp?
		(var-exp
			(var symbol?))
		(lambda-exp
			(bound-var symbol?)
			(body lc-exp?))
		(app-exp
			(rator lc-exp?)
			(rand lc-exp?)))
	
	;; occurs-free? : Symbol * Lc-exp -> Bool
	(define occurs-free?
		(lambda (search-var exp)
			(cases lc-exp exp
				(var-exp (var) (eqv? var search-var))
			(lambda-exp (bound-var body)
				(and
					(not (eqv? search-var bound-var))
					(occurs-free? search-var body)))
			(app-exp (rator rand)
				(or
					(occurs-free? search-var rator)
					(occurs-free? search-var rand))))))
\end{lstlisting}
\end{document}

About

LaTeX code for syntax highlighting the Racket programming language with the listings package.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages