LaTeX Document Creator
Create beautifully formatted LaTeX documents from any input source (markdown files, plain text, structured data, or user instructions). Produce professional-quality typeset output following modern LaTeX best practices.
Workflow
- Analyze input - Read the source material, identify structure (headings, lists, tables, figures, math, code, citations)
- Determine document class - Select appropriate class based on content type and length
- Generate LaTeX - Produce a complete
.tex file with proper preamble and body
- Compile to PDF (if requested) - Detect platform and compile using
latexmk
If the user provides additional formatting instructions, apply them. User instructions override defaults below.
Document Class Selection
| Content Type |
Class |
When |
| Short documents, articles, memos |
scrartcl |
No chapters needed |
| Reports, theses, long documents |
scrreprt |
Chapter-level structure |
| Books, manuals |
scrbook |
Front/back matter, parts |
| Presentations |
beamer |
Slides |
Use KOMA-Script classes (scrartcl, scrreprt, scrbook) over standard classes for superior typography defaults and built-in customization.
Standard Preamble
Organize the preamble in this order. Include only packages the document actually needs.
\documentclass[a4paper, 11pt]{scrartcl}
% --- Typography ---
\usepackage[T1]{fontenc}
\usepackage{lmodern} % Clean, professional font
\usepackage{microtype} % ESSENTIAL: character protrusion + font expansion
% --- Math (include only if document has math) ---
\usepackage{mathtools} % Superset of amsmath with fixes
\usepackage{amssymb}
% --- Layout ---
\usepackage{geometry}
% --- Tables & Figures ---
\usepackage{booktabs} % Professional table rules
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
% --- Lists ---
\usepackage{enumitem}
% --- Language & Quotes ---
\usepackage[english]{babel}
\usepackage{csquotes}
% --- Colors ---
\usepackage{xcolor}
% --- Code Listings (include only if document has code) ---
\usepackage{listings}
% --- Units (include only if document has quantities) ---
\usepackage{siunitx}
% --- Links & References (load near-last) ---
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=blue!70!black,
citecolor=green!50!black,
urlcolor=blue!70!black,
}
\usepackage{cleveref} % MUST be after hyperref
Package Notes
microtype is non-negotiable for professional output - always include it
mathtools loads amsmath automatically; never load both
cleveref must load after hyperref
hyperref should load near-last
- For bibliography: use
biblatex with biber backend, not legacy bibtex/natbib
Typography Rules
Fonts
- Default:
lmodern (Latin Modern) - clean, professional, widely available
- Alternative serif:
libertinus, newtxtext/newtxmath (Times-like)
- For system fonts (Unicode): switch to LuaLaTeX with
fontspec
Spacing and Punctuation
- En-dash for ranges:
2020--2025 renders as 2020–2025
- Em-dash for breaks:
word---word renders as word—word
- Non-breaking space (
~) before \cite, \cref, and between numbers and units
- Thin space before differentials:
\int f(x) \, dx
- Use
\enquote{} from csquotes for quotation marks, never manual quote characters
- Use
\emph{} instead of \textit{} - semantic emphasis that adapts to context
- Use
\dots for ellipses, never three periods
Sentence Spacing
- After abbreviations (not ending a sentence):
e.g.\ this, i.e.\ that
- After a capital letter ending a sentence:
NASA\@. The next sentence
Formatting Standards
Tables
- Always use
booktabs: \toprule, \midrule, \bottomrule
- Never use vertical rules (
|) or \hline
- Place table captions above the table
- Place figure captions below the figure
Figures
- Use
\centering inside floats, not \begin{center}
- Default float placement:
[htbp]
- Reference all figures in text before they appear
Cross-References
- Use
\cref{} from cleveref - automatically produces "Figure 1", "Table 2", etc.
- Label prefixes:
fig:, tab:, sec:, eq:, lst:
- Place
\label immediately after \caption or \section
Lists
- Use
enumitem for customization
- Avoid nesting deeper than 3 levels - restructure content instead
Common Pitfalls to Avoid
- Never use
$$...$$ for display math - use \[...\] or equation environment
- Never use
\\ for paragraph breaks - use a blank line
- Never use
\begin{center} inside floats - use \centering
- Never place
\label before \caption - produces wrong reference numbers
- Never hardcode reference numbers - always use
\cref{}
- Never use bare function names in math - use
\sin, \log, or \DeclareMathOperator
- Escape special characters:
#, %, $, &, _, {, }
Markdown-to-LaTeX Conversion
When converting from markdown, apply these mappings:
| Markdown |
LaTeX |
# Heading |
\section{Heading} |
## Heading |
\subsection{Heading} |
### Heading |
\subsubsection{Heading} |
**bold** |
\textbf{bold} |
*italic* |
\emph{italic} |
`code` |
\texttt{code} |
> blockquote |
\begin{quote}...\end{quote} |
- item |
\begin{itemize}\item ...\end{itemize} |
1. item |
\begin{enumerate}\item ...\end{enumerate} |
[text](url) |
\href{url}{text} |
 |
