Skip to main content
skill CX Codex

pandoc-pdf-generation — Claude Code skill: install and usage

Generates structured PDF documents from Markdown via Pandoc and XeLaTeX. Useful for technical reports with code blocks and tables.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add terrylica/cc-skills --skill pandoc-pdf-generation -a claude-code
Open on GitHub

What pandoc-pdf-generation does

The skill provides an automated build-pdf.sh script alongside a LaTeX preamble named table-spacing-template.tex. It formats documents in landscape orientation by default, using DejaVu Sans typography and colored hyperlinks. Code snippets stay together on a single page instead of splitting across page margins.

The build script detects standalone .md files in the current folder along with citation sources like references.bib. You can switch orientation with --portrait or drop HTML collapsible blocks via --hide-details. Without pandoc and xelatex installed locally, the pre-flight checks fail immediately.

Printing workflows rely on the system lpr utility with simplex and duplex options. The skill enforces user confirmation before sending any generated PDF to a physical printer.

What it helps with

  • compile Markdown notes into PDF with numbered headings and table of contents
  • strip collapsible <details> blocks from printable output via Lua filters
  • render wide ASCII diagrams cleanly using DejaVu Sans Mono
  • manage citations automatically from references.bib and CSL files

Example prompts for the agent

  • Convert document.md to PDF using portrait orientation.
  • Build a PDF report from Markdown and hide all <details> tags.
  • Generate a landscape PDF using monospace font for ASCII diagrams.

How to install pandoc-pdf-generation

1Skills CLI (Vercel)

npx skills add terrylica/cc-skills --skill pandoc-pdf-generation -a claude-code

2Manually: put the files in place

~/.claude/skills/pandoc-pdf-generation/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/pandoc-pdf-generation/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about pandoc-pdf-generation

How to install pandoc-pdf-generation in Claude Code?

Run npx skills add terrylica/cc-skills --skill pandoc-pdf-generation -a claude-code. The command creates the file at ~/.claude/skills/pandoc-pdf-generation/SKILL.md.

What does pandoc-pdf-generation do?

It compiles Markdown files into PDF format using Pandoc and the XeLaTeX engine. The skill manages layouts, prevents code blocks from breaking, and organizes bibliographies.

What dependencies are required for pandoc-pdf-generation?

Your machine needs pandoc and xelatex installed and accessible via system paths. The build script validates both binaries during pre-flight checks before compiling.

Source text

SKILL.md · MIT
---
name: pandoc-pdf-generation
description: PDF generation from markdown via Pandoc/XeLaTeX. TRIGGERS - markdown for PDF, print document, pandoc
allowed-tools: Bash, Read, Write
---

# Pandoc PDF Generation

> **Self-Evolving Skill**: This skill improves through use. If instructions are wrong, parameters drifted, or a workaround was needed — fix this file immediately, don't defer. Only update for real, reproducible issues.

## Overview

Generate professional PDF documents from Markdown using Pandoc with the XeLaTeX engine. This skill covers automatic section numbering, table of contents, bibliography management, LaTeX customization, and common troubleshooting patterns learned through production use.

## When to Use This Skill

Use this skill when:

- Converting Markdown to PDF with professional formatting requirements
- Needing automatic section numbering and table of contents
- Managing citations and bibliographies without manual duplication
- Controlling table formatting and page breaks in LaTeX output
- Building automated PDF generation workflows

## Quick Start: Universal Build Script

### Single Source of Truth Pattern

This skill provides production-proven assets in `$(cc-plugin-root doc-tools)/skills/pandoc-pdf-generation/assets/`:

- `table-spacing-template.tex` - Production-tuned LaTeX preamble (booktabs, colortbl, ToC fixes)
- `build-pdf.sh` - Universal auto-detecting build script

### From Any Project

```bash
/usr/bin/env bash << 'DETECT_EOF'
# Create symlink once per project (git-friendly)
ln -s "$(cc-plugin-root doc-tools)/skills/pandoc-pdf-generation/assets/build-pdf.sh" build-pdf.sh

# Auto-detect single .md file in directory (landscape default)
./build-pdf.sh

# Portrait mode
./build-pdf.sh --portrait document.md

# Monospace font for ASCII diagrams
./build-pdf.sh --monospace diagrams.md

# Explicit input/output
./build-pdf.sh input.md output.pdf
DETECT_EOF
```

**Options:**

| Flag             | Description                                     |
| ---------------- | ----------------------------------------------- |
| `--landscape`    | Landscape orientation (default)                 |
| `--portrait`     | Portrait orientation                            |
| `--monospace`    | Use DejaVu Sans Mono - ideal for ASCII diagrams |
| `--hide-details` | Hide `<details>` blocks from PDF                |
| `-h, --help`     | Show help message                               |

**Features:**

- ✅ Auto-detects input file (if single .md exists)
- ✅ Auto-detects bibliography (`references.bib`) and CSL files
- ✅ Always uses production-proven LaTeX preamble from skill
- ✅ Pre-flight checks (pandoc, xelatex, files exist)
- ✅ Post-build validation (file size, page count)
- ✅ Code blocks stay on same page (no splitting across pages)
- ✅ Lua filter to hide `<details>` blocks from PDF output

### Landscape PDF (Quick Command)

For landscape PDFs with blue hyperlinks (no build-pdf.sh dependency):

