gpt4 book ai didi

latex - Sublime 文本构建系统 - 如何自动打开 pdf

转载 作者:行者123 更新时间:2023-12-05 01:04:15 30 4
gpt4 key购买 nike

我按照此处提供的说明( How to create a shortcut for user's build system in Sublime Text? )在 xelatex 中编译 latex 文档,最重要的是我还希望它像使用 latexmk 一样在编译后自动打开 pdf,我该如何实现?该文档构建得很好,但我每次都必须手动打开它。

最佳答案

这是 CompileWithXelatexCommand 的扩展在我的默认 PDF 查看器中成功打开 PDF 的实现。

import sublime, sublime_plugin
import os
import time

class CompileWithXelatexCommand(sublime_plugin.TextCommand):
def run(self, edit):
if '/usr/texbin' not in os.environ['PATH']:
os.environ['PATH'] += ':/usr/texbin'

base_fname = self.view.file_name()[:-4]
pdf_fname = base_fname + ".pdf"
self.view.window().run_command('exec',{'cmd': ['xelatex','-synctex=1','-interaction=nonstopmode',base_fname]})

tries = 5
seconds_to_wait = 1
while tries > 0:
if os.path.isfile(pdf_fname):
break
time.sleep(seconds_to_wait)
seconds_to_wait *= 2
tries -= 1

os.system("open " + pdf_fname)

需要轮询循环;否则,open 调用可能会在生成 PDF 之前发生。可能有一种更简洁的方式通过 run_command 同步执行一系列命令.

我现在无法访问 Windows,但来自 this post您可能只需要更改 "open ""start " . PATH 初始化逻辑将需要消除或调整。

关于latex - Sublime 文本构建系统 - 如何自动打开 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23505241/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com