VS Code配置Latex的编译文件(包含Latex与SumatraPDF文档之间的正反向跳转)

1 软件及其版本

  • Texlive 2020
  • Visual Studio Code: 1.48.0,相关扩展插件:LaTex workshop
  • SumatraPDF阅读器:3.2

2 Tex编译配置文件 settings.json

2.1 设置编译器和组合编译(Recipe)方式

\\ 这块是设置组合编译的几种方式,如果有需要可以自己随意组合,只要符合编译规则
"latex-workshop.latex.recipes": [
      {
        "name": "PDFLaTeX",  \\ 使用PDFLatex编译一次
        "tools": [
          "pdflatex"
        ]
      },
      {
        "name": "xelatex",  \\ 使用XeLatex编译一次
        "tools": [
            "xelatex"
        ]
      },

      {
        "name": "bibtex",  \\ 使用BibLatex编译一次
        "tools": [
            "bibtex"
        ]
      },
      {
        "name": "pdflatex x2",  \\ 使用PDFLatex编译两次
        "tools": [
            "pdflatex",
            "pdflatex"
        ]
      },
      {
        "name": "xelatex x2",  \\ 使用XeLatex编译两次
        "tools": [
            "xelatex",
            "xelatex"
        ]
      },
      {
        "name": "pdflatex -> bibtex -> pdflatex x2",  \\ 按照PDFLatex、Bibtex、PDFLatex、PDFLatex的顺序编译,适合含有cite、ref和bib文件的英文文档编译
        "tools": [
            "pdflatex",
            "bibtex",
            "pdflatex",
            "pdflatex"
        ]
      },
      {
        "name": "xelatex -> bibtex -> xelatex x2",  \\ 按照XeLatex、Bibtex、XeLatex、XeLatex的顺序编译,适合含有cite、ref和bib文件的中文文档编译
        "tools": [
          "xelatex",
          "bibtex",
          "xelatex",
          "xelatex"
        ]
      }      
      ],
 \\ 这部分是引入编译器工具,将 PDFLatex、Bibtex、Xelatex编译器引用进来,其它我不需要的没写
  "latex-workshop.latex.tools": [
      {
      "name": "pdflatex",
      "command": "pdflatex",
      "args": [
        "-synctex=1",
        "-interaction=nonstopmode",
        "-file-line-error",
        "%DOCFILE%"
      ]
      }, 
      {
        "name": "xelatex",
        "command": "xelatex",
        "args": [
          "-synctex=1",
          "-interaction=nonstopmode",
          "-file-line-error",
          "%DOCFILE%"
        ]
      }, 
      {
      "name": "bibtex",
      "command": "bibtex",
      "args": [
        "%DOCFILE%"
      ]
      }], 
     

2.2 编译完成自动删除某些中间文件

"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",
    //  "*.gz",  \\ 语法文件,需要保留,其它看自己需求
     "*.ist",
     "*.fls",
     "*.log",
     "*.fdb_latexmk"
    ],    
  \\ 这句是关闭 保存文件后自动编译 的功能
  "latex-workshop.latex.autoBuild.run": "never",

2.3 设置预览文件的方式

预览编译好的文件可以在侧边栏的扩展工具箱自己选,如图,有三种方式:在VS Code里面查看,在浏览器查看,在外部PDF阅读器里查看。

由于要设置正反向跳转,所以需要配置SumatraPDF为外部浏览器:
注意修改安装路径!下同

// 设置外部浏览器为SumatraPDF
    "latex-workshop.view.pdf.viewer":"external",
    "latex-workshop.view.pdf.external.viewer.command": "E:\\Tool_Box_Applications\\SumatraPDF\\SumatraPDF.exe",\\ 注意此处的SumatraPDF的安装路径需要自己修改!
    "latex-workshop.view.pdf.external.viewer.args": [
          "%PDF%"
      ],

配置完成后,可以去VScode键盘快捷方式里面修改一下查看编译好的PDF的快捷键(默认是Ctrl+ALT+V)

2.4 设置VS Code的Tex文档与SumatraPDF跳转

