Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of writing LaTeX with VSCode

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail the method of using VSCode to write LaTeX. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Many people are written in texstudio or winedt in conjunction with texlive

Document, texstudio was my only editor for a long time, however, I couldn't stand the original interface, so I took a fancy to VSCode. Beautiful, free and open source are the main reasons why I choose VSCode.

There are many introductions to VSCode + on the Internet.

Although there is a little introduction to configuring external readers, I searched the Internet for a long time to find a way on the LaTeX Workshop author's github home page, and I also came up with the idea of writing a tutorial.

This article mainly introduces how to write simple documents using VSCode and how to set up external PDF readers.

If you have installed texlive, VSCode and SumatraPDF, and do not want to read the whole article, just want to get started, please turn to the appendix at the end of the article, copy all the code into the VSCode settings, and then set up a reverse search according to Section 5 to be available.

1. Install texlive

Load the iso file for texlive 2019

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

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

Click "Customize" to uncheck unwanted macro packages.

I personally do not need many macro packages and functions, so I will uncheck them here. You can check the functions you need according to your needs. If you find it troublesome to install all of them, it does not consume much space.

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

two。 Install the Formula plug-in on VSCode

At the same time, download VSCode and install, the installation of VSCode is very simple, and there is no nagging here.

After the VSCode installation is complete, install the LaTeX Workshop plug-in in the extension store.

After the installation is complete, casually open any tex source file

As you can see, the code has been highlighted.

3. Configure the Formula plug-in for VSCode

Put the following code in the settings area of VSCode.

"latex-workshop.latex.tools": [{/ / compilation tools and commands "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%"]}]

[formula] the default compilation tool for LaTeX Workshop is latexmk. You can modify the required tools and commands as needed. I don't need to use latexmk, so I modify it to xelatex, which is commonly used in Chinese environment, and you can modify it as needed. (thanks to @ huan Yu, replace% DOC% in tools with% DOCFILE% to support files in the Chinese path.)

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

[formula] is used to configure the compilation chain and put it into the setting area as well. The first recipe is the default compilation tool, if you need to use bibtex, you can click the tick in the lower left corner of the VSCode interface when compiling, click "Build LaTeX project" and select "xe- > bib- > xe- > xe". The other way is to use the right column, or directly put the "xe- > bib- > xe- > xe" Recipe into the first place, you can compile as the default Recipe, but because the compilation times are more, the speed will be slower. You can add your own compilation chain according to the format according to your needs.

To use pdflatex, simply add the following code to the beginning of the tex document:

%! TEX program = pdflatex

To preview the compiled PDF file using SumatraPDF, add the following code to enter the settings area.

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

[formula] "viewer" sets the reader as the external reader, and "command" as the path of SumatraPDF.exe, which can be modified according to the specific situation.

You can now compile the tex file using VSCode and preview it with SumatraPDF as a reader.

The plug-in has removed the right-click menu option after several updates, and the option has been moved to the right bar. Click on the right sidebar

Icon, and then click the Recipe you want to use to compile, if you use keyboard shortcuts, the default is to use the first Recipe compilation. Or you can use the shortcut key Ctrl+Alt+V.

Click the button in the upper right corner to open SumatraPDF and preview it.

4. Configure forward search

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

[formula] add code to enter the setting area to configure forward search. "command" is still the location of SumatraPDF.exe, which can be modified according to the situation.

Click "SyncTeX from cursor" to search forward.

You can see that the contents of the line where the cursor is located are highlighted in PDF.

5. Configure reverse search

Open SumatraPDF and go to Settings-> options-> Settings reverse search command line

Add the following command

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

According to the specific installation location of VSCode, replace "Code.exe" and "resources\ app\ out\ cli.js" with the installation location of VSCode on your own computer, for example:

"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"

(thank you @ Macrofuns for pointing out that if you don't add double quotation marks, you can't reverse search if there is a space in the file path.)

Double-click anywhere in the PDF to jump to the source code of the corresponding content in the VSCode.

This way VSCode + texlive is fully configured.

It is best not to clean up the temporary files of the gz suffix generated by xelatex, otherwise you cannot do forward and reverse searches.

In a previous article, I mentioned that starting SumatraPDF from the VSCode preview button would not reverse the search, which has now been resolved by adding the

"resources\ app\ out\ cli.js"

Solution source:

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

6. Other settin

LaTeX Workshop compiles automatically when it is saved by default. If you don't like this setting, you can add the following code to enter the setting area:

"latex-workshop.latex.autoBuild.run": "never"

Appendix

/ / 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" / / pay attention to modify the path "args": [/ / * "% PDF%"]} "latex-workshop.view.pdf.external.synctex": {/ / * "command": "C:/Program Files/SumatraPDF/SumatraPDF.exe" / / notice to modify the path "args": [/ / * "- forward-search", "% TEX%", "% LINE%", "% PDF%"]} So much for the method of writing LaTeX using VSCode I hope the above content can be of some help to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report