可能大家在使用Latex时使用的编辑器器是texstudio。在本文中,将讲解在VScode中配置latex环境。VScode本质还是一个文本编辑器。
1、整体配置过程
(1)安装VScode并完成相关扩展的安装。
2、详细配置过程
2.1、Latex编译器安装
VScode只是一个编辑器,只能用它完成Latex代码的编写。为了实现将编写的Latex代码转化为具体的文章排版还需要安装一个编译工具(可以理解成一个转换工具:将Latex代码转化具体的文章排版),Tex live和MikTex都是Latex的编译器,安装其中一个就可以。本文安装的是Tex live。
Tex live具体安装过程可参考文章:http://t.csdn.cn/ezGfZ
2.2、VScode安装与扩展安装
(1)VScode安装
在VScode官网下载与自己电脑匹配的本进行安装即可。
VScode下载地址:https://code.visualstudio.com/
(2)VScode中latex扩展的安装
打开VScode ——> 点击扩展栏,并在搜索框中搜索latex ——> 找到Latex workshop进行安装
安装完成后,在扩展栏的已安装中能看到安装好的Latex workshop
2.3、在VScode中添加设置
(1)按下F1或者Ctrl+Shift+p,在搜索框中输入json。
(2)选择Preferences:Open User Setting,有的可能是Preferences:Open Setting,然后出现如下界面
(3)在花括号中输入下面的配置代码,输入完成保存即可。
"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.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.latex.clean.fileTypes": [
"*.aux",
"*.bbl",
"*.blg",
"*.idx",
"*.ind",
"*.lof",
"*.lot",
"*.out",
"*.toc",
"*.acn",
"*.acr",
"*.alg",
"*.glg",
"*.glo",
"*.gls",
"*.ist",
"*.fls",
"*.log",
"*.fdb_latexmk"
],
//tex文件浏览器,可选项为"none" "browser" "tab" "external"
"latex-workshop.view.pdf.viewer": "tab",
//自动编译tex文件
"latex-workshop.latex.autoBuild.run": "onFileChange",
//显示内容菜单:(1)编译文件;(2)定位游标
"latex-workshop.showContextMenu": true,
//显示错误
"latex-workshop.message.error.show": false,
//显示警告
"latex-workshop.message.warning.show": false,
//从使用的包中自动补全命令和环境
"latex-workshop.intellisense.package.enabled": true,
//设置为never,为不清除辅助文件
"latex-workshop.latex.autoClean.run": "never",
//设置vscode编译tex文档时的默认编译链
"latex-workshop.latex.recipe.default": "lastUsed",
// 用于反向同步的内部查看器的键绑定。ctrl/cmd +点击(默认)或双击
"latex-workshop.view.pdf.internal.synctex.keybinding": "double-click",
3、测试
下载一个Latex的模板,然后将.tex后缀文件用VScode打开。可以之家将.tex文件之间拖拽到VScode里来打开文件。然后点击编译和查看,看是否配置成功。
也可以在下图中的点击相应位置进行编译查看