from librarian import RDFNS, WLNS, NCXNS, OPFNS, XHTMLNS, OutputFile
from librarian.cover import WLCover, FutureOfCopyrightCover
-
+from librarian.latex import LatexFragment
from librarian import functions, get_resource
functions.reg_person_name()
return output_html, toc, chars
+def render_latex(wldoc, prefix="latex"):
+ """
+ Renders <latex>CODE</latex> as images and returns
+ (changed_wldoc, [ (epub_filepath1, latexfragment_object1), ... ]
+"""
+ root = wldoc.edoc.getroot()
+ latex_nodes = root.findall(".//latex")
+ images = []
+ for ln in latex_nodes:
+ fragment = LatexFragment(ln.text, resize=40)
+ images.append((os.path.join(prefix, fragment.filename), fragment))
+ ln.tag = "img"
+ ln.text = os.path.join(prefix, fragment.filename)
+
+ return wldoc, images
+
+
def transform(wldoc, verbose=False,
style=None, html_toc=False,
sample=None, cover=None, flags=None, resources=None,
if not style:
style = get_resource('epub/style.css')
zip.write(style, os.path.join('OPS', 'style.css'))
+
+ document, latex_images = render_latex(document)
+ for image in latex_images:
+ zip.write(image[1].path, os.path.join('OPS', image[0]))
+ image[1].remove()
+
if resources:
if os.path.isdir(resources):
for dp, dirs, files in os.walk(resources):
<?xml version="1.0" encoding="UTF-8"?>
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="html" version="1.0" encoding="utf-8" />
<xsl:output doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" />
<xsl:output doctype-public="-//W3C//DTD XHTML 1.1//EN" />
</p>
</xsl:template>
+ <xsl:template match="img">
+ <img rel="math formula">
+ <xsl:attribute name="src">
+ <xsl:value-of select="text()"/>
+ </xsl:attribute>
+ <xsl:attribute name="class">latex</xsl:attribute>
+ </img>
+ </xsl:template>
+
+
</xsl:stylesheet>
</xsl:if>
</xsl:template>
+ <xsl:template match="nota_red">
+ <div class="note_red" xmlns="http://www.w3.org/1999/xhtml">
+ <xsl:apply-templates />
+ </div>
+ </xsl:template>
+
+
<xsl:template match="lista_osob" >
<div class="person-list" xmlns="http://www.w3.org/1999/xhtml">
<div class="h3" xmlns="http://www.w3.org/1999/xhtml">
<xsl:template match="uwaga" />
- <xsl:template match="nota_red" />
<!--pominięcie tych metadanych-->
<xsl:template match="rdf:RDF" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" />
</img>
</xsl:template>
+ <xsl:template match="img">
+ <img rel="math formula">
+ <xsl:attribute name="src">
+ <xsl:value-of select="text()"/>
+ </xsl:attribute>
+ <xsl:attribute name="class">latex</xsl:attribute>
+ </img>
+ </xsl:template>
+
<xsl:template match="wyimek_extra">
</xsl:template>