The diagram below shows an architecture for generating books using a dynamic preamble. The top part of the image shows the database relations between a book theme and its preamble. The top set of numbered items represent:
- A LaTeX snippet, later collated into a preamble, stored in a table.
- Various snippets controlling aspects of the final document (e.g., colours, fonts, layout).
- A theme comprised of a default set of snippets (e.g., A, B, & C below).
When the user selects a theme, a database query dynamically creates a preamble. The user can select a theme then tweak it by overriding the default snippets, as illustrated by the browser wire-frame (i.e., palette, font, photo, etc.).
The user creates a book as shown in the diagram. The system performs the following actions when the user clicks the "download" button:
- Generates an XML document to gather the information for the book.
- Dynamically creates the LaTeX preamble based on theme and tweaks.
- Transforms the XML into a
.texfile, injecting the LaTeX preamble.
pdflatexto create a
- Returns the PDF to the user.
Although the LaTeX preamble is almost all database-driven, parts are coded in XSLT, such as the
\documentclass declaration. This is trivial to parameterize.
I would like to revise the architecture to allow users to create version of their documents for different devices and file formats (e.g., ePub, Mobi, Kindle, PDF). There is no math, but any images must be fixed on the page (i.e., they cannot float; here, definitely).
Given the constraints of such an architecture, what approach should I take to convert the LaTeX documents for various eReaders such that the output produced is as high a quality as possible, and as true to the PDF layout as possible?
I have tried to convert the LaTeX, as it stands, directly to XHTML. This failed in spectacular ways using Hevea, latex2html, pandoc, and mk4ht (htlatex), mostly due to the dependency on the
My thoughts are that I'm going to have to do the following, at least:
- Allow the user to choose ePub format (prior to "clicks" in the diagram).
- Update the XSLT To remove the reference to the
.clsfile (for ePub format).
The .cls source code is part of an open source project. There is an example .tex file in the repository, along with example themes. Note that the images in the example
.tex file are not in the repository, so generating a PDF will require minor modifications.
Also, there is an installation script (
install.sh) that drops dependent artefacts into specific directories. It probably won't work for other LaTeX installations without modification.
This section describes the errors I encountered, from memory.
Could not parse the
Could not find the
.cls file, despite it being located in
pdflatex program can generate the PDF without any issues. Generates many PNG images that are difficult to read, even though the content is mostly text:
mk4ht & htlatex
Was able to generate HTML documents, but there appear to be some UTF8 encoding issues (the output is gibberish). There are also image scaling issues (i.e., the images didn't shrink). Not sure why the result is gibberish, as it is UTF8-encoded:
$ file -bi 22.tex text/x-tex; charset=utf-8
.cls file be converted to
.cls file has a dependency on
enumitem, which aren't currently implemented.
Generates a number of warnings and some errors, such as:
ERROR: Error while expanding "csname" in /usr/local/texlive/2013/texmf- dist/tex/latex/ccicons/ccicons.sty on line 31 (sequence item 4: expected string or Unicode, @currname found)
Although it can initially find the
.cls file, it cannot open it:
Traceback (most recent call last): File "/usr/local/bin/plastex", line 108, in <module> main(sys.argv) File "/usr/local/bin/plastex", line 54, in main tex.parse() File "/usr/local/lib/python2.7/dist-packages/plasTeX/TeX.py", line 387, in parse for item in tokens: ...
Alternative to LaTeX
I am leaning towards a non-LaTeX solution. Since XML and XSLT are already part of the architecture, creating a book using DocBook might be an easier path at this point. There are a number of supporting tools, and DocBook readily converts to formats such as EPUB2, EPUB3, HTML, and more.