Configure LaTeX with Vscode
introduction
- install texlive
- install vscode
- InstallSumatraPdf
1 install texlive
Online LaTeX editor: https://www.overleaf.com
TeX Live download: https://www.tug.org/texlive/acquire-iso.html
MikTeX download: https://miktex.org/download
LaTeX formula editor Editor: https://latex.codecogs.com/eqneditor/editor.php
A not-so-short introduction to LaTeX: https://github.com/CTeX-org/lshort-zh-cn
2 install vscode
Refer to the author's previous blog: [Ubuntu] Install Anaconda+vscode
2.1 Plug-in installation
- Chinese , used for Chinese interface
- LaTeX Workshop , a must-have plugin
2.2 Configuration
After installing the plug-in, restart vscode, click the gear in the lower left corner, open the settings, and open the configuration file settings.json, operate as shown below to
open the configuration file and modify it, paste the following code into it
{
"latex-workshop.latex.autoBuild.run": "never",
"latex-workshop.showContextMenu": true,
"latex-workshop.intellisense.package.enabled": true,
"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": "latexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"-outdir=%OUTDIR%",
"%DOCFILE%"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
}
],
"latex-workshop.latex.recipes": [
{
"name": "XeLaTeX",
"tools": [
"xelatex"
]
},
{
"name": "PDFLaTeX",
"tools": [
"pdflatex"
]
},
{
"name": "BibTeX",
"tools": [
"bibtex"
]
},
{
"name": "LaTeXmk",
"tools": [
"latexmk"
]
},
{
"name": "xelatex -> bibtex -> xelatex*2",
"tools": [
"xelatex",
"bibtex",
"xelatex",
"xelatex"
]
},
{
"name": "pdflatex -> bibtex -> pdflatex*2",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
},
],
"latex-workshop.latex.clean.fileTypes": [
"*.aux",
"*.bbl",
"*.blg",
"*.idx",
"*.ind",
"*.lof",
"*.lot",
"*.out",
"*.toc",
"*.acn",
"*.acr",
"*.alg",
"*.glg",
"*.glo",
"*.gls",
"*.ist",
"*.fls",
"*.log",
"*.fdb_latexmk"
],
"latex-workshop.latex.autoClean.run": "onFailed",
"latex-workshop.latex.recipe.default": "lastUsed",
"latex-workshop.view.pdf.internal.synctex.keybinding": "double-click",
"zotero.latexCommand": "cite",
}
3 Install Sumatra PDF
Download from the official website and install directly
3.1 vscode configuration
Put the following code into the configuration file settings.json, pay attention to the position before the last curly brace
"latex-workshop.view.pdf.viewer": "external",
"latex-workshop.view.pdf.external.viewer.command":
"D:/AppData/SumatraPDF/SumatraPDF.exe", //注意修改路径,为安装的 SumatraPdf 的路径
"latex-workshop.view.pdf.external.viewer.args": [
"%PDF%"
],
3.2 Configure reverse search
Reverse search is helpful for quickly locating the source code location corresponding to the document. Add the following code to settings.json, which is also in front of the last curly brace
"latex-workshop.view.pdf.external.synctex.command":
"D:/AppData/SumatraPDF/SumatraPDF.exe", //注意修改路径
"latex-workshop.view.pdf.external.synctex.args": [
"-forward-search",
"%TEX%",
"%LINE%",
"%PDF%",
],
Do some configuration in the SumatraPdf software, open the advanced options through the settings, a configuration file will pop up, we only need to add the following code at the end of the configuration file
InverseSearchCmdLine = "D:\Microsoft VS Code\Code.exe" "D:\Microsoft VS Code\resources\app\out\cli.js" --ms-enable-electron-run-as-node -r -g "%f:%l"
EnableTeXEnhancements = true
双击
Then you can jump to the vscode source code part in the pdf document