Hi,
I was just typing a LaTeX document inside Sublime and I wonder how to launch ie "pdflatex" on it.
I had a look at the docs, but "build", "exec" etc. are not documented.
Thanks for any suggestion.
import sublime, sublimeplugin
import os
class MyPluginCommand(sublimeplugin.TextCommand):
def run(self, view, args):
f = view.fileName();
result = os.system("parser.exe " + f)
def isEnabled(self, view, args):
return True#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sublime, sublimeplugin
import os
class PdfLatexCommand(sublimeplugin.TextCommand):
def run(self, view, args):
f = view.fileName()
print "the file is %s"%f
result = os.system("pdflatex " + f)
def isEnabled(self, view, args):
return TruebuildCommand exec "^(...*?):([0-9]*):?([0-9]*)" pdflatex.exe '"$File"'class MyPluginCommand(sublimeplugin.TextCommand):
def run(self, view, args):
f = view.fileName();
exe = sublime.packagesPath()
exe = os.path.join(exe, "User")
exe = os.path.join(exe, "MyParser.exe")
# Spaces in path workaround:
# add an extra quote (!) before the quoted command name:
# result = os.system('""pythonbugtest.exe" "test"')
# Explanation:
# there was a time when the cmd prompt treated all spaces as delimiters, so
# >cd My Documents
# would fail. Nowadays you can do that successfully and even
# >cd My Documents\My Pictures
# works.
# In the old days, if a directory had a space, you had to enclose it in quotes
# >cd "My Documents"
# But you didn't actually need to include the trailing quote, so you could get away with
# >cd "My Documents
cmd = '""%(exe)s" "%(args)s""' % {'exe' : exe, 'args' : f } # stderr > out.txt 2>&1
result = os.system(cmd)foo.pdf: foo.tex
pdfclose --all
pdflatex -interaction=nonstopmode foo.tex
pdfopen --file foo.pdf
buildCommand exec error-regex command [args].
#
# COMPILE LATEX AND LAUNCH ACROBAT
#
def compilePdf(latexFile):
miktexExe = miktexCommandPath("pdflatex")
commandLine = " --interaction=nonstopmode --aux-directory c:\\temp\\ \"" + latexFile + "\""
# two compiles, to make sure contents etc are up-to-date
for i in range(2):
print runSysCommand(miktexExe, commandLine)
pdf = os.path.splitext(latexFile)[0] + ".pdf"
print "pdf created at '%s'" % pdf
subprocess.Popen(pdf, shell=True)
#
# RUN EXE AND GET OUTPUT
#
def getOutputOfSysCommand(commandText, arguments=None):
"""Returns the output of a command, as a string"""
print "getting output of %s %s" % (commandText, arguments)
p = subprocess.Popen([commandText, arguments], shell=True, bufsize=1024, stdout=subprocess.PIPE)
p.wait()
stdout = p.stdout
return stdout.read()
#
# WHERE DOES MIKTEX LIVE?
#
def miktexCommandPath(commandName):
return os.path.join(programFiles(), "MiKTeX 2.7\\miktex\\bin", commandName + ".exe")
#
# WHERE ARE PROGRAM FILES?
#
def programFiles():
prog32 = "c:\\program files"
prog64 = "c:\\program files (x86)"
if os.path.exists(prog64):
return prog64
elif os.path.exists(prog32):
return prog32
else:
raise Exception("can't find a program files")
Users browsing this forum: No registered users and 10 guests