Skip to content

Instantly share code, notes, and snippets.

@dmccreary
Created April 16, 2014 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmccreary/91a85f4e73d2f30435bb to your computer and use it in GitHub Desktop.
Save dmccreary/91a85f4e73d2f30435bb to your computer and use it in GitHub Desktop.
Unit test to render a LaTeX math equation in XSL-FO using XQuery.
xquery version "1.0";
(: Unit test to check equation rendering in XSL-FO with LaTeX extension.
To pass the test the rendered PDF file must have the equation in it.
Make sure you have the following two jar files in your $EXIST_HOME/lib/extensions:
jlatexmath-1.0.3.jar
jlatexmath-fop-1.0.3.jar
http://forge.scilab.org/index.php/p/jlatexmath/downloads/694/
http://forge.scilab.org/index.php/p/jlatexmath/downloads/get/jlatexmath-1.0.3.jar
http://forge.scilab.org/index.php/p/jlatexmath/downloads/get/jlatexmath-fop-1.0.3.jar
:)
declare namespace fo="http://www.w3.org/1999/XSL/Format";
declare namespace xslfo="http://exist-db.org/xquery/xslfo";
let $fop-config :=
<fop version="1.0">
<renderers>
<renderer mime="application/pdf">
<filterList>
<value>flate</value>
</filterList>
<fonts>
<auto-detect/>
</fonts>
</renderer>
</renderers>
</fop>
let $fo-file :=
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="my-page">
<fo:region-body margin="1in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="my-page">
<fo:flow flow-name="xsl-region-body">
<fo:block>
<fo:block>Test#1: To pass the test you should see an equation
(E = mc squared over the root of 1 minus v squared over c squared) below:</fo:block>
<fo:block>
<fo:instream-foreign-object>
<latex xmlns="http://forge.scilab.org/p/jlatexmath"><![CDATA[
E = \frac{mc^2}{\sqrt{1-\frac{v^2}{c^2}}}
]]></latex>
</fo:instream-foreign-object>
</fo:block>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
let $pdf := xslfo:render($fo-file, "application/pdf", (), $fop-config)
return response:stream-binary($pdf, "application/pdf", "output.pdf")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment