search
HomeDevelopment ToolsVSCodeA brief discussion on how to configure the LaTeX editor in VSCode

This article will introduce to you VSCodeHow to configure LaTeX and use VSCode to write LaTeX. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

A brief discussion on how to configure the LaTeX editor in VSCode

Related recommendations: "vscode tutorial"

Many people use texstudio or winedt with texlive to write A brief discussion on how to configure the LaTeX editor in VSCode documents. For a long time, texstudio was my only editor. However, as a face-conscious person, I couldn't stand the original interface, so I fell in love with VSCode. Beautiful, free, and open source are the main reasons why I choose VSCode.

There are many articles introducing VSCode A brief discussion on how to configure the LaTeX editor in VSCode on the Internet, but there are a little less introductions on configuring external readers. I searched online for a long time before I found the method on the github homepage of the author of LaTeX Workshop, and at the same time I also had the idea. Got the idea to write a tutorial.

This article mainly introduces how to use VSCode to write simple documents and set up an external PDF reader.

If you have installed texlive, VSCode and SumatraPDF, and don’t want to read the entire article and just want to get started quickly, please turn to the appendix at the end of the article and copy all the code to the settings of VSCode , and then replace the "..." with the path of the software on your computer, and then you can use it.

1. Install texlive

You can download the image file of texlive from the following URL:

mirrors.huaweicloud.com

##https://mirrors.aliyun.com/CTAN/systems/texlive/Images/

Open source mirror sites from other universities such as Tsinghua University and University of Science and Technology of China are also available. But in terms of speed, I feel that Huawei Cloud and Alibaba Cloud are faster.

Load the iso file of texlive 2020,

A brief discussion on how to configure the LaTeX editor in VSCode

Right-click install-tl-windows, click Run as administrator to enter the installation interface, Click "Advanced" in the lower left corner to enter advanced installation to cancel the macro packages you do not need to install. A brief discussion on how to configure the LaTeX editor in VSCode

A brief discussion on how to configure the LaTeX editor in VSCode

Click "Customize" to uncheck unnecessary macro packages. A brief discussion on how to configure the LaTeX editor in VSCode

A brief discussion on how to configure the LaTeX editor in VSCode

# You can save 1G of space by simply unchecking the non-Chinese and English language packs. If you find it too troublesome, you can also install them all. A brief discussion on how to configure the LaTeX editor in VSCode

In the lower right corner of the installation interface, you can choose whether to install the TeXworks editor. I think since you have read this article, you should not need this. After setting the installation path and other options, click "Install" and then wait for 20 minutes - 3 hours for the installation to complete.

2. Install the A brief discussion on how to configure the LaTeX editor in VSCodeplug-in on VSCode

At the same time, download VSCode and install it. The installation of VSCode is very simple, here Stop nagging.

A brief discussion on how to configure the LaTeX editor in VSCode

After VSCode is installed, install the LaTeX Workshop plug-in in the extension store. A brief discussion on how to configure the LaTeX editor in VSCode

After the installation is complete, just open a tex source file,

A brief discussion on how to configure the LaTeX editor in VSCode

A brief discussion on how to configure the LaTeX editor in VSCode You can see that the code has been highlighted.

3. Configure VSCode’s A brief discussion on how to configure the LaTeX editor in VSCodeplug-in

Press F1 in the VSCode interface, then type “setjson” and click “Home” Option: Open Settings (JSON)",

A brief discussion on how to configure the LaTeX editor in VSCode

Put the following code into the settings area:

"latex-workshop.latex.tools": [
    {
        // 编译工具和命令
        "name": "xelatex",
        "command": "xelatex",
        "args": [
            "-synctex=1",
            "-interaction=nonstopmode",
            "-file-line-error",
            "-pdf",
            "%DOCFILE%"
        ]
    },
    {
        "name": "pdflatex",
        "command": "pdflatex",
        "args": [
            "-synctex=1",
            "-interaction=nonstopmode",
            "-file-line-error",
            "%DOCFILE%"
        ]
    },
    {
        "name": "bibtex",
        "command": "bibtex",
        "args": [
            "%DOCFILE%"
        ]
    }
],

A brief discussion on how to configure the LaTeX editor in VSCode The default compilation tool of LaTeX Workshop is latexmk , everyone can modify the required tools and commands according to their needs. I don’t need to use latexmk, so I modified it to xelatex, which is commonly used in the Chinese environment, and everyone can modify it according to their needs. (Thanks to @huan Yu, replacing %DOC% in tools with %DOCFILE% will support compiling files under Chinese paths)

"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"
        ]
    }],

A brief discussion on how to configure the LaTeX editor in VSCode is used to configure the compilation chain and is also placed in the settings area. The first recipe is the default compilation tool. If you need to use bibtex, you can use the following method:

  • When compiling, click the small check mark in the lower left corner of the VSCode interface and click "Build LaTeX project ”, select the recipe with bib, or use shortcut keys to quickly select;

  • Put the recipe with bib first, and it can be compiled as the default recipe, or you can Because there are more compilations, the speed will be slower;

  • Add %!BIB program = bibtex

