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 by vscode

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Editor to share with you about vscode's method of writing latex, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

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.

Advanced installation interface

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.

2. Install the Latex 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 Latex 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%"]}]

The default compilation tool for 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 modify it to xelatex, which is commonly used in the Chinese environment. (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"]}]

Used to configure the compilation chain, also put into the setting area. 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%"]}

"viewer" sets the reader as an external reader, and "command" is 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 the [Formula] icon in the right sidebar, and then click the Recipe you want to use to compile. If you use keyboard shortcuts, the first Recipe will be used by default. 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%"]}

Add code to enter the settings 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"

(thanks to Macrofuns for pointing out that without double quotation marks, a reverse search will not be possible 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:

"resources\ app\ out\ cli.js"

6. Other settings

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", / / Note to modify the path "args": [/ / * "% PDF%"]} "latex-workshop.view.pdf.external.synctex": {/ / * "command": "C:/Program Files/SumatraPDF/SumatraPDF.exe", / / modify the path "args": [/ / * "- forward-search" "% TEX%", "% LINE%", "% PDF%"]}, these are all the contents of the article "how vscode writes latex" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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