def compile(self, tikz): '''Compile previously unseen TikZ blocks''' if tikz not in self.cache: tmp = mkdtemp() tex = path.join(tmp, 'job.tex') with open(os.path.join(ROOT, 'tikz.tex.in'), 'rb') as f: template = f.read() with open(tex, 'wb') as f: f.write(template % tikz.encode('utf-8')) # Run Tex4Ht, creates SVG file(s). logging.info('before call tex4ht') cwd = os.getcwd() os.chdir(tmp) try: with open(os.path.join(tmp, 'log'), 'w') as f: check_call(['mk4ht', 'htlatex', 'job', 'xhtml'], shell=True, stdout=f, stderr=f) finally: os.chdir(cwd) logging.info('tex4ht done') # SVGs: results = list(glob.glob(path.join(tmp, '*.svg'))) if results: _randomize_id(results[0]) self.cache[tikz] = etree.parse(results[0]) # Cleanup rmtree(tmp) return self.cache.get(tikz)
def __init__(self, md): name_trans = re.compile(u"[ '\u2019]") tree = etree.parse(TRANSLATION_FILE) translations = defaultdict(dict) for idtag in tree.getiterator('id'): for termtag in idtag.getiterator('term'): lang = termtag.get('lang') translations[lang]["%s:%s" % (idtag.get('ns'), idtag.get('id'))] = \ u"%s:%s" % (idtag.get('ns'), name_trans.sub("_", termtag.text)) # u"%s_%s:%s" % (idtag.get('ns'), lang, name_trans.sub("_", termtag.text)) self.translations = translations vocs = {} for voc in vocabularies_for_DES.itervalues(): vocs[voc] = defaultdict(dict) tree = etree.parse(os.path.join(VDEX_DIR, '%s.vdex' % (voc))) for term in tree.findall(VDEX_PREFIX + 'term'): id = str(term.find(VDEX_PREFIX + 'termIdentifier').text) captions = term.find(VDEX_PREFIX + 'caption') for cap in captions.findall(VDEX_PREFIX + 'langstring'): vocs[voc][str(cap.get('language'))][id] = cap.text self.vocabularies = vocs