首页/手册
Pandoc 手册:二十几个参数覆盖九成用法
官方手册有上百个参数,日常真正用到的不到三十个。这一页按「你要干什么」分组,不按字母顺序。
一、输入输出:先定两端
| 参数 | 全写 | 作用 |
|---|---|---|
| -f | --from | 指定输入格式,可带扩展开关 |
| -t | --to | 指定输出格式 |
| -o | --output | 输出到文件;不写则打到 stdout |
| -s | --standalone | 生成完整文档(带 head、模板骨架) |
| — | --list-input-formats | 列出全部可读格式 |
| — | --list-output-formats | 列出全部可写格式 |
| — | --list-extensions=markdown | 列出某格式的扩展开关 |
pandoc a.md -f markdown+footnotes -t html5 -s -o a.html
二、排版与模板
| 参数 | 作用 | 用于 |
|---|---|---|
| --template | 换整套骨架 | HTML、LaTeX、reveal.js、typst |
| --reference-doc | 照抄样式定义 | docx、odt、pptx |
| -V, --variable | 给模板传变量 | 字号、颜色、字体、页边距 |
| --css | 附加样式表 | HTML、EPUB |
| --highlight-style | 代码高亮主题 | HTML、LaTeX、docx |
| --print-default-template=latex | 导出默认模板 | 准备自己改模板时 |
# 把默认 LaTeX 模板导出来改 pandoc --print-default-template=latex > my.tex # 用改过的模板 pandoc note.md --template=my.tex -o note.pdf
三、内容处理
| 参数 | 作用 |
|---|---|
| --extract-media=DIR | 导出内嵌图片到目录 |
| --resource-path=DIRS | 图片与资源的搜索路径 |
| --toc --toc-depth=N | 生成目录,控制到几级标题 |
| -N, --number-sections | 章节自动编号 |
| --shift-heading-level-by=N | 整体升降标题层级 |
| --embed-resources | 把 CSS 与图片内联进单个文件 |
| --wrap=none | 不自动折行,适合版本管理 |
| --lua-filter=FILE | 用 Lua 脚本改写 AST |
| --filter=CMD | 调用外部程序做 JSON 过滤器 |
pandoc doc.md --toc --toc-depth=2 -N --embed-resources \ --css=print.css -s -o doc.html
注意
--self-contained 是旧名字,3.x 起推荐用 --embed-resources。老脚本还能跑,但新写的别再用旧名。
四、元数据与配置
| 参数 | 作用 |
|---|---|
| -M, --metadata | 命令行设一个元数据字段 |
| --metadata-file | 从 YAML 文件读元数据 |
| -d, --defaults | 加载 defaults 文件,固化参数 |
| --data-dir | 指定数据目录(模板、样式) |
| PANDOC_DATA_DIRS | 环境变量,追加数据目录(3.14 新增) |
pandoc a.md -M title="2026 年度报告" -M lang=zh-CN -s -o a.html
元数据字段名用官方约定的(title、author、date、lang、abstract、keywords),模板里才能直接引用。
五、PDF 与引用
| 参数 | 作用 |
|---|---|
| --pdf-engine=NAME | 选排版引擎:xelatex / lualatex / typst / wkhtmltopdf / weasyprint / context |
| --pdf-engine-opt=OPT | 往引擎命令行追加参数 |
| --citeproc | 启用文献处理 |
| --bibliography=FILE | 指定 .bib 或 CSL JSON |
| --csl=FILE | 指定引用样式(如 GB/T 7714) |
pandoc paper.md --citeproc --bibliography=refs.bib \ --csl=china-national-standard-gb-t-7714-2015.csl \ --pdf-engine=xelatex -o paper.pdf