在Ubuntu上搭建pandoc和textlive完整教程

2023年 8月 26日 82.7k 0

环境

ubuntu 18.04

简要介绍

pandoc是一个文档格式转换软件,可以将我们常见的TXT、DOC、PDF等格式互相转换。

textlive是LaTex的发行版,而LaTex是文案排版系统,通过pandoc进行文件格式转换时需要使用到Latex。

软件安装

在ubuntu上可以通过sudo apt-get install pandocsudo apt-get install textlive安装。但是通过这种方式安装的是pandoc和textlive的低版本。这里我们通过手动下载软件包进行安装。

  • 如果已经安装了老版本则卸载老版本的安装包 ,卸载pandoc:sudo apt-get purge pandoc ,卸载textlive:sudo apt-get purge textlive
  • 安装pandoc,打开pandoc.org/installing.… ,找到Linux条目,在Linux条目中找到download page这个文字链接,然后找到对应平台的安装版本,我当前安装的是pandoc-3.1.6.2-1-amd64.deb. 下载完成之后,通过sudo dpkg -i pandoc-3.1.6.2-1-amd64.deb安装。
  • 安装textlive,打开www.tug.org/texlive/qui… ,找到Unix(ish)条目,按照文档安装即可。
    这里有一个注意事项,通过perl ./install-tl --no-interaction是安装的完整版本,会下载7个G的文件,所以在执行到这一步时最好使用perl ./install-tl --no-interaction --scheme=small安装最小版。
  • cd /tmp # working directory of your choice
  • wget mirror.ctan.org/systems/tex… # or curl instead of wget
  • zcat < install-tl-unx.tar.gz | tar xf -
  • cd install-tl-*
  • perl ./install-tl --no-interaction # as root or with writable destination
  • Finally, prepend /usr/local/texlive/YYYY/bin/PLATFORM to your PATH,
    e.g., /usr/local/texlive/2023/bin/x86_64-linux
  • Changing defaults:

    • The default paper size is a4. If you want the default to be letter, add --paper=letter to the install-tl command.

    • By default, everything is installed (7+GB).

      • To install a smaller scheme, pass --scheme=scheme to install-tl. For example, --scheme=small corresponds to the BasicTeX variant of MacTeX.
      • To omit installation of the documentation resp. source files, pass --no-doc-install --no-src-install to install-tl.
    • To change the main installation directories (rarely needed), add --texdir=/install/dir to the install-tl command. To change the location of the per-user directories (where TEXMFHOME and others will be found), specify --texuserdir=/your/dir.

    • To change anything and everything else, omit the --no-interaction. Then you are dropped into an interactive installation menu.

    遇到错误的解决方式

    以上的流程走完就可以使用pandoc进行文件格式转换了。具体的指令操作参考pandoc文档.

    • latex Unicode char \u8:产 not set up for use with LaTeX ,遇到这个问题则需要在使用pandoc指令时指定中文字体名称。pandoc --pdf-engine=xelatex -V CJKmainfont='SimSun' test.md -o test.pdf ,‘SimSun’是ubuntu上已经安装的中文字体名称,可以通过运行 fc-list :lang=zh-cn命令查看当前机器上支持的中文字体。如果不能找到安装的中文字体则需要手动安装。
    • LaTeX Error: File 'iftex.sty' not found ,这个问题通过sudo apt-get install texlive-iftex来解决。
    • LaTeX Error: File 'xeCJK.sty' not found ,这个问题需要通过sudo tlmgr install xecjk来解决,xeCJK是一个宏文件,tlmgr是textlive的一个工具,在配置好PATH之后即可使用,可以通过tlmgr install来安装缺少的宏文件。在安装的时候有个小坑,如果提示的是xeCJK.sty,但是实际安装用的指令是小写的xecjk,这里是有大小写区分的。
      如果不确定缺少的文件是否是宏文件,可以通过这个站点先进行查找,确定宏包的名称。在这个宏包的站点进行搜索有个搜索技巧,比如说搜索xeCJK,则使用xeCJK*

    参考网站

    • 安装字体
    • pandoc的使用
    • pandoc官网
    • latex官网
    • textlive官网

    相关文章

    服务器端口转发,带你了解服务器端口转发
    服务器开放端口,服务器开放端口的步骤
    产品推荐:7月受欢迎AI容器镜像来了,有Qwen系列大模型镜像
    如何使用 WinGet 下载 Microsoft Store 应用
    百度搜索:蓝易云 – 熟悉ubuntu apt-get命令详解
    百度搜索:蓝易云 – 域名解析成功但ping不通解决方案

    发布评论