Awesome-Agent-Skills-for-Empirical-Research quarto-clean
Cleans a Quarto (.qmd) file by replacing LaTeX holdovers with proper Quarto/Pandoc syntax so the document renders correctly to HTML, PDF (Typst/LaTeX), and Word. Fixes citations (\citep → [@key]), cross-references (\ref → @label), figures (\includegraphics → markdown), tables, text formatting (\textbf → **bold**), inline math (\( \) → $ $), hyperlinks (\href → [text](url)), footnotes (\footnote → ^[]), list environments, section headings, and R Markdown chunk options (dot-style → #| YAML). Use when asked to clean, fix, modernize, or port a Quarto or R Markdown document; when LaTeX commands appear in a .qmd file; when a document fails to render to Word or Typst; or when citations/cross-references do not appear in non-LaTeX output.
git clone https://github.com/brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research
T=$(mktemp -d) && git clone --depth=1 https://github.com/brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/22-christopherkenny-skills/skills/quarto-clean" ~/.claude/skills/brycewang-stanford-awesome-agent-skills-for-empirical-research-quarto-clean && rm -rf "$T"
skills/22-christopherkenny-skills/skills/quarto-clean/SKILL.mdQuarto Clean
You clean a Quarto (
.qmd) document by replacing LaTeX holdovers with correct Quarto/Pandoc
syntax. Many authors migrate manuscripts from LaTeX or R Markdown and leave behind patterns
(e.g., \citep{}, \ref{}, \textbf{}) that silently fail when rendering to Word or Typst PDF.
This skill finds and fixes them all in a single pass.
This skill modifies the source file in place (or writes to a second path if supplied). Before writing, tell the user what file will be changed and remind them that
git diff or
file history can recover the original.
Input Arguments
| Position | Required | Description |
|---|---|---|
| 1 | Yes | Path to the file to clean (e.g., ). Cleaned in place by default. |
| 2 | No | Output path. If supplied, writes the cleaned file there instead of overwriting the input. |
Example invocations:
/quarto-clean paper/paper.qmd /quarto-clean paper/paper.qmd drafts/paper-clean.qmd
Step-by-Step Workflow
1. Parse Arguments
Identify the input
.qmd path (arg 1) and output path (arg 2, or same as arg 1 if omitted).
2. Read the File
Use the
Read tool to load the entire file. Hold the full content in memory — you will rewrite
it in one shot with the Write tool at the end.
3. Apply All Transformations
Work through the full content and apply every applicable transformation from the reference tables below. Key principles:
- Preserve protected regions: Never modify content inside fenced code blocks (
or```
), inline code (~~~
), display math (`
), inline math ($$...$$
), or YAML front matter ($...$
to---
). Treat these regions as opaque.--- - Handle nesting correctly: Because you understand the full document structure, handle nested
commands naturally.
→\textbf{something \cite{key}}
.**something [@key]**
→\footnote{See \cite{key} for details}
.^[See [@key] for details] - Apply all categories: Work through every category in the reference below. A single command
(
) may require multiple rules (\textbf{\emph{text}}
).***text*** - Be complete: Scan the entire file. Do not stop after the first occurrence of a pattern — fix every instance.
4. Write the Cleaned File
Use the
Write tool to overwrite the output path with the fully cleaned content. Do not use
Edit for individual substitutions — rewrite the whole file so nothing is missed.
5. Report to the User
Tell the user:
- Output path written
- Summary of fixes by category (how many of each type were converted)
- Items requiring manual review — any patterns you could not safely convert automatically (list with approximate line numbers so the user can find them)
- Reminder to run
to verifyquarto render
Transformation Reference
Apply every applicable rule. Rules are ordered so that inner/simpler commands are converted before outer/wrapper commands, which handles nesting correctly.
Citations
Convert all natbib/biblatex citation commands to Pandoc bracket syntax. These must work in all output formats (HTML, Word, Typst PDF).
| LaTeX | Quarto | Notes |
|---|---|---|
| | |
| | |
| | Split comma-separated keys |
| | Locator (suffix only) |
| | Prefix + locator |
| | Narrative / in-text citation |
| | Multiple narrative keys |
| | No parentheses |
| | Loses "author-only" semantics; flag in report |
| | Year only; suppresses author |
| Move to YAML | Remove from body; add to front matter |
| Move to YAML |
Cross-References
Convert
\label and \ref commands. The label prefix maps directly:
| LaTeX prefix | Quarto prefix | Example LaTeX | Example Quarto |
|---|---|---|---|
| | → | → |
or | | | |
or | | | |
or | | | |
| | ||
, , , etc. | same with |
Rules:
→\ref{type:name}
(replace@type-name
with:
, map prefix per table)-
→\autoref{type:name}@type-name
→\eqref{eq:name}@eq-name- Drop redundant type words:
→Figure \ref{fig:x}
(Quarto auto-generates "Figure N"). Same for "Table", "Section", "Equation", "Appendix".@fig-x
must be moved to the appropriate Quarto element as\label{type:name}
:{#type-name}- On a figure:
{#fig-name} - On a table caption:
: Caption {#tbl-name} - On a heading:
## Title {#sec-name} - On display math:
(on the line after$$...$$ {#eq-name}
)$$
- On a figure:
- Replace underscores with hyphens in the name part:
→fig:my_fig{#fig-my-fig}
R Markdown Chunk Options
Convert old-style inline chunk options to
#| YAML comments. The fence header becomes bare
(language only), and each option becomes a #| line inside the chunk.
Before:
```{r my-label, echo=FALSE, fig.cap="My figure", fig.width=6, out.width="80%"}
After:
```{r} #| label: my-label #| echo: false #| fig-cap: "My figure" #| fig-width: 6 #| out-width: "80%"
Option name mapping (dots → dashes, booleans → lowercase):
| Old | New |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| (remove — deprecated) |
The first unnamed token in the old header is the label:
{r my-label, echo=FALSE} → #| label: my-label.
Figures
| LaTeX | Quarto |
|---|---|
| |
| |
| |
inside figure env | attribute on the figure |
Full figure environment:
\begin{figure}[h] \centering \includegraphics[width=0.8\textwidth]{figs/map.pdf} \caption{A map of the study region.} \label{fig:map} \end{figure}
Becomes:
{#fig-map width=80% fig-align="center"}
→ add\begin{figure*}
to the attribute blockfig-env="figure*"- For computational figures in code chunks, use
and#| fig-cap:#| label: fig-...
Tables
Markdown / pipe tables:
| Col A | Col B | |:------|------:| | val | 1.23 | : My table caption. {#tbl-results}
- Column alignment from tabular spec:
→l
,:---
→r
,---:
→c:---: - Caption goes below the table, after
, with:
at the end{#tbl-label} - For computational tables (knitr/kable output), add chunk options instead:
#| label: tbl-results #| tbl-cap: "My table caption."
LaTeX table environment → Quarto pipe table:
\begin{table} \caption{My table caption.} \label{tab:results} \begin{tabular}{lrr} \hline Method & Estimate & SE \\ \hline OLS & 1.23 & 0.45 \\ IV & 1.89 & 0.67 \\ \hline \end{tabular} \end{table}
Becomes:
| Method | Estimate | SE | |:-------|--------:|-----:| | OLS | 1.23 | 0.45 | | IV | 1.89 | 0.67 | : My table caption. {#tbl-results}
Text Formatting
Handle nesting:
\textbf{\emph{text}} → ***text***.
| LaTeX | Quarto |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
Math
| LaTeX | Quarto |
|---|---|
| |
| |
/ | / with after closing |
/ | / |
inside math | Remove from math body; add after closing |
Hyperlinks
| LaTeX | Quarto |
|---|---|
| |
| |
Special Characters and Spacing
| LaTeX | Quarto | Notes |
|---|---|---|
| | Outside math |
| | Outside math |
or | | |
| | (also in Text Formatting above) |
| (remove) | |
| blank line | |
or | blank line or two trailing spaces | Paragraph break in prose |
or | | |
(tie space) | or | Context-dependent |
Section Headings
| LaTeX | Quarto |
|---|---|
| |
| |
| |
| |
| |
| |
If a
\label{sec:x} appears on the line following a heading, merge it into the heading's
attribute block: ## Methods {#sec-methods}.
List Environments
| LaTeX | Quarto |
|---|---|
/ | Unordered list with |
/ | Ordered list with |
/ | |
Nested lists: indent continuation lines by two spaces per level.
Abstract and Front Matter
Move these from the document body to YAML:
\begin{abstract} We study the effect of X on Y... \end{abstract}
→ YAML field:
abstract: | We study the effect of X on Y...
Similarly for
\title{}, \author{}, \date{} appearing in the body — move to YAML
title:, author:, date: fields.
Patterns That Need Judgment
Flag these in your report if you encounter them, with a suggested fix but no automatic conversion (the content depends too much on context):
- Custom LaTeX environments (
,\begin{theorem}
,\begin{proof}
,\begin{lemma}
, etc.) → suggest converting to\begin{frame}
or a theorem div::: {.callout-note}
/\vspace{}
→ no direct Quarto equivalent; suggest removing or using CSS\hspace{}
in tables → requires restructuring the table manually\multicolumn{}{}{}
→ converted to\citeauthor{key}
but the "author only" rendering is lost; suggest rephrasing (e.g., "Smith [-@smith2020]")@key
orcite-method: natbib
in YAML → should likely be removed for non-LaTeX output formats; flag for user decisioncite-method: biblatex
or\\[6pt]
(spacing in math display) → the spacing argument is not valid in Quarto; convert to\\[1em]
and note the spacing is lost\\
What to Preserve Unchanged
- All content inside
fenced code blocks (including chunk body code)```...``` - All content inside
inline code`...` - All content inside
inline math and$...$
display math (except$$...$$
which must be moved outside, and\label{}
/\( \)
delimiters which must be converted)\[ \] - YAML front matter between
delimiters--- - Quarto shortcodes
{{< ... >}} - Existing
cross-references and@ref
citations that are already correct[@citation] - Pandoc div/span syntax
and:::
that is already valid Quarto[]{}