Home Development Tools VSCode How to write LaTeX using VSCode?

How to write LaTeX using VSCode?

Dec 20, 2019 am 10:15 AM
latex vscode

How to write LaTeX using VSCode?

Many people use texstudio or winedt with texlive to write How to write LaTeX using VSCode? documents. For a long time, texstudio was my only editor. However, I can’t stand it because of my appearance. 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 How to write LaTeX using 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 set up the reverse search according to Section 5 to use it.

1. Install texlive

Load the iso file of texlive 2019,

How to write LaTeX using VSCode?

Right-click install-tl-windows and click Run as administrator to enter the installation interface.

How to write LaTeX using VSCode?

You can click "Advanced" to enter advanced installation to cancel the macro packages you do not need to install.

How to write LaTeX using VSCode?

Click "Customize" to uncheck unnecessary macro packages.

How to write LaTeX using VSCode?

I personally don’t need many macro packages and functions, so I uncheck them here. You can check the functions you need according to your needs. If you find it troublesome, install them all. It's ok, it doesn't consume much space.

After setting the installation path and other options, click "Install", then sit quietly for 20 minutes and wait for the installation to complete.

2. Install the [formula] plug-in on VSCode

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

How to write LaTeX using VSCode?

#After VSCode is installed, install the LaTeX Workshop plug-in in the extension store.

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

How to write LaTeX using VSCode?

You can see that the code has been highlighted.

3. Configure VSCode’s [formula] plug-in

Put the following code into the settings area of ​​VSCode.

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

[Formula] The default compilation tool of LaTeX Workshop is latexmk. You can modify the required tools and commands according to your needs. I don’t need to use latexmk, so I modified it to xelatex, which is commonly used in the Chinese environment. Modify it yourself as needed. (Thanks to @huan Yu, replace %DOC% in tools with %DOCFILE% to support files under Chinese paths)

"latex-workshop.latex.recipes": [
    {
        "name": "xelatex",
        "tools": [
            "xelatex"
        ]
    },
    {
        "name": "xe->bib->xe->xe",
        "tools": [
            "xelatex",
            "bibtex",
            "xelatex",
            "xelatex"
        ]
    }
],
Copy after login

[formula] 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 click the small check mark in the lower left corner of the VSCode interface during compilation, click "Build LaTeX project", and select "xe->bib->xe-> xe", another method is to use the right column, or directly put the Recipe of "xe->bib->xe->xe" first, then it can be compiled as the default Recipe, but because of the number of compilations The more there are, the slower the speed will be. You can add the compilation chain you need according to the format according to your needs.

How to write LaTeX using VSCode?

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

%!TEX program = pdflatex
Copy after login

To use SumatraPDF to preview the compiled PDF file, add the following code to enter Settings area.

"latex-workshop.view.pdf.viewer": "external",
"latex-workshop.view.pdf.external.command": {
    "command": "E:/Programs/SumatraPDF/SumatraPDF.exe",
    "args": [
        "%PDF%"
    ]
},
Copy after login

[Formula] "viewer" sets the reader to an external reader, "command" is the path of SumatraPDF.exe, modify it according to the specific situation.

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

How to write LaTeX using VSCode?

插件经过几次更新之后已经去掉了右键菜单选项,选项被移动到了右侧栏。点击右侧栏的 How to write LaTeX using VSCode? 图标,再点击你所想要使用的Recipe就可以编译了,如果用快捷键则默认使用第一条 Recipe 编译。或者也可以使用快捷键 Ctrl+Alt+V。

How to write LaTeX using VSCode?

单击右上角的按钮即可打开 SumatraPDF 并预览。

4. 配置正向搜索

"latex-workshop.view.pdf.external.synctex": {
    "command": "E:/Programs/SumatraPDF/SumatraPDF.exe",
    "args": [
        "-forward-search",
        "%TEX%",
        "%LINE%",
        "%PDF%"
    ]
},
Copy after login

[公式] 添加代码进入设置区以配置正向搜索。“command”依旧是 SumatraPDF.exe 的存放位置,根据具体情况修改。

1How to write LaTeX using VSCode?

单击“SyncTeX from cursor”即可正向搜索。

How to write LaTeX using VSCode?

可以看到,光标所在的行的内容在 PDF 中高亮显示。

5. 配置反向搜索

打开 SumatraPDF,进入设置->选项->设置反向搜索命令行

1How to write LaTeX using VSCode?

添加以下命令

"Code.exe" "resources\app\out\cli.js" -g "%f":"%l"
Copy after login

根据 VSCode 具体的安装位置将“Code.exe”和“resources\app\out\cli.js”换成 VSCode 在自己的电脑上的安装位置,例如:

"C:\Users\Marvey\AppData\Local\Programs\Microsoft VS Code\Code.exe" 
"C:\Users\Marvey\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js" -g "%f":"%l"
Copy after login

(感谢 @Macrofuns 指出,如果不加双引号,在文件路径有空格的情况下会导致无法反向搜索)

双击 PDF 中的任意一处即可跳转到 VSCode 中所对应的内容的源代码处。

How to write LaTeX using VSCode?

这样 VSCode + texlive 就完全配置好了。

最好不要清理 xelatex 生成的 gz 后缀的临时文件,否则就不能进行正向和反向搜索;

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

"resources\app\out\cli.js"
Copy after login

解决方案来源:

https://link.zhihu.com/?target=https%3A//github.com/James-Yu/LaTeX-Workshop/issues/637%23issuecomment-473145503

6. 其他设置

