文档转换界的瑞士军刀之pandoc简介
本文首发于我的博客,更多精彩内容请移步Brayn的博客
最近在研究怎样优雅地写毕业论文,无意间看到了pandoc配合markdown完成论文排版的文章,很有趣,故此分享在这里。
简介
Pandoc是一款能够高质量转换文档格式的本地转换工具,其支持的语言十分丰富,而且转换后能够保持格式的完整性。
根据官方介绍,其支持的文档转换格式有:
FROM
Markdown, reStructuredText, textile, HTML, DocBook, LaTeX, MediaWiki markup, TWiki markup, TikiWiki markup, Creole 1.0, Vimwiki markup, roff man, OPML, Emacs Org-Mode, Emacs Muse, txt2tags, Microsoft Word docx, LibreOffice ODT, EPUB, or Haddock markup
TO
-
HTML formats
XHTML, HTML5, and HTML slide shows using Slidy, reveal.js, Slideous, S5, or DZSlides -
Word processor formats
Microsoft Word docx, OpenOffice/LibreOffice ODT, OpenDocument XML, Microsoft PowerPoint. -
Ebooks
EPUB version 2 or 3, FictionBook2 -
Documentation formats
DocBook version 4 or 5, TEI Simple, GNU TexInfo, roff man, roff ms, Haddock markup -
Archival formats
JATS -
Page layout formats
InDesign ICML -
Outline formats
OPML -
TeX formats
LaTeX, ConTeXt, LaTeX Beamer slides -
PDF
via pdflatex, xelatex, lualatex, pdfroff, wkhtml2pdf, prince, or weasyprint. -
Lightweight markup formats
Markdown (including CommonMark and GitHub-flavored Markdown), reStructuredText, AsciiDoc, Emacs Org-Mode, Emacs Muse, Textile, txt2tags, MediaWiki markup, DokuWiki markup, TikiWiki markup, TWiki markup, Vimwiki markup, and ZimWiki markup. -
Custom formats
custom writers can be written in lua.
我们经常使用的文档格式已着重标出。需要注意的是,转换到pdf格式需要LaTeX引擎的支持,而且由于pdf格式的特殊性,不能从pdf格式转出。
以下图片引起极度舒适,请小心食用。

安装
简单粗暴的方法
命令行方式
- Windows + chocolatey
#安装主程序
choco install pandoc
#安装相关依赖包
choco install rsvg-convert python miktex
- Mac + homebrew
#安装homebrew
#强烈推荐,已安装则跳过此步
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
#安装主程序
brew install pandoc
#安装论文引用插件
brew install pandoc-citeproc
#安装LaTeX支持
brew install librsvg python homebrew/cask/basictex
使用
- 在Mac终端 / Windows命令提示行窗口使用
cd
命令定位到目标文件所在文件夹
pandoc演示
- 输入
pandoc [optional] input.txt -o output.docx
[optional]
部分是可选命令,能引入插件实现更多功能。
input.txt
是待转换文件
output.docx
是欲转换的格式,名字可以自定义。
转换命令
实例
- 首先是我的md文档,包含大量的公式(基本的文字由于不能显示pandoc的强大就没有展示了)

- 这是基于md编译形成的pdf文档

- 最后这是转换形成的word文档
