TexLive_installation

Posted on Jul 11, 2019

TexLive + VScode 搭建LaTex编译环境

最近对LaTex十分感兴趣(因为好看),百度了很多教程,最后决定在VScode上配置环境。

  1. 下载TexLive镜像文件(清华大学镜像),选择texlive2019.iso下载即可;

  2. iso文件解压后,在文件夹中点击install-tl-advanced.bat或install-tl-windows.bat文件均可,其中可进行一些安装地址和组件的配置,安装时间较长;

  3. 在VScode中安装插件:LaTex language support, LaTex Workshop

  4. 对latex编译环境进行配置:在设置中搜索latex,对setting.json进行编辑,加入以下代码段:

    "latex-workshop.latex.tools": [
            {
                "name": "latexmk",
                "command": "latexmk",
                "args": [
                    "-synctex=1",
                    "-interaction=nonstopmode",
                    "-file-line-error",
                    "-pdf",
                    "%DOC%"
                ]
            },
            {
                "name": "xelatex",
                "command": "xelatex",
                "args": [
                    "-synctex=1",
                    "-interaction=nonstopmode",
                    "-file-line-error",
                    "%DOC%"
                ]
            },
            {
                "name": "pdflatex",
                "command": "pdflatex",
                "args": [
                    "-synctex=1",
                    "-interaction=nonstopmode",
                    "-file-line-error",
                    "%DOC%"
                ]
            },
            {
                "name": "bibtex",
                "command": "bibtex",
                "args": [
                    "%DOCFILE%"
                ]
            }
        ],
        "latex-workshop.latex.recipes": [
            {
                "name": "xelatex",
                "tools": [
                    "xelatex"
                ]
            },
            {
                "name": "pdflatex",
                "tools": [
                    "pdflatex"
                ]
            },
            {
                "name": "latexmk",
                "tools": [
                    "latexmk"
                ]
            },
            {
                "name": "pdflatex -> bibtex -> pdflatex*2",
                "tools": [
                    "pdflatex",
                    "bibtex",
                    "pdflatex",
                    "pdflatex"
                ]
            }
        ],
        "latex-workshop.view.pdf.viewer": "tab",
        "latex-workshop.latex.clean.subfolder.enabled": true //这里要选择true清除编译过程中产生的文件
    
  5. 创建文件test.tex,Ctrl+S保存编译,得到PDF文件。

    \documentclass[UTF8]{ctexart}
        \title{TexLive + VScode 环境配置}
        \author{Silhouettes}
        \date{\today}
        \begin{document}
        \maketitle
        This is the beginning of the article.\\
    
        编译成功!\\
    
        $ {f}'(0) =  \left. \frac{df}{dx} \right|_{x=0} $
    \end{document}
    

    这里要注意tex文件要按utf-8编码,如果编译后出现乱码,可以更换编码方式重新保存后再编译一次。