less than 1 minute read

将 markdown 文件转换为 pdf 文件时,中文字符无法显示,这是因为 pandoc 默认使用的字体不支持中文字符。解决方法是使用支持中文字符的字体。

解决方法

使用xelatex引擎,指定字体为PingFang SC

Homebrew 安装xelatex

brew install texlive

使用xelatex引擎

pandoc SAMPLE.md -o SAMPLE.pdf --pdf-engine=xelatex

这样就可以将 markdown 文件转换为 pdf 文件,但由于缺少字体,中文字符还是无法显示

指定字体

pandoc SAMPLE.md -o SAMPLE.pdf --pdf-engine=xelatex -V mainfont="PingFang SC"