```bash
pandoc file.md -o file.pdf \
  --pdf-engine=xelatex \
  -V geometry:a4paper,landscape \
  -V geometry:margin=1in \
  -V fontsize=11pt \
  -V mainfont="DejaVu Sans" \
  -V colorlinks=true \
  -V linkcolor=blue \
  -V urlcolor=blue \
  --toc --toc-depth=2 \
  --number-sections
```

**Use landscape for**: Wide data tables, comparison matrices, technical docs with code blocks.

### Manual Command (With LaTeX Preamble)

```bash
/usr/bin/env bash << 'SKILL_SCRIPT_EOF'
pandoc document.md \
  -o document.pdf \
  --pdf-engine=xelatex \
  --toc \
  --toc-depth=3 \
  --number-sections \
  -V geometry:margin=1in \
  -V mainfont="DejaVu Sans" \
  -H "$(cc-plugin-root doc-tools)/skills/pandoc-pdf-generation/assets/table-spacing-template.tex"
SKILL_SCRIPT_EOF
```

---

## ASCII Diagrams

ASCII diagrams need consistent character alignment to survive PDF rendering: use box-drawing characters consistently and keep every row the same width.

**Also important**: Keep annotations OUTSIDE code blocks. Don't add inline comments like `# contains: file1, file2` inside diagram code blocks - they break alignment.

---

## Hiding Content for PDF Output

Use `--hide-details` to remove `<details>` blocks from PDF output. This is useful when:

- **Diagram source blocks**: Keep source in markdown for diagram regeneration, but hide from printed PDFs
- **Technical implementation notes**: Show in web/markdown view, hide from printed handouts
- **Collapsible sections**: HTML `<details>` tags don't render as collapsible in PDF

**Usage:**

```bash
./build-pdf.sh --hide-details document.md
```

**Markdown pattern:**

````markdown
## My Section

```diagram
┌─────┐     ┌─────┐
│ Box │ ──> │ Box │
└─────┘     └─────┘
```
````

<details>
<summary>diagram source</summary>

```
[Box] -> [Box]
```

</details>
```

With `--hide-details`, the entire `<details>` block is stripped from PDF output while remaining visible in markdown/HTML.

---

## Verification Checklist

Before considering a PDF "done", verify:

**Pre-Generation:**

- [ ] No manual section numbering in markdown (use `--number-sections`)
- [ ] Annotations are outside code blocks, not inside

**Post-Generation:**

- [ ] Open PDF and visually inspect each page
- [ ] Verify diagrams don't break across pages
- [ ] Check section numbering is correct (no "1. 1. Title" duplication)
- [ ] Confirm bullet lists render as bullets, not inline dashes

**Pre-Print:**

- [ ] Get user approval before printing
- [ ] Confirm orientation preference (landscape/portrait)
- [ ] Confirm duplex preference (one-sided/two-sided)

---

## Printing Workflow

Always let the user review the PDF before printing.

**Open for review:**

```bash
open output.pdf
```

**Print one-sided (simplex):**

```bash
lpr -P "PRINTER_NAME" -o Duplex=None output.pdf
```

**Print two-sided (duplex):**

```bash
lpr -P "PRINTER_NAME" -o Duplex=DuplexNoTumble output.pdf  # Long-edge binding
lpr -P "PRINTER_NAME" -o Duplex=DuplexTumble output.pdf    # Short-edge binding
```

**Find printer name:**

```bash
lpstat -p -d
```

**Never print without user approval** - this wastes paper if issues exist.

---

## Reference Documentation

For detailed information, see:

- [Core Development Principles](./references/core-principles.md) - **START HERE** - Universal principles learned from production failures
- [Markdown for PDF](./references/markdown-for-pdf.md) - Markdown structure patterns for clean landscape PDFs
- [YAML Front Matter Structure](./references/yaml-structure.md) - YAML metadata patterns
- [LaTeX Customization](./references/latex-parameters.md) - Preamble and table formatting
- [Bibliography & Citations](./references/bibliography-citations.md) - BibTeX and CSL styles
- [Document Patterns](./references/document-patterns.md) - Document type templates
- [Troubleshooting](./references/troubleshooting-pandoc.md) - Common issues and fixes

---

## Troubleshooting

| Issue                         | Cause                        | Solution                                          |
| ----------------------------- | ---------------------------- | ------------------------------------------------- |
| Font not found                | DejaVu Sans not installed    | `brew install font-dejavu`                        |
| xelatex not found             | MacTeX not installed         | `brew install --cask mactex`                      |
| Table breaks across pages     | Missing longtable package    | Include table-spacing-template.tex preamble       |
| Double section numbers        | Manual numbering in markdown | Remove manual numbers, use --number-sections only |
| Bullet list renders as dashes | Markdown formatting issue    | Check for proper blank lines before lists         |
| Bibliography not rendering    | Missing references.bib       | Create .bib file or remove --bibliography flag    |
| PDF file size too large       | Embedded fonts               | Use --pdf-engine-opt=-dEmbedAllFonts=false        |

## Post-Execution Reflection

After this skill completes, check before closing:

1. **Did the command succeed?** — If not, fix the instruction or error table that caused the failure.
2. **Did parameters or output change?** — If the underlying tool's interface drifted, update Usage examples and Parameters table to match.
3. **Was a workaround needed?** — If you had to improvise (different flags, extra steps), update this SKILL.md so the next invocation doesn't need the same workaround.

Only update if the issue is real and reproducible — not speculative.

© terrylica · MIT · terrylica/cc-skills

Similar skills

All skills for Writing and docs →

From the same set4

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor