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: This skill should be used when the user asks to "create a LaTeX document", "convert markdown to LaTeX", "make a PDF from markdown", "format as LaTeX", "write LaTeX", or wants to produce beautifully typeset documents. Handles LaTeX generation from any input source with professional typography, and optionally compiles to PDF.4allowed-tools: Read, Write, Bash(pdflatex:*), Bash(xelatex:*), Bash(lualatex:*), Bash(latexmk:*), Bash(biber:*), Bash(bibtex:*), Bash(which:*), Bash(uname:*)5metadata:6 source: https://skillmd.com/skills/diegosouzapw/latex7---89# LaTeX Document Creator1011Create 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.1213## Workflow14151. **Analyze input** - Read the source material, identify structure (headings, lists, tables, figures, math, code, citations)162. **Determine document class** - Select appropriate class based on content type and length173. **Generate LaTeX** - Produce a complete `.tex` file with proper preamble and body184. **Compile to PDF** (if requested) - Detect platform and compile using `latexmk`1920If the user provides additional formatting instructions, apply them. User instructions override defaults below.2122## Document Class Selection2324| Content Type | Class | When |25|---|---|---|26| Short documents, articles, memos | `scrartcl` | No chapters needed |27| Reports, theses, long documents | `scrreprt` | Chapter-level structure |28| Books, manuals | `scrbook` | Front/back matter, parts |29| Presentations | `beamer` | Slides |3031Use KOMA-Script classes (`scrartcl`, `scrreprt`, `scrbook`) over standard classes for superior typography defaults and built-in customization.3233## Standard Preamble3435Organize the preamble in this order. Include only packages the document actually needs.3637```latex38\documentclass[a4paper, 11pt]{scrartcl}3940% --- Typography ---41\usepackage[T1]{fontenc}42\usepackage{lmodern} % Clean, professional font43\usepackage{microtype} % ESSENTIAL: character protrusion + font expansion4445% --- Math (include only if document has math) ---46\usepackage{mathtools} % Superset of amsmath with fixes47\usepackage{amssymb}4849% --- Layout ---50\usepackage{geometry}5152% --- Tables & Figures ---53\usepackage{booktabs} % Professional table rules54\usepackage{graphicx}55\usepackage{caption}56\usepackage{subcaption}5758% --- Lists ---59\usepackage{enumitem}6061% --- Language & Quotes ---62\usepackage[english]{babel}63\usepackage{csquotes}6465% --- Colors ---66\usepackage{xcolor}6768% --- Code Listings (include only if document has code) ---69\usepackage{listings}7071% --- Units (include only if document has quantities) ---72\usepackage{siunitx}7374% --- Links & References (load near-last) ---75\usepackage{hyperref}76\hypersetup{77 colorlinks=true,78 linkcolor=blue!70!black,79 citecolor=green!50!black,80 urlcolor=blue!70!black,81}82\usepackage{cleveref} % MUST be after hyperref83```8485### Package Notes8687- `microtype` is non-negotiable for professional output - always include it88- `mathtools` loads `amsmath` automatically; never load both89- `cleveref` must load after `hyperref`90- `hyperref` should load near-last91- For bibliography: use `biblatex` with `biber` backend, not legacy `bibtex`/`natbib`9293## Typography Rules9495### Fonts9697- Default: `lmodern` (Latin Modern) - clean, professional, widely available98- Alternative serif: `libertinus`, `newtxtext`/`newtxmath` (Times-like)99- For system fonts (Unicode): switch to LuaLaTeX with `fontspec`100101### Spacing and Punctuation102103- En-dash for ranges: `2020--2025` renders as 2020–2025104- Em-dash for breaks: `word---word` renders as word—word105- Non-breaking space (`~`) before `\cite`, `\cref`, and between numbers and units106- Thin space before differentials: `\int f(x) \, dx`107- Use `\enquote{}` from `csquotes` for quotation marks, never manual quote characters108- Use `\emph{}` instead of `\textit{}` - semantic emphasis that adapts to context109- Use `\dots` for ellipses, never three periods110111### Sentence Spacing112113- After abbreviations (not ending a sentence): `e.g.\ this`, `i.e.\ that`114- After a capital letter ending a sentence: `NASA\@. The next sentence`115116## Formatting Standards117118### Tables119120- Always use `booktabs`: `\toprule`, `\midrule`, `\bottomrule`121- Never use vertical rules (`|`) or `\hline`122- Place table captions **above** the table123- Place figure captions **below** the figure124125### Figures126127- Use `\centering` inside floats, not `\begin{center}`128- Default float placement: `[htbp]`129- Reference all figures in text before they appear130131### Cross-References132133- Use `\cref{}` from `cleveref` - automatically produces "Figure 1", "Table 2", etc.134- Label prefixes: `fig:`, `tab:`, `sec:`, `eq:`, `lst:`135- Place `\label` immediately after `\caption` or `\section`136137### Lists138139- Use `enumitem` for customization140- Avoid nesting deeper than 3 levels - restructure content instead141142## Common Pitfalls to Avoid143144- Never use `$$...$$` for display math - use `\[...\]` or `equation` environment145- Never use `\\` for paragraph breaks - use a blank line146- Never use `\begin{center}` inside floats - use `\centering`147- Never place `\label` before `\caption` - produces wrong reference numbers148- Never hardcode reference numbers - always use `\cref{}`149- Never use bare function names in math - use `\sin`, `\log`, or `\DeclareMathOperator`150- Escape special characters: `#`, `%`, `$`, `&`, `_`, `{`, `}`151152## Markdown-to-LaTeX Conversion153154When converting from markdown, apply these mappings:155156| Markdown | LaTeX |157|---|---|158| `# Heading` | `\section{Heading}` |159| `## Heading` | `\subsection{Heading}` |160| `### Heading` | `\subsubsection{Heading}` |161| `**bold**` | `\textbf{bold}` |162| `*italic*` | `\emph{italic}` |163| `` `code` `` | `\texttt{code}` |164| `> blockquote` | `\begin{quote}...\end{quote}` |165| `- item` | `\begin{itemize}\item ...\end{itemize}` |166| `1. item` | `\begin{enumerate}\item ...\end{enumerate}` |167| `[text](url)` | `\href{url}{text}` |168| `` | `\begin{figure}...\includegraphics{path}...\end{figure}` |169| `` ```lang ``` `` | `\begin{lstlisting}[language=lang]...\end{lstlisting}` |170| `---` (horizontal rule) | `\bigskip\noindent\rule{\textwidth}{0.4pt}\bigskip` |171| Tables | `\begin{tabular}` with `booktabs` rules |172| `$math$` | `$math$` (same) |173| `$$math$$` | `\[math\]` |174175### Conversion Guidelines176177- Infer document title from the first `#` heading or filename178- Infer `\author` and `\date` if present in the source, otherwise omit179- Preserve the semantic structure - do not flatten or over-nest headings180- Convert markdown tables to `booktabs`-styled `tabular` environments181- Escape all LaTeX special characters in text content182- For documents with chapters, promote heading levels (`#` → `\chapter`, `##` → `\section`)183184## Compiling to PDF185186When the user requests PDF output, detect the platform and compile.187188### Engine Selection189190| Engine | Command | Use When |191|---|---|---|192| pdfLaTeX | `latexmk -pdf` | Default. ASCII/Latin content, standard fonts, fastest compilation |193| XeLaTeX | `latexmk -xelatex` | System fonts via `fontspec`, native Unicode |194| LuaLaTeX | `latexmk -lualatex` | System fonts + Lua scripting, no memory limits |195196### Using latexmk (Preferred)197198`latexmk` automatically runs the correct number of passes for cross-references, bibliographies, and indices. Always prefer it over manual multi-pass compilation.199200```bash201latexmk -pdf document.tex # Compile to PDF (pdflatex)202latexmk -xelatex document.tex # Compile with XeTeX203latexmk -lualatex document.tex # Compile with LuaTeX204latexmk -c document.tex # Clean auxiliary files (keep PDF)205```206207### Manual Compilation (When latexmk Is Unavailable)208209```bash210# Simple document (no bibliography)211pdflatex document.tex && pdflatex document.tex212213# Document with biblatex/biber bibliography214pdflatex document.tex && biber document && pdflatex document.tex && pdflatex document.tex215```216217### Platform-Specific Installation218219If LaTeX tools are not installed or compilation fails due to missing packages, read the appropriate platform guide for installation instructions:220221- **Ubuntu/Debian**: Read `references/pdf-compilation-ubuntu.md`222- **macOS**: Read `references/pdf-compilation-macos.md`223224Detect the platform with `uname -s` (`Linux` or `Darwin`).225226Package installation requires system permissions — present the installation command to the user and let them confirm before running `sudo` or `brew` commands.