VSCode + LaTeX的一些配置

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即可编译.


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

  1. 安装LaTeX Workshop插件,在插件设置里禁用所有的有关自动编译(build)的功能。(不装也可以。为了写tex时使用自动补全,把它装上。)
  2. 编写./.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": []
        }
    ]
}

  1. 编写批处理文件./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
  1. 编写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()
  1. 使用:

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

    \input{wordcount.tex}
    

    (不要插入字数就不写)

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值