1\documentclass[12pt]{article}2\usepackage{listings}3\usepackage{xcolor}4\usepackage{courier}5
6\lstset{7 basicstyle=\ttfamily\small,8 keywordstyle=\color{blue}\bfseries,9 stringstyle=\color{red!70!black},10 commentstyle=\color{green!50!black}\itshape,11 numbers=left,12 numberstyle=\tiny\color{gray},13 numbersep=8pt,14 frame=single,15 breaklines=true,16 tabsize=2,17 showstringspaces=false,18}19
20\title{Code Listings in LaTeX}21\author{sublimated}22\date{}23
24\begin{document}25\maketitle26
27\section{Inline Code}28
29Use \lstinline|fn main()| for inline code. Variables like \lstinline|x| and30functions like \lstinline|calculate()| appear in monospace.31
32\section{Rust}33
34\begin{lstlisting}[language=Rust, caption={BLAKE3 hashing}]35use blake3;36
37fn hash_content(data: &[u8]) -> String {38 let hash = blake3::hash(data);39 format!("blake3-{}", hash.to_hex())40}41
42fn main() {43 let content = b"hello world";44 let cid = hash_content(content);45 println!("CID: {}", cid);46}47\end{lstlisting}48
49\section{Python}50
51\begin{lstlisting}[language=Python, caption={LaTeX log parser}]52import re53
54def parse_latex_log(log_text: str) -> dict:55 """Parse a LaTeX .log file into structured errors."""56 errors = []57 for line in log_text.splitlines():58 if line.startswith("! "):59 errors.append({60 "message": line[2:],61 "severity": "error",62 })63 return {"errors": errors, "success": len(errors) == 0}64\end{lstlisting}65
66\section{TypeScript}67
68\begin{lstlisting}[language=Java, caption={Content-addressed storage (TypeScript)}, morekeywords={async, await, const, let, export, import, from, type}]69export async function putCAS(70 cas: R2Bucket,71 content: Uint8Array,72): Promise<string> {73 const hash = await hashBytes(content);74 const key = hash.replace("blake3-", "");75 await cas.put(key, content);76 return hash;77}78\end{lstlisting}79
80\section{SQL}81
82\begin{lstlisting}[language=SQL, caption={Query with CTE}]83WITH recent_versions AS (84 SELECT item_id, MAX(version_number) AS latest85 FROM sublimated.versions86 WHERE created_at > NOW() - INTERVAL '7 days'87 GROUP BY item_id88)89SELECT i.name, i.type, rv.latest90FROM sublimated.items i91JOIN recent_versions rv ON rv.item_id = i.id92ORDER BY rv.latest DESC;93\end{lstlisting}94
95\section{Plain Verbatim}96
97For code without highlighting, use \texttt{verbatim}:98
99\begin{verbatim}100$ git clone sublimated.com/anton/paper.git101$ cd paper102$ vim main.tex103$ git push origin main104\end{verbatim}105
106\end{document} v1
commit 501ed07
message create code.tex via macOS
author anton
date Apr 18, 2026
size 2.4 KB