Pandoc pdf generation

From terrylica/cc-skills · View interactive version

Pandoc pdf generation is an AI agent skill from the GitHub repository terrylica/cc-skills. PDF generation from markdown via Pandoc/XeLaTeX. TRIGGERS - markdown for PDF, print document, pandoc

How to use this skill

Skill file

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:

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/:

From Any Project

/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:

Landscape PDF (Quick Command)

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

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)

/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:

Usage:

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

Markdown pattern:

## My Section

┌─────┐ ┌─────┐

│ 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:**

open output.pdf


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

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


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

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:**

lpstat -p -d

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.