// 设置正反向跳转
    "latex-workshop.view.pdf.external.synctex.command":"E:\\Tool_Box_Applications\\SumatraPDF\\SumatraPDF.exe",
    "latex-workshop.view.pdf.external.synctex.args": [
      "-forward-search",
      "%TEX%",
      "%LINE%",
      "-reuse-instance",
      "-inverse-search",
      "\"E:\\MicroSoft\\Microsoft VS Code\\Code.exe\" \"E:\\MicroSoft\\Microsoft VS Code\\resources\\app\\out\\cli.js\" -g \"%f\":\"%l\"",
      "%PDF%" \\ 注意此处的VS Code的安装路径需要自己修改!而且不能随便增加空格!
    ],    

到此配置文件编写完成。

2.5 跳转方法

  • Tex文档跳转到PDF
    如下图,鼠标放在相应的文档位置后,点击侧边栏的SyncTex from Cursor就会跳转到PDF中去,而且刚开始跳转的时候,PDF对应文本会高亮一秒左右!
    然而点击侧边栏太费事,自己去快捷键设置里面搜索这个SyncTex然后修改为自己习惯的快捷键就很方便了!
  • SumatraPDF跳转到Tex文档
    直接在PDF相关位置双击就可以跳转到VS Code的相关位置了!

3 配置文件总结

    "latex-workshop.latex.recipes": [
      {
        "name": "PDFLaTeX",
        "tools": [
          "pdflatex"
        ]
      },
      {
        "name": "xelatex",
        "tools": [
            "xelatex"
        ]
      },

      {
        "name": "bibtex",
        "tools": [
            "bibtex"
        ]
      },
      {
        "name": "pdflatex x2",
        "tools": [
            "pdflatex",
            "pdflatex"
        ]
      },
      {
        "name": "xelatex x2",
        "tools": [
            "xelatex",
            "xelatex"
        ]
      },
      {
        "name": "pdflatex -> bibtex -> pdflatex x2",
        "tools": [
            "pdflatex",
            "bibtex",
            "pdflatex",
            "pdflatex"
        ]
      },
      {
        "name": "xelatex -> bibtex -> xelatex x2",
        "tools": [
          "xelatex",
          "bibtex",
          "xelatex",
          "xelatex"
        ]
      }      
      ],
      "latex-workshop.latex.tools": [
      {
      "name": "pdflatex",
      "command": "pdflatex",
      "args": [
        "-synctex=1",
        "-interaction=nonstopmode",
        "-file-line-error",
        "%DOCFILE%"
      ]
      }, 
      {
        "name": "xelatex",
        "command": "xelatex",
        "args": [
          "-synctex=1",
          "-interaction=nonstopmode",
          "-file-line-error",
          "%DOCFILE%"
        ]
      }, 
      {
      "name": "bibtex",
      "command": "bibtex",
      "args": [
        "%DOCFILE%"
      ]
      }],
     "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",
    //  "*.gz",
     "*.ist",
     "*.fls",
     "*.log",
     "*.fdb_latexmk"
    ],
    "latex-workshop.latex.autoBuild.run": "never",
    "files.associations": {

    },
    // 设置外部浏览器为SumatraPDF
    "latex-workshop.view.pdf.viewer":"external",
    "latex-workshop.view.pdf.external.viewer.command": "E:\\Tool_Box_Applications\\SumatraPDF\\SumatraPDF.exe",
    "latex-workshop.view.pdf.external.viewer.args": [
          "%PDF%"
      ],

    // 设置正反向跳转
    "latex-workshop.view.pdf.external.synctex.command":"E:\\Tool_Box_Applications\\SumatraPDF\\SumatraPDF.exe",
    "latex-workshop.view.pdf.external.synctex.args": [
      "-forward-search",
      "%TEX%",
      "%LINE%",
      "-reuse-instance",
      "-inverse-search",
      "\"E:\\MicroSoft\\Microsoft VS Code\\Code.exe\" \"E:\\MicroSoft\\Microsoft VS Code\\resources\\app\\out\\cli.js\" -g \"%f\":\"%l\"",
      "%PDF%"
    ],

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值