LaTeX Workshop 默认保存的时候自动编译,如果不喜欢这个设置,可以添加以下代码进入设置区:

    "latex-workshop.latex.autoBuild.run": "never",
Copy after login

附录

    // LaTeX
    "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%"
            ]
        }
    ],
    "latex-workshop.latex.recipes": [
        {
            "name": "xelatex",
            "tools": [
                "xelatex"
            ]
        },
        {
            "name": "xe->bib->xe->xe",
            "tools": [
                "xelatex",
                "bibtex",
                "xelatex",
                "xelatex"
            ]
        },
        {
            "name": "pdflatex",
            "tools": [
                "pdflatex"
            ]
        }
    ],
    "latex-workshop.view.pdf.viewer": "external",
    "latex-workshop.view.pdf.external.command": {                // **********
        "command": "C:/Program Files/SumatraPDF/SumatraPDF.exe", // 注意修改路径
        "args": [                                                // **********
            "%PDF%"
        ]
    },
    
    "latex-workshop.view.pdf.external.synctex": {                // **********
        "command": "C:/Program Files/SumatraPDF/SumatraPDF.exe", // 注意修改路径
        "args": [                                                // **********
            "-forward-search",
            "%TEX%",
            "%LINE%",
            "%PDF%"
        ]
    },
Copy after login

推荐教程:vscode教程

The above is the detailed content of How to write LaTeX using VSCode?. For more information, please follow other related articles on the PHP Chinese website!

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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to view word documents in vscode How to view word documents in vscode How to view word documents in vscode How to view word documents in vscode May 09, 2024 am 09:37 AM

First, open the vscode software on the computer, click the [Extension] icon on the left, as shown in ① in the figure. Then, enter [officeviewer] in the search box of the extension interface, as shown in ② in the figure. Then, from the search Select [officeviewer] to install in the results, as shown in ③ in the figure. Finally, open the file, such as docx, pdf, etc., as shown below

How to draw a flow chart with vscode_How to draw a flow chart with visual_studio code How to draw a flow chart with vscode_How to draw a flow chart with visual_studio code Apr 23, 2024 pm 02:13 PM

First, open visual studio code on the computer, click the four square buttons on the left, then enter draw.io in the search box to query the plug-in, click Install. After installation, create a new test.drawio file, then select the test.drawio file, enter the editing mode on the left There are various graphics on the side. You can draw the flow chart by selecting at will. After drawing, click File → Embed → svg and then select Embed. Copy the svg code. Paste the copied svg code into the html code. Open the html web page and you can see it. Click on the picture on the web page to jump to the flow chart. On this page, you can zoom in and out of the flow chart. Here, we choose to click on the pencil pattern in the lower right corner to jump to the web page.

Caltech Chinese use AI to subvert mathematical proofs! Speed ​​up 5 times shocked Tao Zhexuan, 80% of mathematical steps are fully automated Caltech Chinese use AI to subvert mathematical proofs! Speed ​​up 5 times shocked Tao Zhexuan, 80% of mathematical steps are fully automated Apr 23, 2024 pm 03:01 PM

LeanCopilot, this formal mathematics tool that has been praised by many mathematicians such as Terence Tao, has evolved again? Just now, Caltech professor Anima Anandkumar announced that the team released an expanded version of the LeanCopilot paper and updated the code base. Image paper address: https://arxiv.org/pdf/2404.12534.pdf The latest experiments show that this Copilot tool can automate more than 80% of the mathematical proof steps! This record is 2.3 times better than the previous baseline aesop. And, as before, it's open source under the MIT license. In the picture, he is Song Peiyang, a Chinese boy. He is

How to enable background updates in vscode How to enable background updates in vscode How to enable background updates in vscode How to enable background updates in vscode May 09, 2024 am 09:52 AM

1. First, after opening the interface, click the file menu in the upper left corner. 2. Then, click the settings button in the preferences column. 3. Then, in the settings page that jumps, find the update section. 4. Finally, click the mouse to check and enable it. Download and install the new VSCode version button in the background on Windows and restart the program.

How to add files to vscode workspace How to add files to vscode workspace How to add files to vscode workspace How to add files to vscode workspace May 09, 2024 am 09:43 AM

1. First, open the vscode software, click the explorer icon, and find the workspace window 2. Then, click the file menu in the upper left corner and find the add folder to workspace option 3. Finally, find the folder location in the local disk , click the add button

How to disable wsl configuration file in vscode How to disable wsl configuration file in vscode How to disable wsl configuration file in vscode How to disable wsl configuration file in vscode May 09, 2024 am 10:30 AM

1. First, open the settings option in the settings menu. 2. Then, find the terminal column in the commonly used page. 3. Finally, uncheck the usewslprofiles button on the right side of the column.

How to set animation smooth insertion in VScode VScode tutorial to set animation smooth insertion How to set animation smooth insertion in VScode VScode tutorial to set animation smooth insertion May 09, 2024 am 09:49 AM

1. First, after opening the interface, click the workspace interface 2. Then, in the open editing panel, click the File menu 3. Then, click the Settings button under the Preferences column 4. Finally, click the mouse to check the CursorSmoothCaretAnimation button and save Just set it

How to open workspace trust permissions in Vscode Vscode method to open workspace trust permissions How to open workspace trust permissions in Vscode Vscode method to open workspace trust permissions May 09, 2024 am 10:34 AM

1. First, after opening the editing window, click the configuration icon in the lower left corner 2. Then, click the Manage Workspace Trust button in the submenu that opens 3. Then, find the page in the editing window 4. Finally, according to your office Just check the relevant instructions if required

See all articles