Home>Article>Development Tools> (Super detailed) How to configure latex in vscode

(Super detailed) How to configure latex in vscode

青灯夜游
青灯夜游 forward
2022-12-06 20:29:14 8110browse

How to configure latex in VScode? The following article will introduce to you how to configure latex inVScode(super detailed). I hope it will be helpful to you!

(Super detailed) How to configure latex in vscode

[Recommended learning:vscode tutorial,Programming video

I have been using texstudio to write before Thesis, but I think the UI of texstudio is not good-looking. In addition, during actual use, I have never used the functions in the toolbar of texstudio. Simply writing tex documents is enough, so I consider using a good-looking one. And it is a relatively lightweight document editor, so vscode came into my sight.

After some configuration, I successfully adjusted the tex writing environment in vscode. My personal experience is similar to that of texstudio, but the appearance is better and I am happier to use it! The purpose of writing this document is to record the configuration experience to prevent myself from forgetting, and at the same time to make an output to allow myself to digest the knowledge.

It needs to be explained first that in this document, readers have already installed texlive and vscode by default.

1. Configuration of latex in vscode

Configuring tex in vscode is relatively simple and divided into two steps:(1) Install extension,(2) Add settings.

1.1. Install extensions

Open vscode, there is anExtensioncolumn in the left toolbar, select it! Then search forlatexin the search box, as shown in the figure below.

(Super detailed) How to configure latex in vscode

Look at theInstalledLaTex Workshop

(Super detailed) How to configure latex in vscode

No, if there is, it means the installation is successful; or see if the red box numbered 2 in the picture below is displayed as shown in the picture. If it is, it means the installation is successful.

##1.2. Add settings

(Super detailed) How to configure latex in vscodeOn the vscode page, press
f1

, enter

json(Super detailed) How to configure latex in vscode, select

Preferences: open the Settings

item, as shown in the figure below.

The page shown below will appear.

You can enter the setting code in the curly braces. The code is as follows:
"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",

Note, you must enter it in the curly braces!

If there are other written settings inside the curly braces, remember to add an English comma to the last line of code, then start a new line and write the latex settings.

2 Test

Let’s test whether the configured vscode settings can write tex.

I downloaded alatex template

from IEEE and see if it can be compiled in vscode.

After downloading the latex template,① Drag the .tex file into vscode

② Click the

TEXbutton on the left toolbar③ FindBuild LaTex project

and click on it! If no error is reported, the operation is successful. I usually choose

Recipe:pdflatex(Super detailed) How to configure latex in vscodeas the compilation method

④ Find

View LaTex PDF

, selectView in VSCode tab, this time it will The generated PDF appears on the vscode page, as shown in the white area on the right side of the picture below.

If everything is normal, it will end here.

3 Latex configuration code description

Here is mainly to write some instructions for configuring the code in Section 1.2 to prevent yourself from forgetting.3.1 Compilation command

"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%" ] }],
The code here is to provide the compilation command for the compilation chain of the recipe below,nameis Tag, can be referenced by recipe,command

is the compilation command.

%DOCFILE%indicates that the file path can be in Chinese.

3.2 Compilation chain
"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" ] } ],
The code here defines the compilation chain, that is, in what order should the compiler be selected to compile the tex file,name

is the label, which is the name that appears in the toolbar.

tool

defines the order in which the compiler is used. ###############3.3 Clear auxiliary files######
"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" ],
###The above code defines the format of the auxiliary files to be cleared. ###
//设置为never不清除辅助文件 "latex-workshop.latex.autoClean.run": "never",

这里有三个选项,分别是:

① onBuilt:每次编译后都清除辅助文件;

② onFailed: 编译失败时清除辅助文件;

③ never:从不清除辅助文件。

我这里选了never,一开始用的是onFailed,但我发现一旦编译错误之后,vscode会把所有辅助文件全部清除,导致修改代码去掉bug之后,也无法正常编译了,所以选择了nerver

3.4 pdf浏览器选择

//tex文件浏览器,可选项为"none" "browser" "tab" "external" "latex-workshop.view.pdf.viewer": "tab",

上面代码定义了编译后查看pdf的浏览器,有4个选项,分别是:

① none: 不用浏览器;

② brower:使用网页浏览器;

③ tab:使用vscode内置浏览器;

④ external:使用外置pdf浏览器。

我用的是vscode内置浏览器,其实网页浏览器也挺好用的,显字大。

3.5 自动编译选项

//自动编译tex文件 "latex-workshop.latex.autoBuild.run": "onFileChange",

上面代码定义了自动编译代码的功能,使用默认编译链自动构建tex的project,有3个选项,分别是:

① onFileChange:检测到文件更改的时候自动编译tex;

② onSave:保存的时候自动编译tex;

③ never:不自动编译tex。

我选择的是onFileChange,时时编译,保证自己的文档不丢失。

3.6 显示菜单内容

//显示内容菜单:(1)编译文件;(2)定位游标 "latex-workshop.showContextMenu": true,

上面代码定义了在tex文件中,单击鼠标右键出现的菜单选项。

这是属性为true时右键菜单的样子。

(Super detailed) How to configure latex in vscode

这是属性为false时右键菜单的样子。

(Super detailed) How to configure latex in vscode

Build LaTex projrct为编译latex项目,SyncTex from cursor为定位tex代码在pdf文件中的位置,即正向定位。

这里为了方便编译和定位正文内容,我选了true选项。

3.6 错误和警告信息提示

//显示错误 "latex-workshop.message.error.show": false, //显示警告 "latex-workshop.message.warning.show": false,

上面代码定义了出现错误或者警告的时候是否会出现弹窗,我觉得弹窗很烦人,而且在终端中也可看到,所以选择了false属性。

3.7 自动补全功能

//从使用的包中自动补全命令和环境 "latex-workshop.intellisense.package.enabled": true,

上面代码定义了是否自动补全命令和环境的功能,我觉得挺实用的,少打很多字,特别方便,还有提示,所以选择了true属性。

3.8 默认编译链选择

//设置vscode编译tex文档时的默认编译链 "latex-workshop.latex.recipe.default": "lastUsed",

上面代码设置了vscode编译tex文档中的默认编译链,有2个选项,分别是

① first:选择latex-workshop.latex.recipes的第1条作为默认编译链;

② lastUsed:选择上一次使用的编译链作为默认编译链。

我在这里选择了lastUsed,因为我发现我用的最多的编译链是pdflatex

3.9 反向定位

// 用于反向同步的内部查看器的键绑定。ctrl/cmd +点击(默认)或双击 "latex-workshop.view.pdf.internal.synctex.keybinding": "double-click",

上面代码定义了从pdf浏览器中定位vscode的tex代码位置的功能,我觉得这条功能十分十分好用,强烈推荐!

这里也有2个选项,分别是:

① ctrl-click:ctrl+鼠标左键单击;

② double-click:鼠标左键双击。

我比较喜欢鼠标左键双击,所以选择的第二个选项。

4 结束

到这里整篇文档就结束啦!

我是参考了这篇文档来配置latex的,感谢这位作者!

要是不会安装texlive和vscode的话,这篇文档也有很详细的介绍,大家可以看看。

更多关于VSCode的相关知识,请访问:vscode基础教程

The above is the detailed content of (Super detailed) How to configure latex in vscode. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete