美文网首页
ubuntu16.04下markdown转pdf文件

ubuntu16.04下markdown转pdf文件

作者: 车到山前必有路2021 | 来源:发表于2019-12-05 11:37 被阅读0次

    安装pandoc工具

    sudo apt-get install pandoc

    安装Miktex

    Miktex https://miktex.org/download

    Pandoc的默认引擎是pdflatex,不支持中文,需要手动设置为XeLatex引擎后方可支持中文。XeLaTeX是一种使用Unicode的LaTeX排版引擎,支持一些现代字体技术,命令下直接使用xelatex *.tex即可生成对应的PDF文件。XeLatex的安装命令如下:

    sudo apt-get install texlive-xetex texlive-latex-extra

    sudo apt-get install latex-cjk-chinese texlive-fonts-recommended

    安装字库

    字库的来源于windows系统"C:\\Windows\\Fonts"

    安装方式:只需要将ttf文件拷贝至"/usr/share/fonts/truetype/markdown-fonts"文件夹中.

    md 转 pdf 命令

    pandoc test.md -o test.pdf --latex-engine=xelatex –V mainfont="黑体"

    关于模板文件

    由此生成的PDF文档虽然支持中文,但是格式不能满足要求,可以通过引入模板文件对生成的PDF文件进行设定,其中模板文件主要解决了如下问题:

             -  页面设置

             -  封面

             -  图片大小适配

             -  中、英文字体设定

             -  代码段设定

             -  页眉页脚设置

             -  标题格式设置,标题自动换页

             -  字体、段落设置

             -  目录自动生成

    与上述相关的内容都可以通过模板文件进行设定,其模板内容通过Latex语法描述,如需改动可查阅Latex语法进行相关的设置。一般情况下,生成PDF文档都会结合模板文件执行:

    目录 /usr/share/pandoc/data/templates/ 下存放默认模板。

    pandoc infile.md -o outfile.pdf --toc --smart --template=Templates/pm-template.latex --latex-engine=xelatex

    示例模板文件:
    https://github.com/tzengyuxio/pages/blob/gh-pages/pandoc/pm-template.latex

    有时会突然出现错误(之前明明能用),先卸载再安装Miktex。

    sudo apt-get autoremove miktex

    sudo apt-get install miktex

    相关文章

      网友评论

          本文标题:ubuntu16.04下markdown转pdf文件

          本文链接:https://www.haomeiwen.com/subject/jbrdgctx.html