之前写过一篇windows下的,现在重新总结一下,主要是可以支持ubuntu了。其实从功能上是比上一篇少了一个win32 api隐藏控制台。

采用的编程语言为ruby,窗体程序为 ruby 的 tk。
最后实现的效果为 用notepad++或其他软件编辑,可以自动编译,实时查看(实时查看需要 sumatrapd (in windows) 或者 okular (in ubuntu))。

@20-2-25 修改,增加检测数据文件,支持定义临时文件目录。

安装ruby 和 tk

ruby 2.4以后应该直接可以gem install tk,非常方便。虽然ubuntu默认的ruby 版本比较低,但是可以通过如下方式提高ruby的版本:

sudo apt-get install software-properties-common
sudo apt-add-repository ppa:brightbox/ruby-ng
sudo apt-get updatesudo apt-get install ruby2.6 ruby2.6-dev
sudo apt-get install ruby-switch
sudo ruby-switch --set ruby2.6gem install tk

windows上的话直接官网下载,安装的时候注意选择tk,没有的话就gem装。

安装latex

主要我们需要有以下几个文件
pdflatex[.exe]
bibtex[.exe] 如果不需要bib这个自然不会用到,但是安装latex之后都会有这个。

代码

就一个文件,然后包括一个配置文件 config.yaml
程序文件

