In this guide (25 items)
LaTeX Architecture Docs
LaTeX for Architecture Commands & Documentation Generation
MANDATORY FOR ALL AI AGENTS: This is the canonical guide when an
/arch-*command, thesoftware-architectskill, or/arch-docis asked to produce a board-grade PDF deliverable instead of (or in addition to) the default HTML+Mermaid output. Use LaTeX only when the user asks for PDF / print / signed deliverable / regulator-grade output. Default remains HTML+Mermaid perarch-doc-spec.md.
Companion documents:
- Architecture Document Spec — the 21-section structural contract (format-agnostic).
- Diagrams — diagram catalog (Mermaid is default; TikZ is the LaTeX equivalent).
- Gradle §4.x — build integration (Structurizr export, PlantUML).
1. When to use LaTeX vs Markdown/HTML
| Output need | Format | Why |
|---|---|---|
| Living docs, fast iteration, in-repo review | HTML + Mermaid (default) | Browser-native, no toolchain, version-control diff-friendly |
| Internal team reading, PR comments | Markdown | Diff-friendly, GitHub-rendered |
| Architecture Review Board (ARB) deliverable, audit evidence, regulator submission, executive sign-off, printed signature copy | LaTeX → PDF | Page numbering, ToC, cross-refs, glossary, biblio, deterministic layout, vector diagrams |
| Mixed: HTML in repo + PDF for board | Pandoc bridge — author once in Markdown, render both | Single source of truth |
Rule: never hand-author LaTeX for content that lives in HTML/Markdown elsewhere. Author once, transform.
2. Toolchain (pick one)
| Option | When | Setup |
|---|---|---|
| Tectonic (recommended) | Default for AI-driven generation | brew install tectonic. Self-contained, auto-fetches packages, reproducible, no system TeX Live needed. |
| TeX Live + latexmk | Existing TeX Live installs, large org standardization | brew install --cask mactex-no-gui or brew install texlive; latexmk -pdf. |
| Pandoc (bridge) | Author in Markdown, render LaTeX/PDF | brew install pandoc. Use with Tectonic engine: pandoc -t latex --pdf-engine=tectonic. |
Forbidden: Overleaf-only workflows. Architecture deliverables MUST build locally + in CI from repo sources.
3. Repo layout
docs/architecture/├── README.md # how to build, where artifacts go├── src/│ ├── architecture-document.tex # main file — \input{} other sections│ ├── preamble.tex # packages, macros, colors, geometry│ ├── titlepage.tex│ ├── sections/│ │ ├── 01-purpose.tex│ │ ├── 02-scope.tex│ │ ├── 03-stakeholders.tex│ │ ├── 04-adrs.tex # \input{../../adr/*.tex} or auto-gen from docs/adr/*.md│ │ ├── 08-context-map.tex│ │ ├── 09-c4-l1.tex # TikZ C4 model│ │ ├── 10-c4-l2.tex│ │ ├── 11-c4-l3.tex│ │ ├── 12-event-catalog.tex│ │ ├── 14-threat-model.tex # STRIDE table│ │ ├── 15-nfr.tex│ │ ├── 19-risk-register.tex│ │ └── ... # 21 mandatory sections (see arch-doc-spec.md)│ ├── diagrams/│ │ ├── c4-l1.tex # TikZ source│ │ ├── data-flow.tex│ │ └── *.plantuml # rendered to PDF via Gradle/plantuml-jar│ ├── tables/│ │ ├── stride-findings.tex│ │ └── nfr-targets.tex│ ├── glossary.tex # acronyms (DDD, CQRS, STRIDE, NFR…)│ └── bibliography.bib # biblatex refs (Evans DDD, Fowler, NIST, OWASP)├── build/ # gitignored: PDFs, .aux, .log, .toc└── Makefile # `make pdf`, `make watch`, `make clean`Do not check in build/. PDFs go to dist/ or release artifact storage.
4. Preamble (preamble.tex)
Locked baseline — extend per project, never delete:
\documentclass[11pt,a4paper,twoside,openright]{report}
% --- Layout\usepackage[a4paper,margin=2.5cm,headheight=14pt]{geometry}\usepackage{fancyhdr}\usepackage{microtype}\usepackage{parskip}
% --- Fonts\usepackage{fontspec} % requires xelatex / lualatex / tectonic\setmainfont{Inter}[Scale=1.0] % fallback: Latin Modern Roman\setmonofont{JetBrains Mono}[Scale=0.9]
% --- Colors (corporate palette — override per project)\usepackage{xcolor}\definecolor{archblue}{HTML}{0B5FFF}\definecolor{archteal}{HTML}{009688}\definecolor{archred}{HTML}{D32F2F}\definecolor{archgrey}{HTML}{37474F}\definecolor{codebg}{HTML}{F5F7FA}
% --- Cross-refs, links, ToC\usepackage[colorlinks=true,linkcolor=archblue,urlcolor=archblue,citecolor=archteal]{hyperref}\usepackage{bookmark}\usepackage{tocbibind}
% --- Code listings (minted requires --shell-escape + Pygments; listings is pure TeX)\usepackage{listings}\lstdefinestyle{code}{ basicstyle=\ttfamily\small, backgroundcolor=\color{codebg}, frame=single, rulecolor=\color{archgrey!20}, breaklines=true, captionpos=b, showstringspaces=false, keywordstyle=\color{archblue}\bfseries, commentstyle=\color{archgrey!70}\itshape, stringstyle=\color{archteal}}\lstset{style=code}
% --- Tables\usepackage{booktabs}\usepackage{longtable}\usepackage{tabularx}\usepackage{array}\usepackage{multirow}
% --- Diagrams\usepackage{tikz}\usetikzlibrary{positioning,shapes,arrows.meta,fit,calc,backgrounds,decorations.pathreplacing}\usepackage{pgfplots}\pgfplotsset{compat=1.18}
% --- Glossary / acronyms\usepackage[acronym,toc,nopostdot]{glossaries}\makenoidxglossaries
% --- Bibliography (biblatex)\usepackage[backend=biber,style=ieee,sorting=none]{biblatex}\addbibresource{bibliography.bib}
% --- Diagram package: C4 model in TikZ% No canonical CTAN package for C4 — define the styles manually.% Use the TikZ classDef shown in §6.1 of this guide (vendor it under src/sty/c4tikz.sty).
% --- Page style\pagestyle{fancy}\fancyhf{}\fancyhead[LE,RO]{\thepage}\fancyhead[RE]{\nouppercase{\leftmark}}\fancyhead[LO]{\nouppercase{\rightmark}}\renewcommand{\headrulewidth}{0.4pt}
% --- Reusable macros\newcommand{\arch}[1]{\textcolor{archblue}{\textbf{#1}}}\newcommand{\adrref}[1]{\hyperref[adr:#1]{ADR-#1}}\newcommand{\stridecell}[1]{\textcolor{archred}{\textbf{#1}}}\newcommand{\nfrcell}[1]{\textcolor{archteal}{\textbf{#1}}}\newcommand{\portname}[1]{\texttt{\textcolor{archblue}{#1}}}5. Main document skeleton (architecture-document.tex)
\input{preamble.tex}
\title{\textbf{\Huge Platform Architecture} \\[0.5em] \Large Platform --- Example}\author{Andres Montoya \\ \small Solutions Architecture}\date{\today \quad | \quad Version 1.0}
\input{glossary.tex}
\begin{document}\input{titlepage.tex}\tableofcontents\listoffigures\listoftables\printnoidxglossary[type=acronym,title=Acronyms]
\input{sections/01-purpose.tex}\input{sections/02-scope.tex}\input{sections/03-stakeholders.tex}\input{sections/04-adrs.tex}\input{sections/05-quality-attributes.tex}\input{sections/06-constraints.tex}\input{sections/07-principles.tex}\input{sections/08-context-map.tex}\input{sections/09-c4-l1.tex}\input{sections/10-c4-l2.tex}\input{sections/11-c4-l3.tex}\input{sections/12-event-catalog.tex}\input{sections/13-data-architecture.tex}\input{sections/14-threat-model.tex}\input{sections/15-nfr.tex}\input{sections/16-deployment.tex}\input{sections/17-observability.tex}\input{sections/18-evolution.tex}\input{sections/19-risk-register.tex}\input{sections/20-glossary.tex}\input{sections/21-references.tex}
\printbibliography[heading=bibintoc,title=References]\end{document}A board-grade section layout (adapt to your arch-doc-spec.md section set). Section files are short — each \input{}-able, regenerable per --ddd-only, --events-only, --stride-only, --risks-only flags of /arch-doc.
6. Diagrams in LaTeX
6.1 C4 model (TikZ)
C4 boxes via vendored c4tikz.sty or manual TikZ. Example L1 (System Context):
\begin{figure}[ht]\centering\begin{tikzpicture}[ node distance=2.5cm, person/.style={ rectangle, rounded corners=12pt, fill=archblue, text=white, minimum width=2.8cm, minimum height=1.4cm, align=center }, system/.style={ rectangle, fill=archteal, text=white, minimum width=3.2cm, minimum height=1.6cm, align=center }, external/.style={ rectangle, fill=archgrey!60, text=white, minimum width=3cm, minimum height=1.4cm, align=center }, rel/.style={-Stealth, thick, archgrey, font=\scriptsize}] \node[person] (operator) {Raffle\\Operator}; \node[system, right=of operator] (platform) {Platform}; \node[external, right=of platform] (stripe) {Stripe\\API}; \node[external, below=of platform] (sms) {SMS\\Gateway};
\draw[rel] (operator) -- node[above]{HTTPS / OIDC} (platform); \draw[rel] (platform) -- node[above]{Payments REST} (stripe); \draw[rel] (platform) -- node[right]{Notifications} (sms);\end{tikzpicture}\caption{C4 L1 --- System Context}\label{fig:c4-l1}\end{figure}6.2 Mermaid → PDF bridge
When existing diagrams are Mermaid (in HTML), render via Mermaid CLI to SVG then include:
mmdc -i diagrams/data-flow.mmd -o diagrams/data-flow.pdf -b transparent\begin{figure}[ht]\centering\includegraphics[width=0.9\textwidth]{diagrams/data-flow.pdf}\caption{Order checkout data flow}\label{fig:data-flow}\end{figure}6.3 PlantUML → PDF
Use Gradle PlantUML plugin (already documented in gradle.md) producing *.pdf artifacts, then \includegraphics.
6.4 Structurizr → PUML → PDF
Pipeline: Structurizr DSL → structurizrExport (PlantUML) → plantuml -tpdf → \includegraphics. Same as HTML pipeline but with -tpdf instead of -tsvg.
7. Tables — STRIDE, NFR, Risk Register
7.1 STRIDE findings (tables/stride-findings.tex)
\begin{longtable}{@{}p{2.4cm} p{3.2cm} p{1.6cm} p{4.8cm} p{2.4cm}@{}}\caption{STRIDE Findings --- Order Service}\label{tab:stride-orders}\\\toprule\textbf{Category} & \textbf{Asset} & \textbf{Severity} & \textbf{Mitigation} & \textbf{Owner} \\\midrule\endfirsthead\toprule\textbf{Category} & \textbf{Asset} & \textbf{Severity} & \textbf{Mitigation} & \textbf{Owner} \\\midrule\endhead\stridecell{Spoofing} & Operator JWT & High & OIDC + audience claim verification & Platform \\\stridecell{Tampering} & Outbox payload & Medium & HMAC signature on event body & Backend \\\stridecell{Repudiation} & Refund action & High & Append-only audit log + traceId & Backend \\\stridecell{Info disclosure} & PII in logs & Critical & Structured log scrubber + DLP rule & Platform \\\stridecell{DoS} & Public REST & Medium & Rate limit per tenant + WAF & Platform \\\stridecell{EoP} & Tenant boundary & Critical & ABAC policy + integration test & Backend \\\bottomrule\end{longtable}7.2 NFR target table (tables/nfr-targets.tex)
\begin{table}[ht]\centering\begin{tabularx}{\textwidth}{@{}lXll@{}}\toprule\textbf{Attribute} & \textbf{Scenario} & \textbf{Target} & \textbf{Measure} \\\midrule\nfrcell{Availability} & Operator REST p95 monthly & 99.9\% & Prometheus uptime \\\nfrcell{Latency} & Ticket reservation p95 & < 250ms & RED metric \\\nfrcell{Throughput} & Outbox publisher & 2k msg/s & Kafka lag \\\nfrcell{Recovery} & Cold start after region failover & RTO 15min & DR drill quarterly \\\bottomrule\end{tabularx}\caption{Non-Functional Requirements --- v2.4}\end{table}7.3 Risk register (sections/19-risk-register.tex)
Use longtable with columns: ID | Risk | Likelihood | Impact | Mitigation | Owner | Review date. Same severity colors via \stridecell/\nfrcell.
8. ADR rendering
Two strategies:
A. Hand-authored LaTeX ADRs under docs/adr/tex/ADR-NNNN-<slug>.tex, \input{} from section 04.
B. Pandoc bridge from Markdown ADRs (docs/adr/*.md via MADR template):
for f in docs/adr/*.md; do base=$(basename "$f" .md) pandoc "$f" -o "docs/architecture/src/sections/adr/${base}.tex" \ --top-level-division=section --wrap=preserve --to=latexdoneThen in 04-adrs.tex:
\chapter{Architectural Decision Records}\foreach \adr in {0001,0002,0003,...} { \input{sections/adr/ADR-\adr-slug.tex}}Recommended: use B. Single source of truth, ADRs live in docs/adr/*.md, board PDF auto-generated.
9. Build commands
9.1 Tectonic (recommended)
cd docs/architecturetectonic -X compile src/architecture-document.tex --outdir build --keep-logsmv build/architecture-document.pdf dist/architecture-v$(date +%Y%m%d).pdf9.2 latexmk (TeX Live)
cd docs/architecturelatexmk -pdf -xelatex -interaction=nonstopmode -outdir=build src/architecture-document.tex9.3 Pandoc bridge (Markdown → PDF)
pandoc docs/architecture/src/*.md \ --from markdown+raw_tex \ --to latex \ --pdf-engine=tectonic \ --template templates/arch.tex \ --toc --toc-depth=2 \ --bibliography src/bibliography.bib \ --citeproc \ -o dist/architecture-$(git describe --tags --always).pdf9.4 Makefile (canonical)
PDF_OUT := dist/architecture-$(shell git describe --tags --always).pdfSRC := src/architecture-document.tex
.PHONY: pdf watch clean adr-bridge diagrams
pdf: adr-bridge diagrams mkdir -p build dist tectonic -X compile $(SRC) --outdir build --keep-logs cp build/architecture-document.pdf $(PDF_OUT) @echo "→ $(PDF_OUT)"
watch: tectonic -X watch --src $(SRC)
adr-bridge: @for f in ../adr/*.md; do \ base=$$(basename $$f .md); \ pandoc $$f -o src/sections/adr/$$base.tex --top-level-division=section --to=latex; \ done
diagrams: @for f in src/diagrams/*.mmd; do \ mmdc -i $$f -o $${f%.mmd}.pdf -b transparent; \ done @for f in src/diagrams/*.plantuml; do \ plantuml -tpdf -o ../$(dir $$f) $$f; \ done
clean: rm -rf build dist10. CI integration (GitHub Actions)
name: arch-doc-pdfon: push: paths: ['docs/architecture/**', 'docs/adr/**'] workflow_dispatch:
jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - name: Install Tectonic run: | curl --proto '=https' --tlsv1.2 -fsSL https://drop-sh.fullyjustified.net | sh sudo mv tectonic /usr/local/bin/ - name: Install Pandoc + Mermaid CLI + PlantUML run: | sudo apt-get update sudo apt-get install -y pandoc plantuml graphviz npm install -g @mermaid-js/mermaid-cli - name: Build PDF working-directory: docs/architecture run: make pdf - name: Upload artifact uses: actions/upload-artifact@v5 with: name: architecture-pdf path: docs/architecture/dist/*.pdf retention-days: 90Gate ARB approval on this artifact (require successful build before merging architecture-document changes).
11. Integration with /arch-* commands
| Command | LaTeX touchpoint |
|---|---|
/arch-doc |
Add --format=latex flag → scaffolds docs/architecture/src/ skeleton from this guide instead of single HTML. --format=both generates HTML+LaTeX from same Markdown source via Pandoc. |
/arch-adr |
When ADR is accepted, run Pandoc Markdown→LaTeX into docs/architecture/src/sections/adr/. |
/arch-threat |
STRIDE table output → emit both Markdown (HTML rendering) and tables/stride-findings.tex (LaTeX). |
/arch-deps |
CVE / version drift table → tables/cve-findings.tex for board PDF. |
/arch-perf |
PERF-AUDIT.md → optional Pandoc-render into appendix sections/22-performance-audit.tex. |
/arch-review |
REVIEW.md → optional appendix. |
The HTML output remains the default and primary. LaTeX is an opt-in escalation for board-grade artifacts.
Required updates when wiring --format=latex into /arch-doc
- Add flag handling to
~/.claude/commands/arch-doc.md. - Add scaffolding step: create
docs/architecture/src/{preamble.tex,architecture-document.tex,sections/,diagrams/,tables/}skeleton. - Add Makefile from §9.4.
- Add CI workflow stub from §10.
- Verify Tectonic available locally:
command -v tectonic || echo "Install: brew install tectonic".
12. Anti-patterns (do NOT do)
- ❌ Hand-author duplicate content in LaTeX when it lives in HTML/Markdown. Single source of truth via Pandoc.
- ❌ Embed binary PDFs of diagrams in the repo. Generate from source (
*.mmd,*.plantuml,*.texTikZ) at build time. - ❌ Use
\usepackage{minted}without committing to--shell-escape+ Pygments availability in CI. Default tolistings. - ❌ Inline
\textcolor{red}{...}arbitrarily. Use semantic macros (\stridecell,\nfrcell,\portname). - ❌ Skip
\label{}+\ref{}for figures and tables. Cross-refs are mandatory for board readability. - ❌ Commit
build/artifacts to git. Gitignore everything underdocs/architecture/build/. - ❌ Use
pdflatexwhen the preamble loadsfontspec. Always Tectonic / XeLaTeX / LuaLaTeX. - ❌ Pin
texlive-fullDocker image (~5GB) in CI. Use Tectonic (~50MB).
13. Quick decision matrix
| Question | Answer |
|---|---|
| Need a PDF for ARB next week? | LaTeX via Tectonic + Pandoc bridge (§9.3). |
| Adding a new ADR to the deliverable? | Author in Markdown under docs/adr/, regenerate PDF via make pdf. |
| Need to update only the threat model section? | Run /arch-threat, copy table output to tables/stride-findings.tex, rebuild. |
| First-time setup in a repo? | Run /arch-doc --format=latex <slug> → scaffolds docs/architecture/ from this guide. |
| CI broke on missing font? | Install Inter + JetBrains Mono in the runner, or fall back to \setmainfont{Latin Modern Roman} (always present). |
| Diagram is a Mermaid block in HTML doc? | Bridge via mmdc -o foo.pdf, \includegraphics{foo.pdf}. |