引言
利用pandoc转换Markdown为pdf,其实官方给出了解决方法,在Windows上cmd我的命令为:
pandoc srs.md -o srs.pdf --pdf-engine=xelatex -V mainfont=‘SimSun’
出现了warning, pdf也没有输出出来
[WARNING] Missing character: There is no 鍒?pandoc.exe: : hPutChar: invalid argument (Invalid argument)
解决方式
其实官方已经对这个问题给出了解答:
1.Use the following command to produce your pdf file (reference here):
pandoc srs.md -o srs.pdf --pdf-engine=xelatex -V CJKmainfont=KaiTi
2.Add the following setting to your markdown file
---
CJKmainfont: KaiTi
---Then use
pandoc --pdf-engine=xelatex test.md -o test1.pdf
to generate the pdf file.
3.You can use ctexart class and do not need to manually designate a font (the package will do it for you). Add the following setting to
your markdown file
--- documentclass:
- ctexart
---The pdf-generating command is the same as second way.
其他注意事项
1.查看电脑安装了拿些中文字体,在命令行窗口输入:
fc-list :lang=zh
2.如果中文字体有空格,字体还要用双引号引起来,比如:
pandoc srs.md -o srs.pdf --pdf-engine=xelatex -V CJKmainfont=‘Microsoft YaHei’
3.中文字体也可以直接输中文,同样用引号引起来,比如
pandoc srs.md -o srs.pdf --pdf-engine=xelatex -V CJKmainfont=‘微软雅黑’
4.既设置中文(用)又设置英文
pandoc srs.md -o srs.pdf --pdf-engine=xelatex -V CJKmainfont=‘微软雅黑’ -V mainfont=‘Times New Roman’
其他参考
[1]纯文本做笔记 — 使用 Pandoc 把 Markdown 转为 PDF 文件
[2]使用 Pandoc 实现 Markdown 文件转 PDF 文件