Home > Development Tools > VSCode > Walk you step by step to configure latex in vscode

Walk you step by step to configure latex in vscode

青灯夜游
Release: 2023-04-06 18:58:50
forward
3983 people have browsed it

How to configure latex in vscode? The following article will take you step by step to configure latex in vscode. I hope it will be helpful to you!

Walk you step by step to configure latex in vscode

I have been using texstudio to write papers before, but I think the UI of texstudio is not good-looking. In addition, during actual use, I have never had those functions in the toolbar of texstudio. I have used it before, and it is enough to simply write tex documents, so I considered using a good-looking and 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 . [Recommended learning: vscode tutorial, Programming teaching]

##1.1. Install extension

Open vscode, there is a

Extension column in the left toolbar, select it! Then search for latex in the search box, as shown in the figure below.

Walk you step by step to configure latex in vscode

Look at the

InstalledLaTex Workshop

Walk you step by step 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

Walk you step by step to configure latex in vscode
On the vscode page, press

f1

, enter Walk you step by step to configure latex in vscodejson

, 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",
Copy after login

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 a

latex 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 TEX button on the left toolbar ③ Find

Build LaTex project

and click on it! If no error is reported, the operation is successful. I usually choose Walk you step by step to configure latex in vscodeRecipe:pdflatex

as the compilation method

④ Find

View LaTex PDF, select View 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

The code here provides the compilation command for the compilation chain of the recipe below,name is a label that can be referenced by recipe, command is a 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"
        ]
    }],
Copy after login
The code here defines the compilation chain, that is, in what order the compiler should be selected Compile the tex file, name is the label, that 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"],
Copy after login

上面的代码定义了要清除的辅助文件的格式。

//设置为never不清除辅助文件"latex-workshop.latex.autoClean.run": "never",
Copy after login

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

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

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

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

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

3.4 pdf浏览器选择

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

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

① none: 不用浏览器;

② brower:使用网页浏览器;

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

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

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

3.5 自动编译选项

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

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

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

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

③ never:不自动编译tex。

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

3.6 显示菜单内容

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

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

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

Walk you step by step to configure latex in vscode

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

Walk you step by step 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,
Copy after login

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

3.7 自动补全功能

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

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

3.8 默认编译链选择

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

上面代码设置了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",
Copy after login

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

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

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

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

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

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

The above is the detailed content of Walk you step by step to configure latex in vscode. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template