From 7475946199e7c363fcf125c5b26be173cd4010f3 Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Wed, 14 Aug 2013 17:10:10 +0200 Subject: [PATCH 1/1] option handling in book2pdf, ilustrations, verbatim tag --- librarian/pdf.py | 16 ++++++++++++++-- librarian/pdf/wl2tex.xslt | 11 +++++++++-- librarian/pdf/wlpub.cls | 12 ++++++++++++ scripts/book2pdf | 10 ++++++++-- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/librarian/pdf.py b/librarian/pdf.py index 9fb92b1..20daec8 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 @@ -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, 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) + # 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,10 @@ 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) + if resources: + copy_tree(resources, temp) try: cwd = os.getcwd() diff --git a/librarian/pdf/wl2tex.xslt b/librarian/pdf/wl2tex.xslt index 58bb68d..9663bf5 100644 --- a/librarian/pdf/wl2tex.xslt +++ b/librarian/pdf/wl2tex.xslt @@ -15,7 +15,7 @@ - \documentclass[]{wl} + \documentclass[]{} @@ -362,12 +362,13 @@ + - + @@ -392,6 +393,12 @@ + + + + + + tableh! diff --git a/librarian/pdf/wlpub.cls b/librarian/pdf/wlpub.cls index 05f2aba..d5154e1 100644 --- a/librarian/pdf/wlpub.cls +++ b/librarian/pdf/wlpub.cls @@ -94,6 +94,7 @@ \usepackage{fontspec} \usepackage{xunicode} \usepackage{xltxtra} +\usepackage{trimspaces} \usepackage[overload]{textcase} \usepackage{scalefnt} @@ -190,6 +191,8 @@ Mapping=tex-text \parindent 1em\noindent \hb@xt@ 1.8em{\hss \@makefnmark \enskip}#1. } +\def\trimspace#1{\trim@spaces{#1}} + \makeatother @@ -635,6 +638,15 @@ Mapping=tex-text \vspace{10pt}% } +\newcommand{\ilustr}[2]{ + \vspace{1em}% + \begin{center}% + \par{\includegraphics[width=\textwidth]{\trimspace{#1}}\\#2}% + \end{center}% + \vspace{1em}% +} + + \newcommand{\motyw}[2][0]{% \ifshowthemes \mbox{}% diff --git a/scripts/book2pdf b/scripts/book2pdf index 11c5c04..b4559b4 100755 --- a/scripts/book2pdf +++ b/scripts/book2pdf @@ -14,11 +14,17 @@ class Book2Pdf(Book2Anything): ext = "pdf" uses_cover = True uses_provider = True - transform_args = [ + transform_options = [ Option('-t', '--save-tex', dest='save_tex', metavar='FILE', help='path to save the intermediary LaTeX file to'), + Option('-x', '--save-texml', dest='save_texml', metavar='FILE', + help='path to save the intermediary TeXML file to'), Option('-m', '--morefloats', dest='morefloats', metavar='old/new/none', - help='force morefloats in old (<1.0c), new (>=1.0c) or none') + help='force morefloats in old (<1.0c), new (>=1.0c) or none'), + Option('-R', '--resources', dest='resources', metavar='DIR', + help='a directory with additional resources'), + Option('-D', '--documentclass', dest='documentclass', + help='LaTeX document class, defaults to "wl"') ] -- 2.20.1