VSCode + LaTeX的一些配置

tech2022-08-27  121

VSCode + LaTeX的一些配置


Update::

{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "latex_compile", "type": "shell", "command": [ "cd ${fileDirname} \n", "latex -interaction nonstopmode ${fileBasename} \n", "latex -interaction nonstopmode ${fileBasename} \n", "latex -interaction nonstopmode ${fileBasename} \n", "dvips ${fileBasenameNoExtension}.dvi \n", "ps2pdf ${fileBasenameNoExtension}.ps \n" ], "problemMatcher": [] } ] }

将这一段代码放在全局tasks.json中 (我的路径在: )

重启vsc, CTRL+SHIFT+P → \to Run Task → \to latex_compile即可编译.


该配置达到: 不用敲终端代码, 自动编译+自动在文中可指定位置插入实时字数+自动打开浏览器预览

安装LaTeX Workshop插件,在插件设置里禁用所有的有关自动编译(build)的功能。(不装也可以。为了写tex时使用自动补全,把它装上。)编写./.vscode/tasks.json: { // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "compile_and_view", "type": "shell", "command": "compile_paper.bat", "problemMatcher": [] } ] } 编写批处理文件./compile_paper.bat(for Windows): texcount paper.tex >> wordcount.tex python wordcount.py latex -interaction nonstopmode paper.tex latex -interaction nonstopmode paper.tex dvips paper.dvi ps2pdf paper.ps del paper.aux del paper.dvi del paper.log del paper.ps del x.log del paper.toc C:\Progra~1\Mozill~1\firefox.exe .\paper.pdf 编写python脚本./wordcount.py f = open("wordcount.tex", "r") for i in range(2): f.readline() wit = int(f.readline()[15 : -1]) wih = int(f.readline()[18 : -1]) wot = int(f.readline()[37 : -1]) wc = wit + wih + wot f.close() f = open("wordcount.tex", "w") f.write(str(wc)) f.close()

使用:

想要在论文paper.tex里插入编译时文章的字数,在插入的地方写

\input{wordcount.tex}

(不要插入字数就不写)

编译: CTRL + SHIFT + P -> 选择Tasks: Run Task -> 选择compile_and_view

这时会自动编译并且编译完成后用浏览器打开。 我是路径为C:\Progra~1\Mozill~1\firefox.exe的火狐在浏览器。不同浏览器/安装路径的话 将compile_paper.bat里的这一行中的浏览器路径改成你的浏览器的路径就行了 不想要他自动打开浏览器预览的话把这行删掉就行了

最新回复(0)