花了点儿时间玩 Pandoc,将一些 Markdown 文档转换为 PDF 文档。
首先参考[官方文档](https://pandoc.org/installing.html)在 Mac OS 上安装了 Pandoc:
> You can install pandoc using homebrew: `brew install pandoc`.
>
> There is a package installer at pandoc’s download page. If you later want to uninstall the package, you can do so by downloading this script and running it with perl uninstall-pandoc.pl.
>
> We also provide a zip file containing the binaries and man pages, for those who prefer not to use the installer. Simply unzip the file and move the binaries and man pages to whatever directory you like.
>
> For PDF output, you’ll also need LaTeX. Because a full MacTeX installation takes more than a gigabyte of disk space, we recommend installing BasicTeX (64M) and using the tlmgr tool to install additional packages as needed. If you get errors warning of fonts not found, try `tlmgr install collection-fontsrecommended`
安装了 BasicTex 之后一直在 Apps 里寻找 `LaTex` 或是 `BasicTex` 这样的应用,但是一无所获(?!)
后来跑到 MacTex 读了 [BasicTex 的文档](http://tug.org/mactex/morepackages.html) 发现它将文件安装后会将 `/bin` 路径通过 `/etc/paths.d` 添加到命令行的搜索路径中。但奇怪的是 bash 没问题可是我的 zsh 却完全找不到 `/Library/Tex/texbin`…… 后来发现这貌似是 oh-my-zsh 的[一个坑](https://github.com/robbyrussell/oh-my-zsh/issues/3960)。
没办法只好切换到 bash 继续。参考 [别的文档](https://afoo.me/posts/2013-07-10-how-to-transform-chinese-pdf-with-pandoc.html) 用 `tlmgr` 安装了这么几个包:
tlmgr install collection-fontsrecommended
tlmgr install titling lastpage
又从 GitHub 上借用了 [他人提供的](https://github.com/tzengyuxio/pages) 现成的 `pm-template.latex` 作为转换时的模板。对其略微做了修改,用了本地的字体(当然是可以支持中文)以及补充了一两个packge。
最后,以下命令可以成功执行:
pandoc text-all.mkd \
--pdf-engine=xelatex \
--template=pm-template \
-o sample-notes.pdf
附上一些参考资料:
+ [纯文本做笔记 --- 使用 Pandoc 与 Markdown 实践](https://jdhao.github.io/2017/12/10/pandoc-markdown-with-chinese/)
+ [神器Pandoc的安装与使用](http://zhouyichu.com/misc/Pandoc/)
+ [神器Pandoc的安装与使用](http://liumh.com/2014/07/18/pandoc-convert-chinese-pdf/)
+ [Error: tightlist - converting .md file into .pdf using pandoc](https://tex.stackexchange.com/questions/257418/error-tightlist-converting-md-file-into-pdf-using-pandoc)
评论