热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

从SublimeText2中的另一个构建系统访问构建系统-AccessabuildsystemfromanotherbuildsysteminSublimeText2

ImattemptingtocreateabuildsystemforknitrSweaveinSublimeText2.Mycurrent,simple(and

I'm attempting to create a build system for knitr/Sweave in Sublime Text 2. My current, simple (and working) build system is as follows:

我正在尝试在Sublime Text 2中为knitr / Sweave创建一个构建系统。我当前的简单(和工作)构建系统如下:

{
    "cmd": ["bash", "-c", "/usr/bin/R64 CMD Sweave '${file_name}' && pdflatex '${file_base_name}.tex' -interaction=nonstopmode -synctex=1 %S -f -pdf && /Applications/Skim.app/Contents/MacOS/Skim '${file_base_name}.pdf'"], 
    "path": "$PATH:/usr/texbin:/usr/local/bin", 
    "selector": "text.tex.latex.sweave","shell":false,
    "file_regex": "^(...*?):([0-9]+): ([0-9]*)([^\\.]+)"
}

(The text.text.latex.sweave context is defined in the Sweave Textmate bundle, which kind of works in Sublime Text)

(text.text.latex.sweave上下文在Sweave Textmate包中定义,哪种在Sublime Text中有效)

The build system takes a .Rnw file, converts it to TeX, and then runs pdflatex on it. This build system works, but it is fairly limited in how it opens Skim (it just opens the PDF—that's all). The LaTeXTools Sublime Text package is far more robust and opens/refreshes Skim while highlighting modified lines and providing Skim's magic reverse search.

构建系统采用.Rnw文件,将其转换为TeX,然后在其上运行pdflatex。这个构建系统可以工作,但它在打开Skim的方式上是相当有限的(它只是打开PDF - 这就是全部)。 LaTeXTools Sublime Text包更加强大,可以在突出显示修改后的线条并提供Skim魔术反向搜索的同时打开/刷新Skim。

I don't want to rewrite the LaTeXTools build system, especially since it does most of the heavy lifting (and Skim magic) with a separate Python script. However, I would really like to be able to use it to build a TeX file generated from Sweave.

我不想重写LaTeXTools构建系统,特别是因为它使用单独的Python脚本完成了大部分繁重的工作(和Skim魔术)。但是,我真的希望能够用它来构建一个从Sweave生成的TeX文件。

Ideally, I'd love to somehow nest a build system—convert an .Rnw file to TeX and then immediately run the LaTeXTools build system that already exists. In pseudocode:

理想情况下,我喜欢以某种方式嵌套构建系统 - 将.Rnw文件转换为TeX,然后立即运行已存在的LaTeXTools构建系统。在伪代码中:

{
    [CONVERT RNW TO ${file_name}.tex && RUN THE LATEXTOOLS BUILD SYSTEM ON ${file_name}.tex]
}

Is it possible to access a build system from inside another build system (or alternatively, access a build system from bash)?

是否可以从另一个构建系统内部访问构建系统(或者从bash访问构建系统)?

2 个解决方案

#1


4  

This is a patch to two files in the LatexTools plugin in order to deal with Rnw files, and one patch to the Latex plugin in order to make Rnw files to behave like LaTeX files.

这是LatexTools插件中的两个文件的补丁,用于处理Rnw文件,以及Latex插件的一个补丁,以使Rnw文件的行为类似于LaTeX文件。

First the patch to the Latex plugin, in specific to the file LaTeX.tmLanguage:

首先是Latex插件的补丁,具体到文件LaTeX.tmLanguage:





    fileTypes
    
        tex
        Rnw
    

Observe how I added an element to the array in order to deal with Rnw extensions.

观察我如何向数组添加元素以处理Rnw扩展。

Now the patch to makePDF.py

现在补丁makePDF.py

look for a a line like this

寻找像这样的一条线

if self.tex_ext.upper() != ".TEX":
    sublime.error_message("%s is not a TeX source file: cannot compile." % (os.path.basename(view.file_name()),))
    return

and replace it with

并替换它

if (self.tex_ext.upper() != ".TEX") and (self.tex_ext.upper() != ".RNW"):
    sublime.error_message("%s is not a TeX or Rnw source file: cannot compile." % (os.path.basename(view.file_name()),))
    return

Then look for a line like

然后寻找像这样的一条线

os.chdir(tex_dir)
CmdThread(self).start()
print threading.active_count()

and replace it with

并替换它

os.chdir(tex_dir)
if self.tex_ext.upper() == ".RNW":
    # Run Rscript -e "library(knitr); knit('" + self.file_name + "')"
    os.system("Rscript -e \"library(knitr); knit('"+ self.file_name +"')\"")
    self.file_name = self.tex_base + ".tex"
    self.tex_ext = ".tex"
CmdThread(self).start()
print threading.active_count()

The last patch is to the file jumpToPDF.py

最后一个补丁是文件jumpToPDF.py

look for a line

寻找一条线

if texExt.upper() != ".TEX":
    sublime.error_message("%s is not a TeX source file: cannot jump." % (os.path.basename(view.fileName()),))
    return

and replace it with

并替换它

if (texExt.upper() != ".TEX") and (texExt.upper() != ".RNW"):
    sublime.error_message("%s is not a TeX or Rnw source file: cannot jump." % (os.path.basename(view.fileName()),))
    return

Good luck!

祝你好运!

#2


1  

Thanks for the detailed description of the required changes Herberto!

感谢Herberto所需更改的详细说明!

I just went ahead and changed the mentioned files. Everything works like a charm! One thing is though, not sure if it is required, but I recompiled both python files to .pyc after editing them.

我刚才继续改变了上面提到的文件。一切都像魅力一样!但有一点是,不确定是否需要,但我在编辑后将两个python文件重新编译为.pyc。

python -m py_compile makePDF.py

does the job. Should anyone run into an "invalid syntax error" at the line

做的工作。如果有人在该行遇到“无效的语法错误”

print threading.active_count()

while recompiling, just replace it with:

重新编译时,只需将其替换为:

print(threading.active_count())

Also, since the log parser of LaTeXTools only displays errors from the log files, we might be interested to see the knitr output as well. You can store it in a separate log file by replacing:

此外,由于LaTeXTools的日志解析器仅显示日志文件中的错误,我们可能也有兴趣看到knitr输出。您可以通过替换来将其存储在单独的日志文件中:

os.system("Rscript -e \"library(knitr); knit('"+ self.file_name +"')\"")

with:

有:

    knitcmd = "/usr/bin/Rscript -e \"library(knitr); knit('"+ self.file_name +"')\""
    process = subprocess.Popen(knitcmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    #Launch the shell command:
    knit_output, knit_error = process.communicate()
    #store results in a log
    knit_log = open(self.tex_base + "_knitrbuild.log", "w")
    knit_log.write(knit_output)
    knit_log.write(knit_error)
    knit_log.close()

Before I was using a simple bash script to build the documents (Mac specific):

在我使用简单的bash脚本构建文档之前(特定于Mac):

#!/bin/bash
[ $# -eq 0 ] && { echo "Usage: $0 file.Rnw for knitting"; exit 1; }
rnw="library(knitr);knit("\'"$1.Rnw"\'")"
echo "Rscript executing:" $rnw
tex="$1.tex"
pdf="$1.pdf"
Rscript -e $rnw && pdflatex $tex && pdflatex $tex && open -a Preview $pdf

retval=$?
[ $retval -eq 0 ] && echo "$rnw knitted and $pdf ready"

but being able to customize LaTeXTools and run it directly from ST2 with Skim support is very nice.

但能够自定义LaTeXTools并直接从ST2运行它与Skim支持是非常好的。

Is there any reasons why you wouldn't want to add the changes you outlined directly into your package source? (maybe my it's only my version that's too old.)

您是否有任何理由不想将您概述的更改直接添加到包源中? (也许我只是我的版本太旧了。)


推荐阅读
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
  • 分享2款网站程序源码/主题等后门检测工具
    本文介绍了2款用于检测网站程序源码和主题中是否存在后门的工具,分别是WebShellkiller和D盾_Web查杀。WebShellkiller是一款支持webshell和暗链扫描的工具,采用多重检测引擎和智能检测模型,能够更精准地检测出已知和未知的后门文件。D盾_Web查杀则使用自行研发的代码分析引擎,能够分析更为隐藏的WebShell后门行为。 ... [详细]
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • 本文整理了Java面试中常见的问题及相关概念的解析,包括HashMap中为什么重写equals还要重写hashcode、map的分类和常见情况、final关键字的用法、Synchronized和lock的区别、volatile的介绍、Syncronized锁的作用、构造函数和构造函数重载的概念、方法覆盖和方法重载的区别、反射获取和设置对象私有字段的值的方法、通过反射创建对象的方式以及内部类的详解。 ... [详细]
  • 云原生边缘计算之KubeEdge简介及功能特点
    本文介绍了云原生边缘计算中的KubeEdge系统,该系统是一个开源系统,用于将容器化应用程序编排功能扩展到Edge的主机。它基于Kubernetes构建,并为网络应用程序提供基础架构支持。同时,KubeEdge具有离线模式、基于Kubernetes的节点、群集、应用程序和设备管理、资源优化等特点。此外,KubeEdge还支持跨平台工作,在私有、公共和混合云中都可以运行。同时,KubeEdge还提供数据管理和数据分析管道引擎的支持。最后,本文还介绍了KubeEdge系统生成证书的方法。 ... [详细]
  • 使用Ubuntu中的Python获取浏览器历史记录原文: ... [详细]
  • 本文介绍了Hyperledger Fabric外部链码构建与运行的相关知识,包括在Hyperledger Fabric 2.0版本之前链码构建和运行的困难性,外部构建模式的实现原理以及外部构建和运行API的使用方法。通过本文的介绍,读者可以了解到如何利用外部构建和运行的方式来实现链码的构建和运行,并且不再受限于特定的语言和部署环境。 ... [详细]
  • 本文介绍了Linux系统中正则表达式的基础知识,包括正则表达式的简介、字符分类、普通字符和元字符的区别,以及在学习过程中需要注意的事项。同时提醒读者要注意正则表达式与通配符的区别,并给出了使用正则表达式时的一些建议。本文适合初学者了解Linux系统中的正则表达式,并提供了学习的参考资料。 ... [详细]
  • 本文介绍了如何使用python从列表中删除所有的零,并将结果以列表形式输出,同时提供了示例格式。 ... [详细]
  • 本文介绍了Android 7的学习笔记总结,包括最新的移动架构视频、大厂安卓面试真题和项目实战源码讲义。同时还分享了开源的完整内容,并提醒读者在使用FileProvider适配时要注意不同模块的AndroidManfiest.xml中配置的xml文件名必须不同,否则会出现问题。 ... [详细]
  • 前景:当UI一个查询条件为多项选择,或录入多个条件的时候,比如查询所有名称里面包含以下动态条件,需要模糊查询里面每一项时比如是这样一个数组条件:newstring[]{兴业银行, ... [详细]
  • 本文介绍了Shell中for命令的基本格式和用法,通过提供一个值列表来迭代执行一系列命令。同时还介绍了如何读取列表中的值,并给出了for命令与其他命令的结合使用示例。 ... [详细]
  • 本文介绍了使用Python解析C语言结构体的方法,包括定义基本类型和结构体类型的字典,并提供了一个示例代码,展示了如何解析C语言结构体。 ... [详细]
  • 基于Socket的多个客户端之间的聊天功能实现方法
    本文介绍了基于Socket的多个客户端之间实现聊天功能的方法,包括服务器端的实现和客户端的实现。服务器端通过每个用户的输出流向特定用户发送消息,而客户端通过输入流接收消息。同时,还介绍了相关的实体类和Socket的基本概念。 ... [详细]
author-avatar
mobiledu2502852923
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有