\begin{figure}...\includegraphics{path}...\end{figure} |
```lang ``` |
\begin{lstlisting}[language=lang]...\end{lstlisting} |
--- (horizontal rule) |
\bigskip\noindent\rule{\textwidth}{0.4pt}\bigskip |
| Tables |
\begin{tabular} with booktabs rules |
$math$ |
$math$ (same) |
$$math$$ |
\[math\] |
Conversion Guidelines
- Infer document title from the first
# heading or filename
- Infer
\author and \date if present in the source, otherwise omit
- Preserve the semantic structure - do not flatten or over-nest headings
- Convert markdown tables to
booktabs-styled tabular environments
- Escape all LaTeX special characters in text content
- For documents with chapters, promote heading levels (
# → \chapter, ## → \section)
Compiling to PDF
When the user requests PDF output, detect the platform and compile.
Engine Selection
| Engine |
Command |
Use When |
| pdfLaTeX |
latexmk -pdf |
Default. ASCII/Latin content, standard fonts, fastest compilation |
| XeLaTeX |
latexmk -xelatex |
System fonts via fontspec, native Unicode |
| LuaLaTeX |
latexmk -lualatex |
System fonts + Lua scripting, no memory limits |
Using latexmk (Preferred)
latexmk automatically runs the correct number of passes for cross-references, bibliographies, and indices. Always prefer it over manual multi-pass compilation.
latexmk -pdf document.tex # Compile to PDF (pdflatex)
latexmk -xelatex document.tex # Compile with XeTeX
latexmk -lualatex document.tex # Compile with LuaTeX
latexmk -c document.tex # Clean auxiliary files (keep PDF)
Manual Compilation (When latexmk Is Unavailable)
# Simple document (no bibliography)
pdflatex document.tex && pdflatex document.tex
# Document with biblatex/biber bibliography
pdflatex document.tex && biber document && pdflatex document.tex && pdflatex document.tex
Platform-Specific Installation
If LaTeX tools are not installed or compilation fails due to missing packages, read the appropriate platform guide for installation instructions:
- Ubuntu/Debian: Read
references/pdf-compilation-ubuntu.md
- macOS: Read
references/pdf-compilation-macos.md
Detect the platform with uname -s (Linux or Darwin).
Package installation requires system permissions — present the installation command to the user and let them confirm before running sudo or brew commands.
1---2name: latex3description: Generate LaTeX documents (or convert markdown to LaTeX) with professional typography. Optionally compile to PDF.4---56# LaTeX Document Creator78Create beautifully formatted LaTeX documents from any input source (markdown files, plain text, structured data, or user instructions). Produce professional-quality typeset output following modern LaTeX best practices.910## Workflow11121. **Analyze input** - Read the source material, identify structure (headings, lists, tables, figures, math, code, citations)132. **Determine document class** - Select appropriate class based on content type and length143. **Generate LaTeX** - Produce a complete `.tex` file with proper preamble and body154. **Compile to PDF** (if requested) - Detect platform and compile using `latexmk`1617If the user provides additional formatting instructions, apply them. User instructions override defaults below.1819## Document Class Selection2021| Content Type | Class | When |22|---|---|---|23| Short documents, articles, memos | `scrartcl` | No chapters needed |24| Reports, theses, long documents | `scrreprt` | Chapter-level structure |25| Books, manuals | `scrbook` | Front/back matter, parts |26| Presentations | `beamer` | Slides |2728Use KOMA-Script classes (`scrartcl`, `scrreprt`, `scrbook`) over standard classes for superior typography defaults and built-in customization.2930## Standard Preamble3132Organize the preamble in this order. Include only packages the document actually needs.3334```latex35\documentclass[a4paper, 11pt]{scrartcl}3637% --- Typography ---38\usepackage[T1]{fontenc}39\usepackage{lmodern} % Clean, professional font40\usepackage{microtype} % ESSENTIAL: character protrusion + font expansion4142% --- Math (include only if document has math) ---43\usepackage{mathtools} % Superset of amsmath with fixes44\usepackage{amssymb}4546% --- Layout ---47\usepackage{geometry}4849% --- Tables & Figures ---50\usepackage{booktabs} % Professional table rules51\usepackage{graphicx}52\usepackage{caption}53\usepackage{subcaption}5455% --- Lists ---56\usepackage{enumitem}5758% --- Language & Quotes ---59\usepackage[english]{babel}60\usepackage{csquotes}6162% --- Colors ---63\usepackage{xcolor}6465% --- Code Listings (include only if document has code) ---66\usepackage{listings}6768% --- Units (include only if document has quantities) ---69\usepackage{siunitx}7071% --- Links & References (load near-last) ---72\usepackage{hyperref}73\hypersetup{74 colorlinks=true,75 linkcolor=blue!70!black,76 citecolor=green!50!black,77 urlcolor=blue!70!black,78}79\usepackage{cleveref} % MUST be after hyperref80```8182### Package Notes8384- `microtype` is non-negotiable for professional output - always include it85- `mathtools` loads `amsmath` automatically; never load both86- `cleveref` must load after `hyperref`87- `hyperref` should load near-last88- For bibliography: use `biblatex` with `biber` backend, not legacy `bibtex`/`natbib`8990## Typography Rules9192### Fonts9394- Default: `lmodern` (Latin Modern) - clean, professional, widely available95- Alternative serif: `libertinus`, `newtxtext`/`newtxmath` (Times-like)96- For system fonts (Unicode): switch to LuaLaTeX with `fontspec`9798### Spacing and Punctuation99100- En-dash for ranges: `2020--2025` renders as 2020–2025101- Em-dash for breaks: `word---word` renders as word—word102- Non-breaking space (`~`) before `\cite`, `\cref`, and between numbers and units103- Thin space before differentials: `\int f(x) \, dx`104- Use `\enquote{}` from `csquotes` for quotation marks, never manual quote characters105- Use `\emph{}` instead of `\textit{}` - semantic emphasis that adapts to context106- Use `\dots` for ellipses, never three periods107108### Sentence Spacing109110- After abbreviations (not ending a sentence): `e.g.\ this`, `i.e.\ that`111- After a capital letter ending a sentence: `NASA\@. The next sentence`112113## Formatting Standards114115### Tables116117- Always use `booktabs`: `\toprule`, `\midrule`, `\bottomrule`118- Never use vertical rules (`|`) or `\hline`119- Place table captions **above** the table120- Place figure captions **below** the figure121122### Figures123124- Use `\centering` inside floats, not `\begin{center}`125- Default float placement: `[htbp]`126- Reference all figures in text before they appear127128### Cross-References129130- Use `\cref{}` from `cleveref` - automatically produces "Figure 1", "Table 2", etc.131- Label prefixes: `fig:`, `tab:`, `sec:`, `eq:`, `lst:`132- Place `\label` immediately after `\caption` or `\section`133134### Lists135136- Use `enumitem` for customization137- Avoid nesting deeper than 3 levels - restructure content instead138139## Common Pitfalls to Avoid140141- Never use `$$...$$` for display math - use `\[...\]` or `equation` environment142- Never use `\\` for paragraph breaks - use a blank line143- Never use `\begin{center}` inside floats - use `\centering`144- Never place `\label` before `\caption` - produces wrong reference numbers145- Never hardcode reference numbers - always use `\cref{}`146- Never use bare function names in math - use `\sin`, `\log`, or `\DeclareMathOperator`147- Escape special characters: `#`, `%`, `$`, `&`, `_`, `{`, `}`148149## Markdown-to-LaTeX Conversion150151When converting from markdown, apply these mappings:152153| Markdown | LaTeX |154|---|---|155| `# Heading` | `\section{Heading}` |156| `## Heading` | `\subsection{Heading}` |157| `### Heading` | `\subsubsection{Heading}` |158| `**bold**` | `\textbf{bold}` |159| `*italic*` | `\emph{italic}` |160| `` `code` `` | `\texttt{code}` |161| `> blockquote` | `\begin{quote}...\end{quote}` |162| `- item` | `\begin{itemize}\item ...\end{itemize}` |163| `1. item` | `\begin{enumerate}\item ...\end{enumerate}` |164| `[text](url)` | `\href{url}{text}` |165| `` | `\begin{figure}...\includegraphics{path}...\end{figure}` |166| `` ```lang ``` `` | `\begin{lstlisting}[language=lang]...\end{lstlisting}` |167| `---` (horizontal rule) | `\bigskip\noindent\rule{\textwidth}{0.4pt}\bigskip` |168| Tables | `\begin{tabular}` with `booktabs` rules |169| `$math$` | `$math$` (same) |170| `$$math$$` | `\[math\]` |171172### Conversion Guidelines173174- Infer document title from the first `#` heading or filename175- Infer `\author` and `\date` if present in the source, otherwise omit176- Preserve the semantic structure - do not flatten or over-nest headings177- Convert markdown tables to `booktabs`-styled `tabular` environments178- Escape all LaTeX special characters in text content179- For documents with chapters, promote heading levels (`#` → `\chapter`, `##` → `\section`)180181## Compiling to PDF182183When the user requests PDF output, detect the platform and compile.184185### Engine Selection186187| Engine | Command | Use When |188|---|---|---|189| pdfLaTeX | `latexmk -pdf` | Default. ASCII/Latin content, standard fonts, fastest compilation |190| XeLaTeX | `latexmk -xelatex` | System fonts via `fontspec`, native Unicode |191| LuaLaTeX | `latexmk -lualatex` | System fonts + Lua scripting, no memory limits |192193### Using latexmk (Preferred)194195`latexmk` automatically runs the correct number of passes for cross-references, bibliographies, and indices. Always prefer it over manual multi-pass compilation.196197```bash198latexmk -pdf document.tex # Compile to PDF (pdflatex)199latexmk -xelatex document.tex # Compile with XeTeX200latexmk -lualatex document.tex # Compile with LuaTeX201latexmk -c document.tex # Clean auxiliary files (keep PDF)202```203204### Manual Compilation (When latexmk Is Unavailable)205206```bash207# Simple document (no bibliography)208pdflatex document.tex && pdflatex document.tex209210# Document with biblatex/biber bibliography211pdflatex document.tex && biber document && pdflatex document.tex && pdflatex document.tex212```213214### Platform-Specific Installation215216If LaTeX tools are not installed or compilation fails due to missing packages, read the appropriate platform guide for installation instructions:217218- **Ubuntu/Debian**: Read `references/pdf-compilation-ubuntu.md`219- **macOS**: Read `references/pdf-compilation-macos.md`220221Detect the platform with `uname -s` (`Linux` or `Darwin`).222223Package installation requires system permissions — present the installation command to the user and let them confirm before running `sudo` or `brew` commands.