A brief discussion on how to configure the LaTeX editor in VSCode# at the beginning of the document

##To use pdflatex, just add the following code at the beginning of the tex document:

%!TEX program = pdflatex
To use SumatraPDF to preview the compiled PDF file, add the following code to enter the settings area.

"latex-workshop.view.pdf.viewer": "external","latex-workshop.view.pdf.external.viewer.command": "C:/.../SumatraPDF.exe","latex-workshop.view.pdf.external.viewer.args": [
    "-forward-search",
    "%TEX%",
    "%LINE%",
    "-reuse-instance",
    "-inverse-search",
    "\"C:/.../Microsoft VS Code/Code.exe\" \"C:/.../Microsoft VS Code/resources/app/out/cli.js\" -gr \"%f\":\"%l\"",
    "%PDF%"],

"viewer" chooses to use an external reader. Where there is "..." in "viewer.command" and "viewer.args", you need to install SumatraPDF and VSCode on your computer. To modify the location, remember to change the drive letter as well. A brief discussion on how to configure the LaTeX editor in VSCode

Now you can use VSCode to compile the tex file and preview it with SumatraPDF as the reader.

A brief discussion on how to configure the LaTeX editor in VSCode

After several updates of the plug-in, the right-click menu option has been removed, and the options have been moved to the left column. Click the A brief discussion on how to configure the LaTeX editor in VSCode icon in the left column, and then click the Recipe you want to use to compile. If you use the shortcut key, the first Recipe will be used by default to compile. Click the magnifying glass button in the upper right corner or press Ctrl Alt v to open SumatraPDF for preview. A brief discussion on how to configure the LaTeX editor in VSCode

4. Configure forward and reverse search
"latex-workshop.view.pdf.external.synctex.command": "C:/.../SumatraPDF.exe","latex-workshop.view.pdf.external.synctex.args": [
    "-forward-search",
    "%TEX%",
    "%LINE%",
    "-reuse-instance",
    "-inverse-search",
    "\"C:/.../Microsoft VS Code/Code.exe\" \"C:/.../Microsoft VS Code/resources/app/out/cli.js\" -gr \"%f\":\"%l\"",
    "%PDF%",],

Add code into the settings area to configure forward search, the same as above, inside ".. ." part is modified based on your own situation (thanks to @Macrofuns for pointing out that without double quotes, reverse search will not be possible if the file path contains spaces). A brief discussion on how to configure the LaTeX editor in VSCode

A brief discussion on how to configure the LaTeX editor in VSCode

# Click "SyncTeX from cursor" to search forward. A brief discussion on how to configure the LaTeX editor in VSCode

A brief discussion on how to configure the LaTeX editor in VSCode

A brief discussion on how to configure the LaTeX editor in VSCode 可以看到,光标所在的行的内容在 PDF 中高亮显示(可以自己配置快捷键,我设置的是 Alt + S)。

A brief discussion on how to configure the LaTeX editor in VSCode

A brief discussion on how to configure the LaTeX editor in VSCode 在PDF中双击即可反向搜索

不要清理生成的名字中带 synctex 的文件,否则就不能进行正向和反向搜索;

之前的文章中,我提到了从 VSCode 预览按钮启动 SumatraPDF 会无法反向搜索的问题,现在已经解决,解决方法是在反向搜索命令中添加

"resources\app\out\cli.js"

解决方案来源:

https://github.com/James-Yu/LaTeX-Workshop/issues/637#issuecomment-473145503

这个方法目前有个 bug,SumatraPDF 要从 VSCode 中打开才能进行反向搜索,单独打开的 SumatraPDF 在进行反向搜索时会跳转到 VSCode 的配置文件 cli.js。

6. 快捷键设置

在 VSCode 界面下按下 F1,键入“keyjson”,选择“打开键盘快捷方式(JSON)”,然后把以下代码放入:

{
    "key": "alt+s",
    "command": "latex-workshop.synctex",
    "when": "editorTextFocus && !isMac"},{
    "key": "alt+b",
    "command": "latex-workshop.build",
    "when": "editorTextFocus && !isMac"},{
    "key": "alt+t",
    "command": "latex-workshop.kill",
    "when": "editorTextFocus && !isMac"},{
    "key": "alt+e",
    "command": "latex-workshop.recipes"},

这段代码的意义是将 Alt+s 绑定到正向搜索,将 Alt+b 绑定到使用默认 recipe 编译,将 Alt+t 绑定到终止编译,将 Alt+e 绑定到选择其他 recipe 编译,可以自行更换为适合自己的快捷键,只需修改“key”那一项即可。

7. 其他设置

  • LaTeX Workshop 默认保存的时候自动编译,如果不喜欢这个设置,可以添加以下代码进入设置区:
"latex-workshop.latex.autoBuild.run": "never",
  • 如果编译出错,插件会弹出两个很烦人的气泡,不喜欢的话可以在设置中添加以下代码:
"latex-workshop.message.error.show": false,"latex-workshop.message.warning.show": false,

附录

注意:只需把以下代码放入设置区的方括号里,不要删去方括号,不要忘记替换软件的路径。

