LaTeX build server in Ruby
So — I’ve been writing functional specs at work in LaTeX, a system for writing documents in a code-y markup language. Seems to fit nicely with being in a programmer headspace. The only thing, really, is that you have to compile your document. A bit of a ballache. But — I’ve also been learning Ruby, and found it easy to knock up a program that sits patiently waiting for you to save your .tex source file, then recompiles it in the background.
So, if you want to use it, here’s how it works;
- modify the script below to point to your own latex distribution and source file.
- run the script to start the ‘build server’
- open your
.texfile, make a change, and save it. - watch your ruby program spring to life and compile to a
.dvifile - Open that
.dvifile in a viewer; I’m usingyap. - make more changes to your
.texfile. Every time you save it, the .dvi file will be updated, andyapwill reload it, giving you instant feedback on your changes. It’s just like a wysiwyg editor! almost!
enjoy;
#
# LaTeX build server!
#
# Steve Cooper
#
file = "c:\\documents and settings\\steve\\Desktop\\bulk-activation-specification.tex"
cmd = "\"C:\\Program Files (x86)\\MiKTeX 2.7\\miktex\\bin\\latex.exe\" --interaction=nonstopmode \"" + file + "\""
print "Compilation command:\n #{ cmd }\n\n"
class String
def mtime
File.new(self).mtime
end
end
lastmtime = file.mtime
while true
currentTime = file.mtime
if (currentTime > lastmtime) then
print "file modified at " + currentTime.to_s
lastmtime = currentTime
print "Compiling " + file + "\n"
system cmd
end
print ". "
sleep 1
end