# -*- coding:utf-8 -*-
FILEPATH=File.expand_path("..",__FILE__);
$LOAD_PATH.unshift FILEPATH if !$LOAD_PATH.include? FILEPATHDir::chdir( FILEPATH )# 长虹剑 2015-11-16 bibtex是后续修改的
=begin
@main_file 这个我先固定了
编译时间,及是否编译可以控制
使用了TK,又让我对窗体编程有所了解,而且对ruby的对象机制有所了解。root=TkRoot.new  生成一个类class<<root写你自己要加入的东西end定义各种部件的时候要传入root,一些控制的东西都通过root,所以root这个single类要定义好Tk.mainloop运行----------------------------- TK 布局等说明
http://www.tutorialspoint.com/ruby/ruby_tk_button.htm button=end
require 'yaml'
require 'tk'
require 'Win32API'root=TkRoot.new{title 'latex即时编译工具-made by CHJ'}
# my_object.instance_eval {}
class <<root #只有在root类中的才可以 ******attr_accessor :compiler,:thread  #不属于自己的不能直接用@def run_base@compiler=Latex_runtime_complie.new@compiler.load_config@compiler.sleep_time=3@compiler.listen_control=:run #隐藏掉控制台 这个API改了@console_hand=Win32API.new('kernel32', 'GetConsoleWindow', 'i', 'l').call(0)@show_console=falsetrigger_console
end  #rundef trigger_consoleif @show_console==trueWin32API.new('user32', 'ShowWindow', 'li', 'i').call(@console_hand, 0)@show_console=falseelseWin32API.new('user32', 'ShowWindow', 'li', 'i').call(@console_hand, 1)@show_console=trueend
endclass Latex_runtime_complieattr_accessor :listen_controlattr_accessor :sleep_timedef initialize@is_bibtex="T"@config_file=FILEPATH+"/config.yaml"@latex_file_path=""@latex_file="LaTeX1"#多线程控制@sleep_time=5@listen_control=:run # run 正常 pause 暂停 stop 退出@last_file_mtime=[] enddef load_config#p `pwd`#puts Dir.pwd data = YAML.load_file(@config_file)@pdflatex_exe=data['config']['pdflatex_exe']@bibtex_exe=data['config']['bibtex_exe']@is_bibtex=data['config']['is_bibtex']@latex_file_path=data['config']['latex_file_path']@latex_file=data['config']['latex_file']edit_files=data['config']['edit_file']@main_file=@latex_file_path+"/"+@latex_file+".tex" @edit_file=[ @config_file ]for e in edit_files@edit_file.push @latex_file_path+"/"+e #+".tex" end@output_directory=data['config']['output_directory']p @main_file, @edit_file@argument=%Q[-synctex=-1 -interaction=nonstopmode "#{@main_file}" ]#puts @argument@latex_cmd="#{@pdflatex_exe} -output-directory=#{@output_directory} #{@latex_file}"@bib_cmd="#{@bibtex_exe} #{@output_directory}/#{@latex_file}"# ***** 这里修改运行目录@argument = "-output-directory=#{@output_directory} #{@argument}"Dir.chdir(@latex_file_path)puts Dir.pwd enddef compile#puts @pdflatex_exe+""+@argumentif @is_bibtex=="T"puts system(@latex_cmd)puts system(@bib_cmd);puts system(@latex_cmd);endputs system(@pdflatex_exe+" "+@argument);#system(@pdflatex_exe+" "+@argument);enddef get_mtimeres=[]for e in @edit_fileres.push File.mtime(e)endreturn resenddef is_different(a, b)a.zip(b).each_with_index do |e, id|return id+1 if e[0] != e[1]endreturn 0end##  核心,通过文件修改时间决定是否重新编译def listeningcompilebgs=get_mtimewhile truecase @listen_controlwhen :runeds = get_mtimercode = is_different( bgs, eds )if rcode!=0load_config if rcode==1bgs=edscompileendwhen :pausewhen :stop@last_file_mtime=bgsreturnendsleep(@sleep_time)endend
end #class Latex_runtime_complieend #添加的类属性#相当于设置了主窗体
TkLabel.new {width 15height 3#packgrid('row'=>0, 'column'=>0)
}
BTrun=TkButton.new(root){text " 运行 "width 8#height 1#pack :padx=>2,:pady=>2,:side=>'bottom'grid('row'=>0, 'column'=>3,'padx'=>5,'pady'=>5)command{root.compiler.listen_control=:runif root.thread && root.thread.alive?root.thread.exitendroot.thread = Thread.new {root.compiler.listening}BTstop.state="normal"BTrun.state="disabled"}
}BTstop=TkButton.new(root){text " 停止 "width 8state "disabled"#pack :padx=>3,:pady=>2,:side=>'bottom'grid('row'=>1, 'column'=>3,'padx'=>5,'pady'=>5)command{root.compiler.listen_control=:stop  if root.threadBTrun.state="normal"BTstop.state="disabled"}
}
TkButton.new(root){text "exit"#pack :padx=>2,:pady=>2,:side=>'bottom'grid('row'=>0, 'column'=>0,'padx'=>5,'pady'=>5) #,'columnspan'=>2command{if root.threadroot.thread.exit if root.thread.alive?endexit}
}
var=TkVariable.new
TkEntry.new(root){text var  #这个变量就会不断被监控width 5grid('row'=>1, 'column'=>1)
}
TkButton.new(root){text "set"#pack :padx=>2,:pady=>2,:side=>'bottom'grid('row'=>1, 'column'=>0,'padx'=>5,'pady'=>5)command{if var=~/\d+/var=var.to_iif var>=1root.compiler.sleep_time=var#puts varendend}
}TkButton.new(root){text "控制台"#pack :padx=>2,:pady=>2,:side=>'bottom'grid('row'=>0, 'column'=>1,'padx'=>5,'pady'=>5)command{root.trigger_console}
}root.run_base
Tk.mainloop

配置文件为

config:is_bibtex: Tpdflatex_exe: /usr/bin/pdflatexbibtex_exe: /usr/bin/bibtexlatex_file_path: /data/tools/tex_file_dir/latex_file: main_tex_file_nameedit_file: [Tex/chap-02.tex]output_directory: Tmp

edit_file 这个是程序监听修改的,只要这个改动就会重新编译。(已经改成了数组,可多个问价 [a, b])
latex_file 这是你主 tex 文件。
上面那两个可以不用写.tex后缀
is_bibtex 是否用bibtex [T/F]
output_directory 临时目录,供latex产生

软件介绍


注意控制台还是有必要的,如果语法出现什么问题可能导致编译卡主,这样修改之后需要你手动敲回车。(在ubuntu中由于程序一般就是在控制台中运行的,因此一定会有)

其中set 可以设置每多少秒检查一次文件是否被改动。

