文章目录
1. 安装 texlive 和 SumatraPDF
1.1 下载
选择texlive2021.iso 下载:
SumatraPDF下载:https://www.sumatrapdfreader.org/download-free-pdf-viewer.html
1.2 加载 texlive 2020 的 iso 文件
1.2.1 解压
注意不能在中文路径下解压,这样安装时会出错!!!
1.2.2 运行
右键以管理员身份运行 install-tl-windows.bat 文件。
2. 配置 VScode
2.1 安装LaTeX Workshop插件
2.2 配置 VSCode 的 LaTex 插件
配置文件内容如下:
// 取消 LaTex 保存时自动编译
//"latex-workshop.latex.autoBuild.run": "never",
// 去掉编译出错时的气泡
// "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",
"-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": "pdflatex",
"tools": [
"pdflatex"
]
},
{
"name": "xe->bib->xe->xe",
"tools": [
"xelatex",
"bibtex",
"xelatex",
"xelatex"
]
},
{
"name": "pdf->bib->pdf->pdf",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
}
],
// 使用 SumatraPDF 预览编译好的PDF文件
"latex-workshop.view.pdf.viewer": "external",
"latex-workshop.view.pdf.external.viewer.command": "E:/SumatraPDF/SumatraPDF.exe",
"latex-workshop.view.pdf.external.viewer.args": [
"-forward-search",
"%TEX%",
"%LINE%",
"-reuse-instance",
"-inverse-search",
"\"E:/Microsoft VS Code/Code.exe\" \"E:/Microsoft VS Code/resources/app/out/cli.js\" -gr \"%f\":\"%l\"",
"%PDF%"
],
// 配置正向和反向搜索
"latex-workshop.view.pdf.external.synctex.command": "E:/SumatraPDF/SumatraPDF.exe",
"latex-workshop.view.pdf.external.synctex.args": [
"-forward-search",
"%TEX%",
"%LINE%",
"-reuse-instance",
"-inverse-search",
"\"E:/Microsoft VS Code/Code.exe\" \"E:/Microsoft VS Code/resources/app/out/cli.js\" -gr \"%f\":\"%l\"",
"%PDF%",
],
2.3 Bug
编译时弹出如下bug:
Recipe terminated with fatal error: spawn xelatex ENOENT.
解决方法:
在用户和系统环境变量中添加:
E:\texlive\2021\bin\win32
参考来自:Recipe terminated with fatal error: spawn xelatex ENOENT
3. 锦上添花的 VScode插件
参考:VScode插件
4. 保存时自动格式化
参考来自:https://blog.csdn.net/Aloneingchild/article/details/108716987
下载:https://ctan.org/tex-archive/support/latexindent,解压后放在指定目录下,如 E:\texlive\latexindent下,将其添加到用户和系统环境变量中。
配置文件中添加:
// LaTex 格式化
"latex-workshop.latexindent.path": "E:/texlive/latexindent/latexindent.exe",
若要在保存时自动格式化,需要参考VScode插件这里的相关配置。
安装这个插件(可能暂时不能格式化中文):
5. 最新配置文件
{
"workbench.colorTheme": "Material Theme",
"workbench.iconTheme": "material-icon-theme",
// 取消 LaTex 保存时自动编译
"latex-workshop.latex.autoBuild.run": "never",
// 去掉编译出错时的气泡
"latex-workshop.message.error.show": false,
"latex-workshop.message.warning.show": false,
// 配置 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": "pdflatex",
"tools": ["pdflatex"]
},
{
"name": "xe->bib->xe->xe",
"tools": ["xelatex", "bibtex", "xelatex", "xelatex"]
},
{
"name": "pdf->bib->pdf->pdf",
"tools": ["pdflatex", "bibtex", "pdflatex", "pdflatex"]
}
],
// 在侧边栏中预览PDF文件
"latex-workshop.view.pdf.viewer": "tab",
// 使用 SumatraPDF 预览编译好的PDF文件
// "latex-workshop.view.pdf.viewer": "external",
// "latex-workshop.view.pdf.external.viewer.command": "E:/SumatraPDF/SumatraPDF.exe",
// "latex-workshop.view.pdf.external.viewer.args": [
// "-forward-search",
// "%TEX%",
// "%LINE%",
// "-reuse-instance",
// "-inverse-search",
// "\"E:/Microsoft VS Code/Code.exe\" \"E:/Microsoft VS Code/resources/app/out/cli.js\" -gr \"%f\":\"%l\"",
// "%PDF%"
// ],
// 配置正向和反向搜索
// "latex-workshop.view.pdf.external.synctex.command": "E:/SumatraPDF/SumatraPDF.exe",
"latex-workshop.view.pdf.external.synctex.args": [
"-forward-search",
"%TEX%",
"%LINE%",
"-reuse-instance",
"-inverse-search",
"\"E:/Microsoft VS Code/Code.exe\" \"E:/Microsoft VS Code/resources/app/out/cli.js\" -gr \"%f\":\"%l\"",
"%PDF%"
],
// LaTex 格式化,好像 latexindent 不支持中文
// "latex-workshop.latexindent.path": "E:/texlive/latexindent/latexindent.exe",
// Prettier + ESLint VSCode config
"editor.formatOnSave": true, // 保存时格式化
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[latex]": {
"editor.defaultFormatter": "James-Yu.latex-workshop"
},
// 自动换行
"editor.wordWrap": "on",
// "[latex]": {
// "editor.defaultFormatter": "nickfode.latex-formatter"
// }
// LaTex 编译时自动删除多余的文件,如果自动删除 .aux 文件,则 \ref{} 会报错; .out 文件被删除也会产生一个警告
"latex-workshop.latex.autoClean.run": "onBuilt", //注意结尾是 t 不是 d
"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"
]
}
6. 参考链接
[1] https://zhuanlan.zhihu.com/p/38178015