参考pandoc转pdf文件用的latex模板介绍(Linux环境)
错误
Error: Command failed: pandoc -f markdown+tex_math_single_backslash
Error producing PDF.
! Package inputenc Error: Unicode character 的 (U+7684)
(inputenc) not set up for use with LaTeX.
See the inputenc package documentation for explanation.
Type H for immediate help.
Try running pandoc with —pdf-engine=xelatex.
解决方法
pdflatex,是不支持中文的,因此需要手动设置编译时所用的引擎为xelatex
安装xelatex
sudo apt-get install texlive-xetex
编译命令改为:
pandoc i.md -o o.pdf --pdf-engine=xelatex"
这时就能够成功了但打开pdf会发现没有中文, 还要设置编译的时候的字体
1 | pandoc i.md -o o.pdf --pdf-engine=xelatex -V mainfont="Noto Sans CJK SC" #这里我使用了思源字体 |
更好的方法
使用Latex模板
模板的话去网上找别人的来用一下就好
我用的是
pm-template
把下载下来的pm-template.latex放在$HOME/Templates/下(个人习惯)
pandoc i.md -o o.pdf --pdf-engine=xelatex --template=$HOME/Templates/pm-template.latex
这样就完美了, 但是我还是踩了坑
1 | 报错kpathsea:make_tex: Invalid filename `LiHei Pro/OT', contains ' ' |
eisvogel.tex 模板
1 | ! LaTeX Error: File `sourcesanspro.sty' not found. |
上述模板的作者貌似不是亚洲人,他的模板默认使用的字体是 Source Sans Pro 字体,这个字体文件里没有 CJK 字符的画法。为了让这个模板默认使用我们安装的 Noto Serif SC 字体,我们需要编辑一下 ~/.local/share/pandoc/templates/eisvogel.latex 。我的版本里,我在 \else % if not pdftex 这一行后面加了三行,使其看上去是这个样子。
1 | \else % if not pdftex |
我用的是Noto Sans CJK SC