// LaTeX
"latex-workshop.latex.autoBuild.run": "never",
"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": "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.view.pdf.viewer": "external",

"latex-workshop.view.pdf.external.viewer.command": "C:/.../SumatraPDF.exe",
"latex-workshop.view.pdf.external.viewer.args": [
    "-forward-search",
    "%TEX%",
    "%LINE%",
    "-reuse-instance",
    "-inverse-search",
    "\"C:/.../Microsoft VS Code/Code.exe\" \"C:/.../Microsoft VS Code/resources/app/out/cli.js\" -gr \"%f\":\"%l\"",
    "%PDF%"
],

"latex-workshop.view.pdf.external.synctex.command": "C:/.../SumatraPDF.exe",
"latex-workshop.view.pdf.external.synctex.args": [
    "-forward-search",
    "%TEX%",
    "%LINE%",
    "-reuse-instance",
    "-inverse-search",
    "\"C:/.../Microsoft VS Code/Code.exe\" \"C:/.../Microsoft VS Code/resources/app/out/cli.js\" -gr \"%f\":\"%l\"",
    "%PDF%",
],

更多编程相关知识,请访问:编程视频!!

The above is the detailed content of A brief discussion on how to configure the LaTeX editor in VSCode. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:知乎. If there is any infringement, please contact admin@php.cn delete
Visual Studio Professional and Enterprise: Paid Versions and FeaturesVisual Studio Professional and Enterprise: Paid Versions and FeaturesMay 10, 2025 am 12:20 AM

The difference between VisualStudioProfessional and Enterprise is in the functionality and target user groups. The Professional version is suitable for professional developers and provides functions such as code analysis; the Enterprise version is for large teams and has added advanced tools such as test management.

Choosing Between Visual Studio and VS Code: The Right Tool for YouChoosing Between Visual Studio and VS Code: The Right Tool for YouMay 09, 2025 am 12:21 AM

VisualStudio is suitable for large projects, VSCode is suitable for projects of all sizes. 1. VisualStudio provides comprehensive IDE functions, supports multiple languages, integrated debugging and testing tools. 2.VSCode is a lightweight editor that supports multiple languages ​​through extension, has a simple interface and fast startup.

Visual Studio: A Powerful Tool for DevelopersVisual Studio: A Powerful Tool for DevelopersMay 08, 2025 am 12:19 AM

VisualStudio is a powerful IDE developed by Microsoft, supporting multiple programming languages ​​and platforms. Its core advantages include: 1. Intelligent code prompts and debugging functions, 2. Integrated development, debugging, testing and version control, 3. Extended functions through plug-ins, 4. Provide performance optimization and best practice tools to help developers improve efficiency and code quality.

Visual Studio vs. VS Code: Pricing, Licensing, and AvailabilityVisual Studio vs. VS Code: Pricing, Licensing, and AvailabilityMay 07, 2025 am 12:11 AM

The differences in pricing, licensing and availability of VisualStudio and VSCode are as follows: 1. Pricing: VSCode is completely free, while VisualStudio offers free community and paid enterprise versions. 2. License: VSCode uses a flexible MIT license, and the license of VisualStudio varies according to the version. 3. Usability: VSCode is supported across platforms, while VisualStudio performs best on Windows.

Visual Studio: From Code to ProductionVisual Studio: From Code to ProductionMay 06, 2025 am 12:10 AM

VisualStudio supports the entire process from code writing to production deployment. 1) Code writing: Provides intelligent code completion and reconstruction functions. 2) Debugging and testing: Integrate powerful debugging tools and unit testing framework. 3) Version control: seamlessly integrate with Git to simplify code management. 4) Deployment and Release: Supports multiple deployment options to simplify the application release process.

Visual Studio: A Look at the Licensing LandscapeVisual Studio: A Look at the Licensing LandscapeMay 05, 2025 am 12:17 AM

VisualStudio offers three license types: Community, Professional and Enterprise. The Community Edition is free, suitable for individual developers and small teams; the Professional Edition is annually subscribed, suitable for professional developers who need more functions; the Enterprise Edition is the highest price, suitable for large teams and enterprises. When selecting a license, project size, budget and teamwork needs should be considered.

The Ultimate Showdown: Visual Studio vs. VS CodeThe Ultimate Showdown: Visual Studio vs. VS CodeMay 04, 2025 am 12:01 AM

VisualStudio is suitable for large-scale project development, while VSCode is suitable for projects of all sizes. 1. VisualStudio provides comprehensive development tools, such as integrated debugger, version control and testing tools. 2.VSCode is known for its scalability, cross-platform and fast launch, and is suitable for fast editing and small project development.

Visual Studio vs. VS Code: Comparing the Two IDEsVisual Studio vs. VS Code: Comparing the Two IDEsMay 03, 2025 am 12:04 AM

VisualStudio is suitable for large projects and Windows development, while VSCode is suitable for cross-platform and small projects. 1. VisualStudio provides a full-featured IDE, supports .NET framework and powerful debugging tools. 2.VSCode is a lightweight editor that emphasizes flexibility and extensibility, and is suitable for various development scenarios.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function