vscode配置latex环境
- 1.安装LaTeX Workshop插件
- 2.配置环境
- 附录
1.安装LaTeX Workshop插件
2.配置环境
- 按照下图进行操作:
- 在打开的
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": "tab"
-
加完后的
settings.json
如下所示:
-
加按下图所示编译运行即可:
附录
.json代码详解
//never:手动编译文档 onSave:代码保存时自动编译文档 onFileChange:代码被更改就自动编译文档"latex-workshop.latex.autoBuild.run": "never",//true:启用编译文档的右键菜单 false:关闭编译文档的右键菜单"latex-workshop.showContextMenu": true,//true:代码自动补全 false:关闭代码自动补全"latex-workshop.intellisense.package.enabled": true,//true:编译错误时弹出错误弹窗 false:编译错误时不弹出错误弹窗"latex-workshop.message.error.show": false,//true:弹出警告弹窗 false:不弹出警告弹窗"latex-workshop.message.warning.show": false,//以下代码是在下文中recipes编译链中所使用的编译命令,保持默认即可;其中的%DOCFILE可更改为%DOC//%DOCFILE代表文件所在路径可以包含中文,%DOC表面文件路径不能包含中文"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%"]}],//以下代码是对编译链进行定义,也就是工具栏中出现的链名称//PDFLaTeX 使用的是TeX的标准字体,会对非TeX 标准字体进行替换;//XeLaTeX 允许用户使用操作系统字体来代替 TeX 的标准字体; //PDFLaTeX 的编译的速度较XeLaTeX 快;//编译链是为了方便编译,若设计到.bib文件,就需要用不同的编译命令,而编译链可以方便的解决该问题"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"],//never : 永不清除辅助文件 onFailed : 编译失败时清除辅助文件 onBuilt : 无论是否编译成功均清除辅助文件"latex-workshop.latex.autoClean.run": "onFailed",//选择默认的编译链 //first:采用latex-workshop.latex.recipes中的第一条编译链//lastUsed:采用最近一次的编译链"latex-workshop.latex.recipe.default": "lastUsed",//用于点击pdf文件的指定位置即可跳转到tex文件中代码对应的位置//ctrl-click:Ctrl+鼠标左键单击//double-click:鼠标左键双击"latex-workshop.view.pdf.internal.synctex.keybinding": "double-click",//browser:外置浏览器显示PDF//tab:vscode内置浏览器显示PDF"latex-workshop.view.pdf.viewer": "tab"