天天看点

VS Code + LaTeX Workshop + SumatraPDF<实用的LaTeX编辑方式>

1. Visual Studio Code

2. LaTeX Workshop Github地址 https://link.zhihu.com/?target=https%3A//github.com/James-Yu/LaTeX-Workshop

安装过程:

  1. 使用VSCode编写LaTeX - Marvey的文章 - 知乎
  2. VS Code和LaTeX Workshop一直在迭代更新,所以部分配置可能会有差别。比如配置Sumatra的部分已经有了新的变化,参见官方文档 (James-Yu/LaTeX-Workshop) :

    所以正反向搜索代码应该修改如下(截至到2021.5.2):

"latex-workshop.view.pdf.viewer": "external",//如果前面已经有了,这行代码就删掉
"latex-workshop.view.pdf.external.synctex.command": "D:/Software/SumatraPDF/SumatraPDF.exe",
"latex-workshop.view.pdf.external.synctex.args": [
    "-forward-search",
    "%TEX%",
    "%LINE%",
    "-reuse-instance",
    "-inverse-search",
    "Code.exe \"D:\\Software\\Vscode\\Microsoft VS Code\\resources\\app\\out\\cli.js\" -r -g \"%f:%l\"",
    "%PDF%",
],
           

还可以补上以下代码以清除中间文件,

"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"
    ],
           

最终完整代码如下:

{
    "latex-workshop.latex.tools": [
    {
// 编译工具和命令
"name": "xelatex",
"command": "xelatex",
"args": 
["-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"%DOCFILE%"
        ]
    },
    {
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOCFILE%"
        ]
    },
    {
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
        ]
    }
],
"latex-workshop.latex.recipes": [
  {
"name": "xelatex",
"tools": [
"xelatex"
      ],
  },
  {
"name": "pdflatex",
"tools": [
"pdflatex"
      ]
  },
  {
"name": "xe->bib->xe->xe",
"tools": [
"xelatex",
"bibtex",
"xelatex",
"xelatex"
      ]
  },
  {
"name": "pdf->bib->pdf->pdf",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
      ]
  }
],
"latex-workshop.view.pdf.viewer": "external",
"latex-workshop.view.pdf.external.viewer.command": "D:/Software/SumatraPDF/SumatraPDF.exe",
"latex-workshop.view.pdf.external.viewer.args": [
"-forward-search",
"%TEX%",
"%LINE%",
"-reuse-instance",
"-inverse-search",
"\"D:/Software/Vscode/Microsoft VS Code/Code.exe\" \"D:/Software/Vscode/Microsoft VS Code/resources/app/out/cli.js\" -gr \"%f\":\"%l\"",
    "%PDF%"
],

"latex-workshop.view.pdf.external.synctex.command": "D:/Software/SumatraPDF/SumatraPDF.exe",
"latex-workshop.view.pdf.external.synctex.args": [
    "-forward-search",
    "%TEX%",
    "%LINE%",
    "-reuse-instance",
    "-inverse-search",
    "Code.exe \"D:\\Software\\Vscode\\Microsoft VS Code\\resources\\app\\out\\cli.js\" -r -g \"%f:%l\"",
    "%PDF%",
],
"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"
    ],
}