+ cover_class = None
+ tex_passes = 1
+ style = get_resource('pdf/default.sty')
+ cover = None
+
+ @property
+ def has_cover(self):
+ """ For use in XSLT. """
+ return self.cover is not None
+
+ @property
+ def customization_str(self):
+ """ For use in XSLT. """
+ return u','.join(k for k, v in self.customization.items() if v)
+
+ def get_document(self):
+ document = load_including_children(self.wldoc)
+ root = document.edoc.getroot()
+ root.set('editors', u', '.join(sorted(
+ editor.readable() for editor in document.editors())))
+
+ # hack the tree
+ move_motifs_inside(document.edoc)
+ hack_motifs(document.edoc)
+ parse_creator(document.edoc)
+ substitute_hyphens(document.edoc)
+ fix_hanging(document.edoc)
+ return document
+
+ def get_texml(self):
+ style_filename = get_stylesheet("wl2tex")
+ functions.reg_get(self)
+ try:
+ style = etree.parse(style_filename)
+ texml = self.get_document().transform(style)
+ return texml
+ except (XMLSyntaxError, XSLTApplyError), e:
+ raise ParseError(e)
+
+ def get_tex_dir(self):
+ texml = self.get_texml()
+ temp = mkdtemp('-wl2pdf')
+ # Save TeX file
+ tex_path = os.path.join(temp, 'doc.tex')
+ with open(tex_path, 'w') as fout:
+ process(StringIO(texml), fout, 'utf-8')
+ if self.save_tex:
+ shutil.copy(tex_path, self.save_tex)
+ # Copy style
+ shutil.copy(get_resource('pdf/wl.cls'), temp)
+ shutil.copy(self.style, os.path.join(temp, 'style.sty'))
+ # Save attachments
+ if self.cover:
+ self.cover.for_pdf().dump_to(os.path.join(temp, 'makecover.sty'))
+ return temp
+
+ def get_pdf(self):
+ temp = self.get_tex_dir()
+ tex_path = os.path.join(temp, 'doc.tex')
+ try:
+ cwd = os.getcwd()
+ except OSError:
+ cwd = None
+ os.chdir(temp)
+
+ if self.verbose:
+ for i in range(self.tex_passes):
+ p = call(['xelatex', tex_path])
+ else:
+ for i in range(self.tex_passes):
+ p = call(['xelatex', '-interaction=batchmode', tex_path],
+ stdout=PIPE, stderr=PIPE)
+ if p:
+ raise ParseError("Error parsing .tex file")