latex自动编译 (ubuntu/win)相关推荐

  1. 用ruby实现latex自动编译

    由于时间久远,这里就写出当时制作的大致思路. 基本思想是,另外开一个线程,每隔一段时间检测你的latex文件是否有改动,如果有改动则调用latex程序编译一下.如果使用bibtex的话注意需要有四个过 ...

  2. linux(以ubuntu为例)下Android利用ant自动编译、修改配置文件、批量多渠道,打包生成apk文件...

    原创,转载请注明:http://www.cnblogs.com/ycxyyzw/p/4555328.html  之前写过一篇<windows下Android利用ant自动编译.修改配置文件.批量 ...

  3. linux下ant编译android,linux(以ubuntu为例)下Android利用ant自动编译、修改配置文件、批量多渠道,打包生...

    之前写过一篇<windows下Android利用ant自动编译.修改配置文件.批量多渠道,打包生成apk文件>,关于ant打包原理,请先阅读这篇文章.再次不再赘述. 我使用的Linux环境 ...

  4. linux(以ubuntu为例)下Android利用ant自动编译、修改配置文件、批量多渠道,打包生...

    之前写过一篇<windows下Android利用ant自动编译.修改配置文件.批量多渠道,打包生成apk文件>,关于ant打包原理,请先阅读这篇文章.再次不再赘述. 我使用的Linux环境 ...

  5. 用shell写了一个自动编译代码的脚本

    点击打开链接 为了充分利用晚上的时间进行编译,用shell写了一个自动编译代码的脚本,这样保证第二天的调试工作不会受大版本编译的影响,同时也能监测服务器端的代码是否出错.我习惯是在每天下班离开之前运行 ...

  6. ts文件编译与运行,vscode自动编译

    ts文件编译与运行 根据官方文档提示,ts文件无法直接运行,需要编译成js文件. 1.那么问题就来了,如何把ts文件编译成js文件呢? 官方文档说,Visual Studio 2017和Visual ...

  7. VSCode + Latex +Texlive 编译 biber格式参考文献时 VSCode的配置方法

    { "editor.fontSize": 17, "files.autoSave": "onFocusChange", "late ...

  8. 【Ubuntu】安装Ubuntu+Win双系统后,每次开机默认是进入Ubuntu,如何设置成默认进入Win?

    1.问题描述 安装Ubuntu+Win双系统后,每次开机默认是进入Ubuntu,如何设置成默认进入Win? 2.解决方法 1)记住开机选择中windows 10是第几个,从0开始记,如下图本人的是4 ...

  9. installshield 2009实现安装包自动编译

    1.根据当前日期,在服务器上建立一个以日期命名的文件夹,删除本地现有的文件夹并下载最新的文件到本地 call mydate %DATE% Rem Copy files from common fold ...

最新文章

  1. javascript跨域实践
  2. 如何查看默认root密码?
  3. vba遍历数组_VBA代码解决方案的第59讲内容:如何在代码运行时创建数组
  4. ngTemplateOutlet递归的问题
  5. C语言中指针的使用方法
  6. for-each 循环原理
  7. 代码收藏——js+asp 的屏幕滚动脚本
  8. SignalR ——Android实践
  9. MySQL concat()函数
  10. 【SpringBoot 2】(一)基础知识了解学习
  11. 浅谈Scala 2.8的包对象(package object)
  12. tcp的粘包和拆包示例以及使用LengthFieldFrameDecoder来解决的方法
  13. RabbitMQ工作模式Publish/Subscribe发布订阅,test测试代码
  14. 数字化时代,需要数据思维!
  15. html登录页面验证码代码怎么写,js实现登录验证码
  16. FFMPEG推流到RTMP服务器命令
  17. 读书笔记 - Thoughts on interaction design (第二版) - 交互设计沉思录
  18. 计算机四级网络工程师知识点(非常全面!)
  19. Win8快捷键的使用
  20. 液化石油气(LPG)的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告

热门文章

  1. ps如何切html用的图片,前端实战(一)-----用ps把PSD切成HTML能用的图片
  2. 年轻人要对自己狠一点
  3. 选择SAP IBP(集成业务计划云)的十大理由
  4. 如何将Jenkins基础环境迁移到Docker?
  5. Linux怎么彻底删除用户
  6. 劳务派遣员工转正制度是什么
  7. The software-quanlity landscape -- Code complete reading notes
  8. 如何开发一款用户体验优秀的语音交友app?
  9. 推荐一款自动更新 Docker 镜像与容器的神器 Watchtower
  10. Python+Excel数据分析实战:军事体能考核成绩评定(一)项目概况