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 __init__(self): self.start_time = time.time() self.time_limit = 36 * 2 self.debug_mode = True self.deadline = self.start_time + self.time_limit self.tex_template = r""" \documentclass{minimal} \usepackage{amssymb} \setlength\arraycolsep{10pt} \setlength\tabcolsep{16pt} \setlength\arrayrulewidth{.3pt} \usepackage{xecyr} \XeTeXdefaultencoding "utf-8" \XeTeXinputencoding "utf-8" \defaultfontfeatures{Mapping=tex-text} \setmonofont{Consolas} \usepackage{color} \usepackage{fancyvrb} \usepackage[russian,english]{babel} \begin{document} %(tex)s \end{document} """ self.lines = [] myfilename = sys._getframe(2).f_code.co_filename #pylint: disable=W0212 mypath, mynameext = os.path.split(myfilename) self.basename = os.path.splitext(mynameext)[0] self.objdir = os.path.join(mypath, "--obj", mynameext + ".obj") if not os.path.exists(self.objdir): ut.createdir(self.objdir) self.prefix = os.path.join(self.objdir, "") self.dotprefix = os.path.join(self.objdir, "dot") self.svgprefix = os.path.join(self.objdir, "svg") self.texprefix = os.path.join(self.objdir, "tex") self.options, args, parser = process_cmd_line() #pylint: disable=W0612 if self.options.outputfile: sys.stdout = open(self.options.outputfile, "w") self.experiment_scale = 10 self.experiment_trycount = 2 self.debug_mode = True self.sprite_count = 1 self.random_source = random.Random(time.time())
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 register_pdf(self, filename): if os.path.sep not in filename: filename = os.path.join(self.env.GetLaunchDir(), filename) pathname = os.path.splitext(os.path.abspath(filename))[0] path, name = os.path.split(pathname) target = os.path.realpath(pathname + ".pdf") source = os.path.realpath(pathname + ".tex") metafile = lib.get_target(source, self.META_FILE) depsfile = lib.get_target(source, self.DEPS_FILE) cmd = self.env.Command(depsfile, metafile, self.meta2deps) cmd = self.env.Command(metafile, source, self.extract_meta) cmd = self.env.Command(target, [source, depsfile], actions.pdfbeamlatex) auxfile = os.path.join(path, '--obj', name + '.aux') if not os.path.exists(auxfile): ut.createdir(os.path.split(auxfile)[0]) ut.string2file("", auxfile) self.env.Depends(cmd, auxfile) self.env.Precious(target)