Write latex through VSCode under Windows

Keywords: Windows Latex Visual Studio Code

Why latex

You have this demand. It must be because latex is very popular. In my opinion, the cow is:

  1. Autotypesetting format
  2. When submitting papers, you can directly borrow the template provided by relevant journals to fill in information.

How to install and configure latex

The configuration mentioned here is mainly aimed at the latex configuration under windows platform. Those who have learned programming can understand this. We need to compile the tex language. For example, g + +, gcc. And we write c, c + + tools or programming environment will choose to use vscode, clion. So for latex, we mainly need to install two parts. texlive (similar to mingw under windows) and texstudio (clion, etc.).
How to install, I still want to post a tutorial that I think is nice
[texlive and texstudio] and [VSCode writing LaTeX] installation and setup - YuanXin's article - Zhihu

At this time, you can actually write latex directly with textstudio. I've been doing this for a long time. Now I want to write latex with vscode. There are several reasons:

  1. I can't prompt for completion when I write on textstudio
  2. The operation does not have much gradient (if you use vscode, you can also use vim editing mode)

How to install the necessary plug-ins for latex in vscode

There are also many more perfect tutorials.

  1. Write LaTeX - Marvey's article using VSCode - know

Here, I just want to share some considerations that are not mentioned in the tutorial.

Shortcut key settings

First, let's take a look at my complete configuration:

{
    // "Latex workshop. Latex. Autobuild. Run": "never"
    "latex-workshop.message.error.show": false,
    "latex-workshop.message.warning.show": false,
    "latex-workshop.view.pdf.viewer": "external", 
    "latex-workshop.view.pdf.external.viewer.command": "E:/Program Files/SumatraPDF/SumatraPDF.exe", // Pay attention to modifying the path
    "latex-workshop.view.pdf.external.viewer.args": [
        "%PDF%"
    ],
    "latex-workshop.view.pdf.external.synctex.command": "E:/Program Files/SumatraPDF/SumatraPDF.exe", // Pay attention to modifying the path
    "latex-workshop.view.pdf.external.synctex.args": [
        "-forward-search",
        "%TEX%",
        "%LINE%",
        "-reuse-instance",
        "-inverse-search",
        //"\" E: \ \ program files (x86) \ \ Microsoft vs Code \ \ code.exe \ "- R - G \"% F:% L \ "", / / no cli version, external startup required "
        "\"E:\\Program Files (x86)\\Microsoft VS Code\\Code.exe\" \"E:\\Program Files (x86)\\Microsoft VS Code\\resources\\app\\out\\cli.js\" -r -g \"%f:%l\"", //With cli, it must be started internally
        "%PDF%"
    ],
    // Compiler configuration (commands and parameters): pdflatex or xelatex or latexmk
        "latex-workshop.latex.tools": [
        {// Compilation tools and commands
            "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",
                "-pdf",
                "%DOCFILE%"
            ]
        },
        {
            "name": "bibtex",
            "command": "bibtex",
            "args": [
                "%DOCFILE%"
            ]
        },
        {
            "name": "latexmk",
            "command": "latexmk",
            "args": [
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "-pdf",
                "%DOCFILE%",
            ]
        },
    ],
    // Call and execute in sequence according to the configured tools.
    // In general, it is recommended to put "latexmk" first, which is the default compilation method
    "latex-workshop.latex.recipes": [
    {
            "name": "xe->bib->xe->xe",
            "tools": [
                "xelatex",
                "bibtex",
                "xelatex",
                "xelatex"
            ]
        },
        { // latexmk compilation mode
            "name": "latexmk",
            "tools": [
                "latexmk"
            ]  
        },
        { // xelatex compilation mode
            "name": "xelatex",
            "tools": [
                "xelatex",
            ]
        },
        { // pdflatex compilation mode
            "name": "pdflatex",
            "tools": [
                "pdflatex"
            ]
        },
        
    ],
}

After completing the above settings, our tex plug-in will present the compilation scheme in the figure below.

Corresponds to the order of our recipes. Also, the default is the first XE - > Bib - > XE - > Xe. Therefore, you can adjust the order according to your own situation. Generally, latexmk is used by default, which can avoid a lot of unnecessary trouble. It just takes a long time to compile.

Forward and reverse direction search

This is also a very cowhide thing. There's nothing to say. Just watch the tutorial.

Quickly write latex documents through vim mode

Leave a tail and how to achieve this function in the next update.
And how to automatically switch to English when vim exits to normal mode through ESC. So that we can operate conveniently without an additional input method switching. In the insert mode, the default is Chinese input. It is convenient for us to write Chinese documents.

Posted by dsoukup on Sun, 31 Oct 2021 02:18:50 -0700