如何在Sublime Text中为用户的构建系统创建快捷方式? [英] How to create a shortcut for user's build system in Sublime Text?

查看:127
本文介绍了如何在Sublime Text中为用户的构建系统创建快捷方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚通过在Sublime Text的User目录中创建一个名为XeLaTeX.sublime-build的文件来创建了一个名为XeLaTeX的构建系统,该文件的内容为:

I've just created a build system named XeLaTeX by creating a file named XeLaTeX.sublime-build in the User directory of Sublime Text, whose content is:

{
    "cmd": ["xelatex.exe","-synctex=1","-interaction=nonstopmode","$file_base_name"]
}

如果我想将 F1 密钥绑定到此特定的构建系统,该怎么办?

What should I do, if I want to bind my F1 key to this specific build system?

注意: Ctrl + B ,不应影响默认的构建系统.也就是说,我可以使用 Ctrl + B 来使用默认值,新的系统键 F1 也可以同时使用.

Note: Ctrl + B, the default build system should not be influenced. That is to say, I could use Ctrl + B to use the default one, and the key F1, the new system, is also available at the same time.

也许还有另一种方法可以实现这一目标.在Default(Windows).sublime-keymap中添加以下文本将执行命令:

Maybe there is another way to achieve this. Add the following text to Default(Windows).sublime-keymap will execute the command:

{"keys": ["f1"], "command": "exec", "args": {"cmd": ["xelatex.exe","-synctex=1","-interaction=nonstopmode","$file_base_name"]}},

但是,此处未定义$file_base_name.有什么方法可以将当前文件(base_)名称传递给exec?

However, $file_base_name is not defined here. Is there any method to pass current file (base_)name to exec?

推荐答案

我自己钉了钉子.

AFAIK,没有通过键绑定传递当前文件名的方法,并且不可能使用键绑定来指定特定的构建系统.因此,必须编写Python脚本.

AFAIK, there is no such a way to pass current file name through key binding, and it's not possible to use key binding to specify a certain build system. Thus, writing a Python script is of necessity.

只有三个步骤.

1..将以下内容保存到/Data/Package/User/compile_with_xelatex.py:

1. Save the following content to /Data/Package/User/compile_with_xelatex.py:

import sublime, sublime_plugin

class CompileWithXelatexCommand(sublime_plugin.TextCommand):
   def run(self, edit):
      self.view.window().run_command('exec', {'cmd': ["xelatex.exe","-synctex=1","-interaction=nonstopmode", self.view.file_name()[:-4]]})

2..在/Data/Packages/User/Default(<your-plat>).sublime-keymap

{"keys": ["f1"], "command": "compile_with_xelatex"},

3..使用Sublime Text打开LaTeX源文件,然后按 F1 用XeLaTeX对其进行编译.

3. Open your LaTeX source file with Sublime Text, and then press F1 to compile it with XeLaTeX.

的确,这有点棘手,但对我来说却像是一种魅力.

Indeed, it's a little tricky, but it works like a charm for me.

这篇关于如何在Sublime Text中为用户的构建系统创建快捷方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