VSCode下实现LaTeX的环境配置

tech2025-11-01  7

VSCode下实现LaTeX的环境配置

准备工作

Texlive: http://tug.org/texlive/Visual Studio Code: https://code.visualstudio.com/SumatraPDF: https://www.sumatrapdfreader.org/free-pdf-reader.html

下载对应安装包并安装,注意安装Texlive的时候建议不选择安装Texlive前端。还可以在高级选项中自由选择安装需要的宏包。VsCode和SumatraPDF傻瓜式安装便可。

VsCode下载Latex插件——LaTeX workshop

在安装完毕后界面并不会出现什么变化,但是当我们创建一个tex文件的时候,VsCode左栏便会出现一个TEX的按钮,如下图 注意:然而这个插件的默认状态是不能编译中文的,当我们使用ctex宏包的时候,会发现没有xelatex这个功能,这需要我们自己进行手动配置。

配置

对VsCode的settings.json文件进行文本编辑,添加以下代码(注意自行修改内容)。

{ "latex-workshop.latex.autoBuild.run": "never", "latex-workshop.showContextMenu": true, "latex-workshop.intellisense.package.enabled": true, "latex-workshop.message.error.show": false, "latex-workshop.message.warning.show": false, "latex-workshop.latex.tools": [ { "name": "xelatex", "command": "xelatex", "args": [ "-synctex=1", "-interaction=nonstopmode", "-file-line-error", "%DOCFILE%" ] }, { "name": "pdflatex", "command": "pdflatex", "args": [ "-synctex=1", "-interaction=nonstopmode", "-file-line-error", "%DOCFILE%" ] }, { "name": "latexmk", "command": "latexmk", "args": [ "-synctex=1", "-interaction=nonstopmode", "-file-line-error", "-pdf", "-outdir=%OUTDIR%", "%DOCFILE%" ] }, { "name": "bibtex", "command": "bibtex", "args": [ "%DOCFILE%" ] } ], "latex-workshop.latex.recipes": [ { "name": "XeLaTeX", "tools": [ "xelatex" ] }, { "name": "PDFLaTeX", "tools": [ "pdflatex" ] }, { "name": "BibTeX", "tools": [ "bibtex" ] }, { "name": "LaTeXmk", "tools": [ "latexmk" ] }, { "name": "xelatex -> bibtex -> xelatex*2", "tools": [ "xelatex", "bibtex", "xelatex", "xelatex" ] }, { "name": "pdflatex -> bibtex -> pdflatex*2", "tools": [ "pdflatex", "bibtex", "pdflatex", "pdflatex" ] }, ], "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" ], "latex-workshop.latex.autoClean.run": "onFailed", "latex-workshop.latex.recipe.default": "lastUsed", "latex-workshop.view.pdf.internal.synctex.keybinding": "double-click", "latex-workshop.view.pdf.viewer": "external", "latex-workshop.view.pdf.ref.viewer":"auto", "latex-workshop.view.pdf.external.viewer.command": "E:/SumatraPDF/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\" -r -g \"%f:%l\"", "%PDF%" ], "latex-workshop.view.pdf.external.synctex.command": "E:/SumatraPDF/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\" -r -g \"%f:%l\"", "%PDF%" ] }

小试牛刀

基本使用图片中的这些,先编译生成pdf文件,再进行查看,使用外部pdf就是之前安装的SumatraPDF,这个软件很轻量级,十分适合用于pdf文件阅读,还可以进行正向和逆向的搜索,从而更高效率进行纠错。

总结

相比于TexStudio等软件,在VsCode配置latex环境更加便捷,编译也比较快,但是TexStudio毕竟比较专业,有很多功能是VsCode下不具备的,就比如公式的预编译,可以在不进行全文编译的情况下对一个公式直接进行编译,从而有更高的效率。个人介意写小文章使用轻量级VsCode,长篇文章使用专业级软件。当然还是得根据自身喜好。
最新回复(0)