安装
windows
1
| winget install JohnMacFarlane.Pandoc
|
linux
1 2
| sudo apt update sudo apt install pandoc
|
验证:pandoc --version
基础转换
1 2 3 4 5 6
| pandoc input.docx -o output.md
pandoc input.docx --extract-media=./images -o output.md
for file in *.docx; do pandoc "$file" --extract-media="./${file%.docx}_images" -o "${file%.docx}.md"; done
|
高级转换
一篇教程
从模板库中clone一个模板仓库:
1
| git clone https://github.com/Wandmalfarbe/pandoc-latex-template.git
|
按照README写好markdown文件后执行转换命令:
1
| pandoc "document.md" -o "document.pdf" --from markdown --template "../../dist/eisvogel.latex" --syntax-highlighting idiomatic --pdf-engine "xelatex" -V CJKmainfont="SimSun"
|
循环转换命令(windows):
1 2 3 4 5 6 7 8 9 10 11 12 13
| chcp 65001 | Out-Null Set-Location $PSScriptRoot Get-ChildItem -Path "./src" -Filter "*.md" | ForEach-Object { $inputFile = $_.FullName $outputFile = Join-Path "./build" ($_.BaseName + ".pdf") pandoc $inputFile ` -o $outputFile ` --from markdown ` --template "./resources/latex/eisvogel.latex" ` --syntax-highlighting idiomatic ` --pdf-engine "xelatex" ` -V CJKmainfont="SimSun" }
|
示例markdown:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| --- title: "标题" author: [你的名字] date: "2026-09-12" subject: "Markdown" keywords: [关键词, markdown] subtitle: "副标题" titlepage: true, titlepage-rule-color: "360049" titlepage-background: "绝对路径" page-background: "绝对路径" ---
## 二级标题
正文
|