首先进入清华大学开源软件镜像站下载最新的TexLive
https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/Images/
下载完成后双击下图红框中的文件
这时会出现安装的GUI界面
点击下一步,选择安装的位置
建议不安装在系统盘,因为占用空间较大。
下面默认安装即可。安装时间较长,20分钟左右,耐心等待安装完成。
进入VS Code的官网下载安装包文件安装。
安装完成后,打开VS Code,如下图所示,打开插件,搜索latex,安装LaTeX Workshop
完成上述步骤后已经可以编译tex文件了,但是我们先配置一下LaTeX Workshop。
默认情况下按Ctrl + ,
打开设置,搜索latex-workshop.latex.recipes
并单击User目录下的Edit setttings.json
此时文件内容应该如下图所示
我选择将其注释后再粘贴进下面的代码,如下图所示
全部配置信息如下
{
"editor.wordWrap": "on",
"workbench.startupEditor": "newUntitledFile",
"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",
"*.gz"
],
"latex-workshop.view.pdf.viewer": "tab",
"latex-workshop.latex.recipes": [
{
"name": "xelatex",
"tools": [
"xelatex",
"xelatex"
]
},
{
"name": "xelatexb",
"tools": [
"xelatex",
"bibtex",
"xelatex",
"xelatex"
]
},
{
"name": "latexmk",
"tools": [
"latexmk"
]
},
{
"name": "pdflatex -> bibtex -> pdflatex*2",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
}
],
"latex-workshop.latex.tools": [
{
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
{
"name": "latexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"%DOC%"
]
},
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
}
],
"latex-workshop.latex.autoClean.run": "onBuilt"
}
配置解释如下
"latex-workshop.latex.clean.enabled"
是否删除每次编译成pdf时生成得到中间文件"latex-workshop.latex.clean.fileTypes"
删除哪些文件"latex-workshop.latex.tools"
配置排版引擎程序"latex-workshop.latex.recipes"
定义排版引擎程序调用顺序注意
默认使用排版引擎程序调用顺序配置"latex-workshop.latex.recipes"中的第一个进行编译排版,上述配置中第一个xelatex不会对bib形式的参考文献编译排版,如用bib形式的参考文献请把第二个xelatexb移到第一个,否则会报错
\documentclass{article}
\usepackage{newtxtext,newtxmath}
\usepackage{bm}
\author{Yonmin Ma}
\title{Test of Visual Studio Code for LaTeX}
\begin{document}
\maketitle
\begin{align}
\begin{aligned}
& \nabla\times \bm{H} = \bm{J} + \frac{\partial{\bm{D}}}{\partial{t}}\\
& \nabla\times \bm{E} = -\frac{\partial{\bm{B}}}{\partial{t}}\\
& \nabla\cdot\bm{B} = 0\\
& \nabla\cdot\bm{D} = \rho
\end{aligned}
\end{align}
\end{document}