def deps_scan(self, node, env, path): """ «Сканируем» deps-файл, возвращаем зависимости. """ # pylint: disable=R0201 contents = node.get_contents().replace('\r', '') deps = [] if contents: deps = contents.split('\n') metapath = os.path.join(os.path.split(node.abspath)[0], self.META_FILE) for dep in copy.copy(deps): deps += self.analyze_dep(dep, env) ext = os.path.splitext(dep)[1] if ext in ['.tex']: meta = lib.get_target(dep, self.META_FILE) cmd = env.Command(meta, dep, self.extract_meta) deps.append(meta) fulldep = lib.get_target(dep, self.DEPS_FILE) cmd = env.Command(fulldep, meta, self.meta2deps) deps.append(fulldep.strip()) deps.append(metapath) #deps.append(r'C:\app\docstruct\xetex\texmf-dist\tex\latex\docstruct\docstruct.sty') #paths = node.abspath.split(os.path.sep) #texname = paths[-2].split('.')[0] #auxname = '..\\'+texname+'.aux' #deps.append(auxname) return deps
def extract_algorithms(ps_infile, env): """ Вытаскиваем части кода-алгоритмы """ import pygments from pygments.lexers import get_lexer_by_name from pygments.formatters import LatexFormatter algorithm_regexp = re.compile( r"(?ms)\#ALGORITHM\s+(?P<name>[a-zA-z-0-9]+)\s*(?P<code>.+?)\s*\#ENDALGORITHM") hideline_regexps = [re.compile(r"(?m)^.*\#hide *\n"), re.compile(r"(?m)\n.*\#hide *") ] ls = ut.file2string(ps_infile) for algorithm in algorithm_regexp.finditer(ls): algfilename = lib.get_target(ps_infile, algorithm.group('name')+".py") texfilename = lib.get_target(ps_infile, algorithm.group('name')+".tex") #lf = open(algfilename, 'w') code = algorithm.group('code') for r in hideline_regexps: code = re.sub(r, "", code) #code = lib.utf8anyway(code) #lf.write(code) #lf.close() #tempblock = os.path.join(tempfile.gettempdir(), tempfile.gettempprefix()) #ls = ''.join([env.project_db['paths']['python'], # r'\scripts\pygmentize -f latex -l python ', # ' -o "%(tempblock)s" "%(algfilename)s" ' % vars() ]) #os.system(ls) lexer = get_lexer_by_name('python') code = ut.unicodeanyway(code) latex_tokens = pygments.lex(code, lexer) # sblock = ut.file2string(tempblock) # from pygments.formatters import LatexFormatter latex_formatter = LatexFormatter(texcomments = True) latex = pygments.format(latex_tokens, latex_formatter) stexblock = r""" \documentclass{minimal} \usepackage{xecyr} \XeTeXdefaultencoding "utf-8" \XeTeXinputencoding "utf-8" \defaultfontfeatures{Mapping=tex-text} \setmonofont{Consolas} \usepackage{color} \usepackage{fancyvrb} \usepackage[russian,english]{babel} """ + latex_formatter.get_style_defs() + r""" \begin{document} """ + latex + r""" \end{document} """ ut.string2file(stexblock, texfilename, encoding='utf-8')
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)
def meta2deps(self, target, source, env): strs = [] for src in source: srcstr = src.get_contents().replace('\r', '') strs.append(srcstr.strip()) srcstrs = srcstr.split('\n') for str in srcstrs: depsfile = lib.get_target(str, self.DEPS_FILE) if os.path.exists(depsfile): depsfilestr = ut.file2string(depsfile).strip() if depsfilestr: strs.append(depsfilestr) mystr = '\n'.join(strs) ut.string2file(mystr, target[0].abspath)
def meta_scan(self, node, env, path): """ «Сканируем» meta-файл, возвращаем зависимости. """ # pylint: disable=R0201 contents = node.get_contents().replace('\r', '') deps = [] if contents: deps = contents.split('\n') mydepses = [] for dep in deps: dep = dep.strip() mydepses += self.analyze_dep(dep, env) ext = os.path.splitext(dep)[1] if ext in ['.tex']: meta = lib.get_target(dep, self.META_FILE) cmd = env.Command(meta, dep, self.extract_meta) mydepses.append(meta) fulldep = lib.get_target(dep, self.DEPS_FILE) cmd = env.Command(fulldep, meta, self.meta2deps) mydepses.append(fulldep.strip()) return mydepses