def tex2pdf(target, source, env): """ Translate SVG files to EPS """ (pathname, ext) = os.path.splitext(target[0].abspath) assert (ext in [".pdf"]) tmpname = os.path.join(tempfile.gettempdir(), tempfile.gettempprefix()) tmptexname = tmpname + ".tex" tmppdfname = tmpname + ".pdf" tmppcropname = tmpname + ".crop.pdf" shutil.copy(source[0].abspath, tmptexname) command = os.path.join( env.project_db['paths']['tex'], 'xelatex -interaction nonstopmode "%(tmptexname)s"' % vars()) curdir = os.getcwd() os.chdir(tempfile.gettempdir()) cutefilter = mf.CuteFilter(tempfile.gettempdir()) out = "Mock:" + command out = ut.get_prog_output(command) out = cutefilter(out) #print out.encode("utf8") os.system(command) print os.environ['PATH'] print "!!", command command = os.path.join( env.project_db['paths']['tex'], "".join(['pdfcrop "', tmppdfname, '" "', target[0].abspath, '"'])) os.system(command) os.chdir(curdir)
def pdfbeamlatex(target, source, env): """ PDFLatex-обработка для слайдов. """ filename = str(source[0].abspath) (path, nameext) = os.path.split(filename) (name, ext) = os.path.splitext(nameext) outpdf = os.path.join(path, "--obj", name) + ".pdf" outpdfsync = os.path.join(path, "--obj", name) + ".synctex" outlog = os.path.join(path, "--obj", name) + ".log" pdfsync = os.path.join(path, name) + ".synctex" texlog = os.path.join(path, name) + ".log" curdir = os.getcwd() beamdir = path os.chdir(path) ut.createdir("--obj") command = ''.join([ r'xelatex -synctex=-1 -file-line-error-style -output-directory="--obj" ', ' -interaction nonstopmode "', nameext, '"']) print os.environ["PATH"] print command #texfilter = tx.TeXFilter(path) cutefilter = mf.CuteFilter(path) out= "Mock:" + command out = ut.get_prog_output(command) out = cutefilter(out) print out.encode("utf8") env.warnings += cutefilter.warnings ut.string2file("\n".join(env.warnings), filename + ".warnings") outbcffile = os.path.join(path, "--obj", name) + ".bcf" if os.path.exists(outbcffile): os.chdir('--obj') command = os.path.join(env.project_db['paths']['tex'], 'biber "%(outbcffile)s"' % vars()) os.system(command) os.chdir('..') mkidx.makeindex(env, filename) shutil.copyfile(outpdf, target[0].abspath) if os.path.exists(outpdfsync): shutil.copy(outpdfsync, pdfsync) if os.path.exists(outlog): shutil.copy(outlog, texlog) os.chdir(curdir)
def main(): """ Call SumatraPDF View, try to synchronize line number """ filename = str(os.path.abspath(sys.argv[1])) (path, nameext) = os.path.split(filename) (name, ext) = os.path.splitext(nameext) respdf = os.path.join(path, name) + ".pdf" outpdf = os.path.join(path, "--obj", name) + ".pdf" outpdfsync = os.path.join(path, "--obj", name) + ".pdfsync" pdfsync = os.path.join(path, name) + ".pdfsync" curdir = os.getcwd() os.chdir(path) ut.createdir("--obj") command = ''.join([ r'xelatex -synctex=1 -file-line-error-style -output-directory="--obj" ', ' -interaction nonstopmode "', nameext, '"']) os.environ['PATH'] = ';'.join([r'c:\app\docstruct\xetex\bin\win32', os.environ['PATH'] ]) print os.environ["PATH"] print command texfilter = tx.TeXFilter(path) out = ut.get_prog_output(command) out = texfilter(out) print out.encode("utf8") shutil.copyfile(outpdf, respdf ) if os.path.exists(outpdfsync): foutpdfsync = open(outpdfsync, "r") fpdfsync = open(pdfsync, "w") for line in foutpdfsync.readlines(): if line.startswith("("): realpath = os.path.realpath(line[1:-1]) if not realpath[-4:-3] == ".": realpath = realpath + ".tex" newline = "(" + realpath.replace('\\','/') + "\n" else: newline = line fpdfsync.write(newline) fpdfsync.close() foutpdfsync.close() os.chdir(curdir)
def python_run(target, source, env): """ Запуск Python-файла """ filename = str(source[0].abspath) (path, nameext) = os.path.split(filename) (name, ext) = os.path.splitext(nameext) extract_algorithms(filename, env) curdir = os.getcwd() os.chdir(path) scmd = ''.join([env.project_db['paths']['python'], '\\python "', filename, '" ', '--output="', path, '/--obj/', nameext, '.obj/log.out"', ]) #command = ('python "%s" --quiet --batchmode --output="%s/--obj/%s.obj/log.out"' # % (filename, path, nameext) ) cutefilter = mf.CuteFilter(path) out = ut.get_prog_output(scmd) out = cutefilter(out) print out.encode("utf8") env.warnings += cutefilter.warnings #pattern = "%s/*" % (os.path.split(target[0].abspath)[0]) #for f in glob.glob(pattern): # if os.path.splitext(f)[1] == ".svg": # svgtarget = lib.get_target(f,"svg.eps") # env.Command(svgtarget, f, [inkscape]) # if os.path.splitext(f)[1] in [".dot", ".neato", ".fdp"]: # svgfilename = lib.get_target(f,"obj.svg") # env.Command(svgfilename, f, [transformation.dot2svg]) # epsfilename = lib.get_target(f,"obj.eps") # env.Command(epsfilename, svgfilename, [inkscape]) # pdffilename = lib.get_target(f,"obj.pdf") # env.Command(pdffilename, svgfilename, [inkscape]) os.chdir(curdir)