Use when the user needs to convert documents between formats with Pandoc, including Markdown, DOCX, PDF, HTML, EPUB, LaTeX, Typst, RST, AsciiDoc, Org, ODT, R...
---
name: pandoc-convert
description: Use when the user needs to convert documents between formats with Pandoc, including Markdown, DOCX, PDF, HTML, EPUB, LaTeX, Typst, RST, AsciiDoc, Org, ODT, RTF, ipynb, single-file conversion, batch document conversion, citations, templates, table of contents, Pandoc installation help, or PDF engine troubleshooting.
allowed-tools:
- Bash(bash */scripts/convert.sh *)
- Bash(bash */scripts/validate.sh *)
- Bash(bash */scripts/install_pandoc.sh *)
- Bash(python3 */scripts/batch_convert.py *)
- Bash(pandoc *)
- Read
- Glob
- Grep
---
# Pandoc Convert
Convert documents with Pandoc while keeping conversions predictable, validated, and easy to troubleshoot. Prefer the bundled wrappers for user-facing work because they add dependency checks, safer defaults, progress output, retries, and reports.
## Quick Decision
- Use `scripts/convert.sh` when the user gives one input file or asks for one output.
- Use `scripts/batch_convert.py` when the user gives a directory, multiple files, a glob, or says “批量 / batch”.
- Use `scripts/validate.sh` when the user asks whether a document is ready to convert or when a conversion needs citations, templates, CSS, resources, or PDF output.
- Use `scripts/install_pandoc.sh` only when the user explicitly asks to install Pandoc or fix a missing Pandoc dependency.
- If the target is PDF, mention that Pandoc needs a PDF engine. For Chinese documents, prefer `--pdf-engine xelatex` when available.
## Installation Policy
Do not silently install Pandoc during conversion. If Pandoc is missing, report the validation error and ask whether the user wants installation help.
Run the installer in dry-run mode first unless the user explicitly requested installation:
```bash
bash ${CLAUDE_SKILL_DIR}/scripts/install_pandoc.sh
```
Only run installation with explicit user approval:
```bash
bash ${CLAUDE_SKILL_DIR}/scripts/install_pandoc.sh --yes
```
The installer detects existing `pandoc`, Homebrew, Conda, `apt-get`, `dnf`, or `pacman`, then prints or runs the recommended command. It does not install PDF engines such as `xelatex`; handle PDF engine setup separately.
## Single File Workflow
1. Confirm the input file exists and infer the requested output format.
2. If the output path is missing, suggest a default beside the input file, for example `README.md` → `README.docx`.
3. Run the wrapper from the skill directory:
```bash
bash ${CLAUDE_SKILL_DIR}/scripts/convert.sh input.md -o output.docx
bash ${CLAUDE_SKILL_DIR}/scripts/convert.sh input.md -o output.pdf --pdf-engine xelatex --toc
bash ${CLAUDE_SKILL_DIR}/scripts/convert.sh input.md -o output.pdf --citeproc --bibliography refs.bib --csl style.csl
```
4. Report the generated file path. If the command fails, show the actionable error and recommend the smallest fix.
## Batch Workflow
Use the Python batch wrapper for retries, fault tolerance, progress, and reports:
```bash
python3 ${CLAUDE_SKILL_DIR}/scripts/batch_convert.py docs --output-dir out --to docx
python3 ${CLAUDE_SKILL_DIR}/scripts/batch_convert.py docs --output-dir out --to pdf --pdf-engine xelatex --retries 2
python3 ${CLAUDE_SKILL_DIR}/scripts/batch_convert.py docs --output-dir out --to html --continue-on-error --report out/report.md --json-report out/report.json
```
Batch behavior:
- Preserves relative paths: `docs/a/b.md` becomes `out/a/b.pdf`.
- Skips hidden directories, `.git`, `node_modules`, `dist`, `build`, `target`, and the output directory.
- Shows progress like `[3/28] converting docs/a.md -> out/a.pdf`.
- Retries failed files with `--retries N` and `--retry-delay SEC`.
- Continues after failures by default, unless `--fail-fast` is passed.
- Summarizes success, failure, and skipped counts and can write Markdown/JSON reports.
If any files fail, never say the whole batch succeeded. List failed files, report paths, and a retry command.
## Common Options
| Need | Option |
|---|---|
| Input format override | `--from markdown`, `--from gfm`, `--from docx` |
| Output format override | `--to html`, `--to docx`, `--to pdf`, `--to epub` |
| Standalone document | `--standalone` or `-s` |
| Table of contents | `--toc --toc-depth 3` |
| Numbered sections | `--number-sections` |
| Citations | `--citeproc --bibliography refs.bib --csl style.csl` |
| DOCX style | `--reference-doc reference.docx` |
| HTML/LaTeX template | `--template template.html` or `--template template.tex` |
| HTML/EPUB CSS | `--css style.css` |
| PDF engine | `--pdf-engine xelatex` |
| Images/resources | `--resource-path .:assets:images` |
| Extract DOCX media | `--extract-media media` |
## Format Notes
Load `references/formats.md` when format support or extension mapping matters.
Load `references/workflows.md` for step-by-step conversion recipes.
Load `references/troubleshooting.md` when a conversion fails.
## Best Practices
- Prefer Markdown plus YAML frontmatter as the source of truth; treat DOCX/PDF/EPUB as generated outputs.
- Validate citations, templates, and resource paths before long conversions.
- For batch conversion, start with a small sample before converting a large directory.
- For PDF, choose the engine explicitly when output quality matters.
- For Word styling, use a Pandoc-generated `reference.docx` as the base for custom styles.
## Common Mistakes
- Running Markdown→PDF without a PDF engine installed.
- Using `pdflatex` for Chinese text; use `xelatex` instead.
- Converting DOCX→Markdown without `--extract-media`, which loses embedded images.
- Forgetting `--resource-path` when Markdown references images in sibling directories.
- Claiming a batch succeeded when only some files converted.
don't have the plugin yet? install it then click "run inline in claude" again.
restructured original into implexa's 6-component format (intent, inputs, procedure with explicit steps and io, decision points with if-else branches, output contract with data formats and locations, outcome signal with success and failure cases), added edge cases (missing pdf engine, auth expiry, empty result sets, network timeouts, output path conflicts), documented all external connections (bibliography, csl, templates, css, resource paths) as inputs, and preserved original author's procedure faithfully while making implicit logic explicit.
use this skill when a user needs to convert documents between formats using pandoc. covers single-file conversions (markdown to docx, html to pdf, etc.), batch directory conversions, pdf engine setup, citation handling, templates, table of contents generation, and troubleshooting. prefer the bundled wrapper scripts because they add dependency checks, safer defaults, progress output, retries, and detailed reports. do not silently install pandoc; report missing dependencies and ask first.
pandoc installation: pandoc binary must be available in PATH. if missing, the skill will report validation error and offer installation help via ${CLAUDE_SKILL_DIR}/scripts/install_pandoc.sh.
pdf engine (conditional): for pdf output, a pdf engine is required. common engines: pdflatex (ascii/latin only), xelatex (unicode, chinese, arabic), lualatex (unicode). for chinese documents, xelatex is preferred. user must install separately; the skill does not install pdf engines.
input file or directory: path to source document(s). single file (e.g. README.md) or directory glob (e.g. docs/*.md). must exist and be readable.
output format: target format (html, docx, pdf, epub, latex, typst, rst, asciidoc, org, odt, rtf, ipynb, or json). inferred from output filename extension or explicitly specified via --to flag.
optional external files (conditional):
refs.bib, .json, or .yaml) for --citeproc citations.csl) for citation formattingreference.docx) for word styling via --reference-doc.html, .tex) via --template.css) for html/epub via --css--resource-pathbash tools: bash shell, python3 (for batch conversion), file operations (glob, grep, find).
environment variable: ${CLAUDE_SKILL_DIR} points to the skill directory containing scripts/ subdirectory.
inputs: user request (file path or directory, desired output format, any special options).
action: check whether this is a single-file or batch conversion. if user says "batch", "directory", "multiple files", or "glob", prepare batch workflow. otherwise, assume single-file workflow.
outputs: confirmed scope (single or batch), input path(s), target format.
inputs: confirmed scope, paths.
action: run validation script to detect pandoc and any missing dependencies.
bash ${CLAUDE_SKILL_DIR}/scripts/validate.sh
if pandoc is missing, show validation error. do not silently install. ask user whether they want installation help and offer the dry-run command:
bash ${CLAUDE_SKILL_DIR}/scripts/install_pandoc.sh
only run with --yes flag after explicit user approval.
if pandoc is present, continue.
outputs: pandoc availability confirmed (or installation guidance offered), list of detected dependencies.
inputs: input file path, requested output format (inferred from user request or filename extension).
action: if output path not specified, suggest default (same directory, same basename, new extension). ask user to confirm or provide explicit path.
gather any special options user mentioned: citations, toc, pdf engine, templates, css, resource paths, extraction of media.
outputs: confirmed input file, confirmed output path, option list.
inputs: input directory, output directory, target format, any special options (retries, fail-fast, continue-on-error, report format).
action: confirm output directory path. ask whether user wants a progress report (markdown or json).
outputs: confirmed input directory, output directory, format, options, report preference.
single-file: execute convert wrapper with confirmed parameters.
bash ${CLAUDE_SKILL_DIR}/scripts/convert.sh <input> -o <output> [--pdf-engine xelatex] [--toc] [--citeproc --bibliography refs.bib --csl style.csl] [other options]
batch: execute python batch wrapper.
python3 ${CLAUDE_SKILL_DIR}/scripts/batch_convert.py <input-dir> --output-dir <output-dir> --to <format> [--pdf-engine xelatex] [--retries 2] [--report report.md] [--json-report report.json]
inputs: input file(s), output path(s), format, all options from step 3a or 3b.
outputs: converted file(s) written to disk, command output showing success/failure, progress (for batch).
inputs: command exit status, output file path(s), error messages (if any).
single-file success: report the output file path. user can open/download immediately.
single-file failure: show the actionable error message from pandoc. suggest the smallest fix (missing dependency, format mismatch, file not found, etc.). offer retry command.
batch success: report summary (X files converted, Y skipped, Z failed). list output directory. if report was generated, note its path.
batch partial failure: never claim full success if any files failed. list failed files with paths. show the error for each failure. provide retry command that re-runs only failed files.
outputs: user-facing result summary, file path(s) or directory, any error details and recovery steps.
single-file vs. batch: if user says "batch", "directory", "glob", "multiple files", or "批量", use batch workflow (step 3b + batch conversion). otherwise use single-file workflow (step 3a + single conversion).
pandoc missing: if validation reports pandoc not found, stop and ask user whether to install. do not proceed with conversion. only install after explicit user approval.
pdf engine missing for pdf output: if user requests pdf output and --pdf-engine not provided, check if xelatex is available (preferred for unicode/chinese). if not available, ask user to install it or specify a fallback engine. do not attempt pdf conversion without a working pdf engine.
output path conflict: if output file already exists, ask user whether to overwrite. do not overwrite silently.
citations requested but bibliography missing: if user asks for citations (--citeproc) but no bibliography file is provided, ask for the file path or confirm that user wants citation processing without a bibliography (which will search for references.bib in the current directory).
template or css requested but file missing: if user specifies --template or --css and the file does not exist, report error and do not attempt conversion.
batch with failures and continue-on-error: if batch conversion has partial failures and --continue-on-error is active, list failed files. do not claim batch succeeded. provide a retry command that converts only the failed subset.
resource paths and relative directories: if conversion references images or assets in sibling directories or parent paths, confirm --resource-path includes those directories. if user does not specify it, infer common paths (., assets, images) and suggest the option.
extract media from docx: if user converts from docx to markdown and does not specify --extract-media, warn that embedded images will be lost. suggest --extract-media media to extract and preserve images.
single-file success: one file written to the confirmed output path. file is valid in the target format. example output paths:
README.docx (docx format)output.pdf (pdf format)index.html (html format)batch success: directory tree created at the output directory path, with converted files preserving relative paths from the input directory.
docs/chapter1/intro.md, output dir: out, target: pdf → output: out/chapter1/intro.pdf.git, node_modules, etc.), and the output directory itself are not processed.batch reports (optional): if --report or --json-report flags provided:
on failure: no file is written. pandoc error message is returned as-is. user receives actionable guidance (missing dependency, format mismatch, invalid option, file not found, network timeout for remote resources, rate-limited citation server, etc.).
user knows the skill worked when:
[3/28] converting docs/a.md -> out/a.pdf in real-time.on failure: user sees the specific error (e.g. "pandoc not found", "xelatex not installed", "input file not found", "bibliography file not found") and a recovery step (install pandoc, install xelatex, check path, provide file).