# 一、Tex Live 与 Latex workshop 安装

Tex Live 可以从官网进行安装, Latex workshopVscode 的插件商城安装
⚠️⚠️⚠️需要注意的是, Latex workshop 插件需安装 8.8.0 版本,更高版本不稳定,会产生 bug

# 二、Tex Live 环境变量配置

在环境变量中添加 D:\texlive\2022\bin\win32 (需更改为自己的 texlive 安装路径)
配置完成后在命令行输入 latex -v ,出现如下信息则判断 latex 安装及配置完成

# 三、Vscode 配置

依次点击 File→Preferences→Settings 打开用户设置
添加一下内容并保存(注:= 以下内容和原本内容公用一个大括号 =)

{
  // 禁止自动编译
  "latex-workshop.latex.autoBuild.run": "never",
  // 不弹出报错、警告窗
  "latex-workshop.message.error.show": false,
  "latex-workshop.message.warning.show": false,
  //pdf 预览
  "latex-workshop.view.pdf.viewer": "tab",
  // 自动删除一些过程文件
  "latex-workshop.latex.autoClean.run": "onBuilt",
  // 指出编译后删除的文件种类
  "latex-workshop.latex.clean.fileTypes":[
    "*.aux",
    "*.bbl",
    "*.blg",
    "*.idx",
    "*.ind",
    "*.lof",
    "*.lot",
    "*.out",
    "*.toc",
    "*.acn",
    "*.acr",
    "*.alg",
    "*.glg",
    "*.glo",
    "*.gls",
    "*.ist",
    "*.fls",
    "*.log",
    "*.fdb_latexmk",
    "*.gz"
    ],
    // 定义编译策略,默认首个,xelatex 支持中文,故放在第一个
    "latex-workshop.latex.recipes": [
      {
        "name": "xelatex",
        "tools": [
          "xelatex"
        ]
      },
      {
        "name": "xelatex -> bibtex -> xelatex*2",
        "tools": [
          "xelatex",
          "bibtex",
          "xelatex",
          "xelatex"
        ]
      }
    ],
    //LaTeX tools
    "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": "bibtex",
        "command": "bibtex",
        "args": [
          "%DOCFILE%"
        ]
      }
    ],
  "latex-preview.command": "xelatex",
  // 自定义 PDF 预览工具,这里使用 SumatraPDF.exe,记得改路径
  "latex-workshop.view.pdf.external.viewer.command":                "G:/R/RStudio/bin/sumatra/SumatraPDF.exe",
  // 前向搜索,后向搜索,记得改文件的路径
  "latex-workshop.view.pdf.external.viewer.args": [
    "-forward-search",
    "%TEX%",
    "%LINE%",
    "-reuse-instance",
    "-inverse-search",
    ""E:/.../Microsoft VS Code/Code.exe" "E:/.../Microsoft VS Code/resources/app/out/cli.js" -gr "%f":"%l"",
    "%PDF%"
  ],
  "latex-workshop.view.pdf.external.synctex.command": "G:/R/RStudio/bin/sumatra/SumatraPDF.exe",
  "latex-workshop.view.pdf.external.synctex.args": [
    "-forward-search",
    "%TEX%",
    "%LINE%",
    "-reuse-instance",
    "-inverse-search",
    "code "E:/.../Microsoft VS Code/resources/app/out/cli.js" -gr "%f":"%l"",
    "%PDF%",
  ]
}

# 四、其他

# 4.1 如何配置 Vscode 的 Settings

参考文章:https://zhuanlan.zhihu.com/p/113222681
新版的 Vscode 设置默认为 UI 的设置,而非之前的 json 设置。如果想复制这段代码进行配置,可以进行如下的修改
File→Preferences→Settings→搜索 workbench.settings.editor ,选中 json 即可改成 json 设置

# 4.2 编译方式的选择

通常编译排版时 = 英文文档 = 选择 PDFLaTeX ,= 中文文档 = 选择 XeLaTeX

更新于 阅读次数