X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/cba76114f031d47c93e1af947a350230cbef0a1f..05fbf034b60a035d01f41dbbafffb493e584537a:/librarian/pdf.py?ds=sidebyside diff --git a/librarian/pdf.py b/librarian/pdf.py index 9fb92b1..a5c4253 100644 --- a/librarian/pdf.py +++ b/librarian/pdf.py @@ -13,6 +13,7 @@ from __future__ import with_statement import os import os.path import shutil +from distutils.dir_util import copy_tree # shutil.copytree is so uncapable. from StringIO import StringIO from tempfile import mkdtemp, NamedTemporaryFile import re @@ -83,7 +84,7 @@ def substitute_hyphens(doc): insert_tags(doc, re.compile("(?<=[^-\s])-(?=[^-\s])"), "dywiz", - exclude=[DCNS("identifier.url"), DCNS("rights.license")] + exclude=[DCNS("identifier.url"), DCNS("rights.license"), "www"] ) @@ -183,17 +184,20 @@ def package_available(package, args='', verbose=False): return p == 0 -def transform(wldoc, verbose=False, save_tex=None, morefloats=None, - cover=None, flags=None, customizations=None): +def transform(wldoc, verbose=False, save_tex=None, save_texml=None, morefloats=None, + cover=None, cover_file=None, flags=None, customizations=None, documentclass='wl', resources=None): """ produces a PDF file with XeLaTeX wldoc: a WLDocument verbose: prints all output from LaTeX save_tex: path to save the intermediary LaTeX file to + save_texml: path to save the intermediary TeXML file to morefloats (old/new/none): force specific morefloats cover: a cover.Cover factory or True for default flags: less-advertising, customizations: user requested customizations regarding various formatting parameters (passed to wl LaTeX class) + documentclass: LaTeX document class, defaults to wl + resources: a directory with resources, copied to place where LaTeX compilation is made """ # Parse XSLT @@ -228,6 +232,8 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None, if customizations is not None: root.set('customizations', u','.join(customizations)) + root.set('documentclass', documentclass or 'wl') + # add editors info root.set('editors', u', '.join(sorted( editor.readable() for editor in document.editors()))) @@ -245,6 +251,9 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None, texml = document.transform(style) + if save_texml: + texml.write(save_texml) + # TeXML -> LaTeX temp = mkdtemp('-wl2pdf') @@ -265,7 +274,11 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None, # LaTeX -> PDF shutil.copy(get_resource('pdf/wl.cls'), temp) + shutil.copy(get_resource('pdf/wlpub.cls'), temp) shutil.copy(get_resource('res/wl-logo.png'), temp) + shutil.copy(get_resource('res/cover.jpg'), temp) + if resources: + copy_tree(resources, temp) try: cwd = os.getcwd() @@ -273,6 +286,9 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None, cwd = None os.chdir(temp) + if resources: + os.putenv("TEXINPUTS", "::.:%s" % resources) + if verbose: p = call(['xelatex', tex_path]) else: