目前已经习惯了VS Code写代码,虽然有很多奇葩的地方,但是至少界面看起来比较舒服。LaTeX除了Overleaf,之前使用的是TeX Maker,感觉界面太原始了,就想换成VS Code,参考了下面几个教程:
https://zhuanlan.zhihu.com/p/38178015
https://blog.csdn.net/edward_zcl/article/details/114155507
http://wap.sciencenet.cn/home.php?mod=space&do=blog&id=1251549
很多内容我就不详细介绍了,大家看看这些教程就明白。强调几点:
安装好LaTeX Workshop之后,在VS Code的界面中按F1打开Settings.json,然后这个json文件中增加以下内容:
"latex-workshop.latex.recipes": [
{
"name": "pdflatex -> bibtex -> pdflatex*2",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
}
],
"latex-workshop.latex.tools": [{
"name": "latexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"%DOC%"
]
}, {
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
}, {
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
}, {
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
}],
// "latex-workshop.view.pdf.viewer": "tab",
"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.view.pdf.viewer": "external",
"latex-workshop.view.pdf.ref.viewer":"external",
// "latex-workshop.view.pdf.external.viewer.command": "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe",
"latex-workshop.view.pdf.external.viewer.command": "D:/Program Files/SumatraPDF/SumatraPDF.exe",
"latex-workshop.view.pdf.external.viewer.args": [
"%PDF%"
],
"latex-workshop.view.pdf.external.synctex.command": "D:/Program Files/SumatraPDF/SumatraPDF.exe",
// "latex-workshop.view.pdf.external.synctex.command": "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe",
"latex-workshop.view.pdf.external.synctex.args":[
"-forward-search",
"%TEX%",
"%LINE%",
"-reuse-instance",
"-inverse-search",
// "\"D:/Program Files/Microsoft VS Code/Code.exe\" -r -g \"%f\":%l",
"\"D:/Program Files/Microsoft VS Code/Code.exe\" \"D:/Program Files/Microsoft VS Code/resources/app/out/cli.js\" -r -g \"%f:%l\"",
"%PDF%"
],
(CSDN感觉不能用了,代码段点不出来)。需要注意的是,大家可以看到预览PDF的工具我尝试了好几个,只有目前用SumatraPDF以及目前这种配置可以实现正向搜索和反向搜索。另外,如果这个json中本来就有内容,可以把上面的这些填到后面,但有可能向我一样,前面的一个设置选项后面没有逗号:"python.languageServer": "Pylance" 导致会报Expected Comma,这时候只需要给前面加上逗号即可。另外,VS Code的路径大家要改成自己机子上的。
另外,如果不能正常换行的话,把View——Toggle Word Wrap前的对号选上即可。
2021年6月10日更新:发现这样默认安装的话,LaTeX没有拼写检查的功能,解决方法也很简单,在VS Code Extension里搜索“LTeX”即可,具体可以参考这里:https://zhuanlan.zhihu.com/p/92670838