Claude Code for LaTeX Document Workflow 2026
The Workflow
Use Claude Code to write, edit, and manage LaTeX documents for academic papers, theses, technical reports, and presentations. Claude Code handles complex formatting, bibliography management, equation typesetting, and compilation pipeline automation.
Expected time: 10 minutes setup Prerequisites: TeX Live 2024+ or MiKTeX, Claude Code CLI installed, latexmk
Setup
1. Install LaTeX and Tools
# macOS
brew install --cask mactex-no-gui
brew install latexmk
# Ubuntu/Debian
sudo apt install texlive-full latexmk
# Verify
pdflatex --version
latexmk --version
biber --version
2. Create CLAUDE.md for LaTeX Projects
# Project: Research Paper
LaTeX document using ACM sigconf template.
## Conventions
- Use biblatex with biber backend (not bibtex)
- All figures in figures/ directory as PDF or PNG
- Tables use booktabs package (no vertical lines)
- Code listings use minted package
- Cross-references: \cref{} from cleveref package
- Citations: \textcite{} for narrative, \parencite{} for parenthetical
- One sentence per line in source (for better git diffs)
- Compile with: latexmk -pdf -shell-escape main.tex
3. Create Compilation Script
cat > build.sh << 'EOF'
#!/bin/bash
set -e
echo "Building LaTeX document..."
latexmk -pdf -shell-escape -interaction=nonstopmode main.tex
if [ $? -eq 0 ]; then
echo "Success: main.pdf generated ($(du -h main.pdf | cut -f1))"
else
echo "Build failed. Check main.log for errors."
tail -20 main.log
exit 1
fi
EOF
chmod +x build.sh
4. Verify
claude --print "What LaTeX packages are loaded in main.tex?"
# Expected output:
# Lists the packages from your document preamble
Usage Example
Generate a complete research paper structure with Claude Code:
claude
> Create a LaTeX paper structure for a computer science research paper:
> - ACM sigconf format
> - Title: "Efficient Caching Strategies for Distributed LLM Inference"
> - Sections: Abstract, Introduction, Background, Methodology,
> Evaluation, Related Work, Conclusion
> - biblatex with biber
> - Include a Makefile for compilation
Claude Code generates:
% main.tex
\documentclass[sigconf,nonacm]{acmart}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{cleveref}
\usepackage[style=acmauthoryear,backend=biber]{biblatex}
\addbibresource{references.bib}
\title{Efficient Caching Strategies for Distributed LLM Inference}
\author{Jane Smith}
\affiliation{%
\institution{University of Example}
\city{San Francisco}
\state{California}
\country{USA}
}
\email{[email protected]}
\begin{abstract}
We present a novel caching framework for distributed large language
model inference that reduces redundant computation by 47\%
while maintaining response quality.
Our approach combines semantic similarity caching with
prefix-aware key-value cache sharing across inference nodes.
\end{abstract}
\begin{document}
\maketitle
\section{Introduction}
\label{sec:introduction}
Large language model inference at scale presents significant
computational challenges.
Each request requires processing through billions of parameters,
making caching strategies essential for practical deployment.
\section{Background}
\label{sec:background}
\subsection{KV-Cache in Transformer Models}
The key-value cache stores intermediate attention computations
to avoid redundant work during autoregressive generation
\parencite{vaswani2017attention}.
For a model with $L$ layers and head dimension $d_h$,
the cache size per token is:
\begin{equation}
\text{Cache}_{size} = 2 \times L \times n_h \times d_h \times \text{sizeof(dtype)}
\label{eq:cache-size}
\end{equation}
where $n_h$ is the number of attention heads.
\subsection{Semantic Caching}
Semantic caching groups requests by embedding similarity
rather than exact string matching.
Given an embedding function $f: \mathcal{T} \to \mathbb{R}^d$,
two prompts $p_1, p_2$ share a cache entry when:
\begin{equation}
\text{sim}(f(p_1), f(p_2)) > \tau
\label{eq:similarity}
\end{equation}
\section{Methodology}
\label{sec:methodology}
Our framework operates in three stages, as shown in \cref{fig:architecture}.
\begin{figure}[t]
\centering
\includegraphics[width=\columnwidth]{figures/architecture.pdf}
\caption{System architecture showing the three-stage caching pipeline.}
\label{fig:architecture}
\end{figure}
\section{Evaluation}
\label{sec:evaluation}
\begin{table}[t]
\centering
\caption{Inference latency comparison (ms) across caching strategies.}
\label{tab:latency}
\begin{tabular}{lrrr}
\toprule
Strategy & P50 & P95 & P99 \\
\midrule
No cache & 2,340 & 4,120 & 6,890 \\
Exact match & 1,890 & 3,450 & 5,230 \\
Semantic (ours) & 980 & 2,100 & 3,410 \\
\bottomrule
\end{tabular}
\end{table}
The results in \cref{tab:latency} demonstrate that our semantic
caching approach reduces median latency by 58\% compared to
no caching and 48\% compared to exact-match caching.
\section{Related Work}
\label{sec:related}
\textcite{pope2023efficiently} introduced the concept of
paged attention for efficient KV-cache management.
\section{Conclusion}
\label{sec:conclusion}
We presented a semantic caching framework that significantly
reduces inference latency for distributed LLM serving.
\printbibliography
\end{document}
# Makefile
.PHONY: all clean watch
all: main.pdf
main.pdf: main.tex references.bib
latexmk -pdf -shell-escape -interaction=nonstopmode main.tex
clean:
latexmk -C
rm -f *.bbl *.run.xml
watch:
latexmk -pdf -shell-escape -pvc main.tex
Continue editing with Claude Code:
> Add a "Limitations" subsection to the Conclusion. Mention that
> our approach has higher memory overhead and doesn't handle
> streaming responses. Include the equation for memory overhead.
Common Issues
- biber fails with “control file not found”: Run
latexmk -Cto clean all auxiliary files, then rebuild from scratch. - minted package errors: Ensure
-shell-escapeflag is passed to pdflatex. The build script above includes this. - Claude Code inserts incorrect LaTeX escapes: Add to CLAUDE.md: “When writing LaTeX, use raw LaTeX commands. Do not HTML-escape ampersands or percent signs.”
Why This Matters
Researchers spend 30-40% of paper-writing time on LaTeX formatting. Claude Code handles the boilerplate, equation typesetting, and table formatting so you can focus on the content and analysis.