Skip to content

brycewang-stanford/Auto-Empirical-Research-Skills / skills/22-christopherkenny-skills/skills/latex-to-quarto

latex-to-quarto

Verified

Converts LaTeX article-class .tex documents to Quarto .qmd format for multi-format publishing (HTML, PDF, Word). Use when asked to convert, port, migrate, or translate a .tex LaTeX file to Quarto; when porting an academic paper or manuscript from LaTeX to Quarto; when a .tex document needs to render to HTML, Word, or Typst PDF. Covers preamble → YAML front matter, section headings, text formatting, math, citations (natbib/biblatex), cross-references, figures, tables, lists, footnotes, hyperlinks, and special characters.

references/10-misc.md

View on GitHub
# Miscellaneous: Special Characters, Spacing, Code, and Includes

---

## Special Characters

| LaTeX | Quarto | Notes |
|-------|--------|-------|
| `\&` | `&` | Outside math |
| `\%` | `%` | Outside math |
| `\$` | `$` | Outside math (literal dollar sign) |
| `\#` | `#` | Outside math |
| `\_` | `_` | Outside math |
| `\{` | `{` | Outside math |
| `\}` | `}` | Outside math |
| `\textbackslash` | `\` | Literal backslash |
| `\ldots` or `\dots` | `...` | Ellipsis |
| `\textellipsis` | `...` | |
| `---` (em dash) | `---` | Keep as-is (Pandoc converts to em dash) |
| `--` (en dash) | `--` | Keep as-is |
| `\textemdash` | `---` | |
| `\textendash` | `--` | |
| `\copyright` | `©` | Unicode directly |
| `\textregistered` | `®` | |
| `\texttrademark` | `™` | |
| `\S` | `§` | Section symbol |
| `\P` | `¶` | Paragraph symbol |
| `\dag` | `†` | Dagger |
| `\ddag` | `‡` | Double dagger |

---

## Spacing and Page Breaks

| LaTeX | Quarto | Notes |
|-------|--------|-------|
| `\newpage` | `{{< pagebreak >}}` | Quarto shortcode |
| `\clearpage` | `{{< pagebreak >}}` | |
| `\cleardoublepage` | `{{< pagebreak >}}` | |
| `\vspace{1em}` | *(remove)* | No direct equivalent; flag if critical |
| `\vspace*{1em}` | *(remove)* | |
| `\hspace{1em}` | ` ` or `&nbsp;` | Context-dependent; usually remove |
| `\smallskip` | *(remove)* | |
| `\medskip` | *(remove)* | |
| `\bigskip` | *(remove)* | |
| `\noindent` | *(remove)* | |
| `\par` | Blank line | |
| `\linebreak` | Two trailing spaces | Forces line break in paragraph |
| `\\` in prose | Blank line or two trailing spaces | |
| `~` (tie) | ` ` (space) | Non-breaking space; convert to regular space after cross-ref processing |

---

## Verbatim and Code Listings

### `verbatim` Environment

```latex
\begin{verbatim}
x <- 1:10
mean(x)
\end{verbatim}
```

→

````markdown
```
x <- 1:10
mean(x)
```
````

### `lstlisting` Environment

```latex
\begin{lstlisting}[language=R, caption={Mean calculation}, label={lst:mean}]
x <- 1:10
mean(x)
\end{lstlisting}
```

→

````markdown
```{r}
#| label: lst-mean
#| lst-cap: "Mean calculation"
x <- 1:10
mean(x)
```
````

For non-executed code (display only):

````markdown
```r
x <- 1:10
mean(x)
```
````

### `lstlisting` Language Mapping

| LaTeX `language=` | Fenced block language |
|-------------------|----------------------|
| `R` | `r` |
| `Python` | `python` |
| `Matlab` | `matlab` |
| `bash` or `sh` | `bash` |
| `C` | `c` |
| `C++` | `cpp` |
| `Java` | `java` |
| `SQL` | `sql` |
| *(none or unknown)* | *(no language tag)* |

### `minted` Environment

Convert the same way as `lstlisting`: extract the language identifier and code body.

### Inline Verbatim

| LaTeX | Quarto |
|-------|--------|
| `\verb|code|` | `` `code` `` |
| `\verb!code!` | `` `code` `` |
| `\texttt{code}` | `` `code` `` |

---

## `\input` and `\include` (Flag for Review)

Flag each occurrence with the filename and line number.

| LaTeX | Suggested Action |
|-------|-----------------|
| `\input{sections/intro}` | Inline the file contents here, OR replace with `{{< include sections/intro.qmd >}}` |
| `\include{sections/intro}` | Same as `\input` |
| `\input{tables/results}` | If the file is a pure tabular block, inline and convert the table |

When inlining: read the included `.tex` file and apply all the same conversion rules to
its content before inserting it at the `\input` location.

---

## Macro Definitions (Flag for Review)

Flag each `\newcommand` / `\renewcommand` / `\DeclareMathOperator`:

```latex
\newcommand{\E}{\mathbb{E}}
\newcommand{\Var}{\operatorname{Var}}
\DeclareMathOperator*{\argmax}{arg\,max}
```

For each:
1. Note the command name and its expansion
2. Count the occurrences in the document body
3. Inline the expansion at each occurrence

Example:
- `\E[X]` → `\mathbb{E}[X]`
- `\Var(X)` → `\operatorname{Var}(X)`
- `\argmax_x f(x)` → `\operatorname*{arg\,max}_x f(x)`

Report each substitution count so the user can verify completeness.

---

## Comments

LaTeX `%` comments are removed entirely during conversion — they are not part of the
document content and have no Quarto equivalent.

Exception: if a comment appears to be a structural TODO or important annotation
(e.g., `% TODO: update this figure`), flag it in your report so the user can decide
whether to convert it to a Quarto comment `<!-- TODO: update this figure -->`.

---

## Raw LaTeX Blocks (Last Resort)

For patterns that truly have no Quarto equivalent and cannot be restructured,
you may wrap them in a raw LaTeX block for PDF-only rendering:

```markdown
```{=latex}
\begin{somepackageenv}
  ...
\end{somepackageenv}
```
```

Flag these prominently: raw LaTeX blocks will not render in HTML or Word output.
Use this only when flagging for manual review is insufficient and the user needs
something in place.

---

## TikZ / PGF Diagrams (Flag for Review)

TikZ diagrams have no automatic Quarto equivalent. Flag each one:

> **Manual review needed**: TikZ diagram at line N. Options:
> - Replace with a Mermaid diagram (flowcharts, sequence diagrams): ` ```{mermaid} `
> - Replace with an Observable JS visualization for interactive HTML
> - Keep as a raw LaTeX block (`{=latex}`) for PDF-only output
> - Export the TikZ diagram to PDF/PNG and include as a static figure

Do not attempt automatic conversion.
canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill.Stars: 198kUpdated Claude CodeCodexVerifiedInstall