在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):transpect/mml2tex开源软件地址(OpenSource Url):https://github.com/transpect/mml2tex开源编程语言(OpenSource Language):XSLT 93.1%开源软件介绍(OpenSource Introduction):mml2texmml2tex is an XProc/XSLT-library to convert MathML to LaTeX. It should currently support MathML 2 and 3 presentation markup. Content markup and some MathML 1 elements are not supported. You may either invoke mml2tex standalone or include it as library in your XSLT or XProc project. The LaTeX code is wrapped in processing instructions named This library is also used in docx2tex that converts Word docx files with OOMML (= new equation editor) formulas to LaTeX. Consider this XML input file … <?xml version="1.0" encoding="UTF-8"?>
<article xmlns="http://docbook.org/ns/docbook" version="5.0">
<title>Area enclosed by a circle</title>
<equation>
<mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML">
<mml:mi>A</mml:mi>
<mml:mo>=</mml:mo>
<mml:mi>π</mml:mi>
<mml:msup>
<mml:mrow>
<mml:mi>r</mml:mi>
</mml:mrow>
<mml:mrow>
<mml:mn>2</mml:mn>
</mml:mrow>
</mml:msup>
</mml:math>
</equation>
</article>
… you should get this output: <?xml version="1.0" encoding="UTF-8"?><article xmlns="http://docbook.org/ns/docbook" version="5.0">
<title>Area enclosed by a circle</title>
<equation>
<?mml2tex A=\pi r^{2}?>
</equation>
</article> Invoke standaloneThere is a simple frontend XSLT to invoke mml2tex. You may use Saxon to apply the stylesheet to your input XML file.
Include as XSLT libraryYou have to import <?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:saxon="http://saxon.sf.net/"
xmlns:tr="http://transpect.io"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
exclude-result-prefixes="saxon tr fn mml xs">
<xsl:import href="mml2tex.xsl"/>
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:preserve-space elements="mml:mn mml:mi mml:mtext mml:mo mml:ms"/>
<xsl:param name="debug" select="'no'"/>
<xsl:param name="debug-dir-uri" select="'debug'"/>
<xsl:template match="mml:math">
<xsl:processing-instruction name="mml2tex">
<xsl:apply-templates select="." mode="mathml2tex"/>
</xsl:processing-instruction>
</xsl:template>
<xsl:template match="*|@*|processing-instruction()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet> Note: You may omit the Include as XProc libraryGet dependenciesRunning mml2tex requires an XProc processor, the libary store-debug.xpl and of course mml2tex. To facilitate the invocation of the XProc pipeline, we recommend to use our patched calabash-frontend. You can checkout the repositories with Git or SVN. Git
SVN
Create an XML catalogAs a convention, our calabash frontend looks after an XML catalog file under
The catalog is necessary to resolve canonical URIs in import statements, such as <?xml version="1.0" encoding="UTF-8"?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<nextCatalog catalog="../cascade/xmlcatalog/catalog.xml"/>
<nextCatalog catalog="../mml-normalize/xmlcatalog/catalog.xml"/>
<nextCatalog catalog="../mml2tex/xmlcatalog/catalog.xml"/>
<nextCatalog catalog="../xproc-util/xmlcatalog/catalog.xml"/>
<nextCatalog catalog="../xslt-util/xmlcatalog/catalog.xml"/>
</catalog> Include mml2tex in your XProc pipelineThe step <?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:c="http://www.w3.org/ns/xproc-step"
xmlns:mml2tex="http://transpect.io/mml2tex"
version="1.0">
<p:input port="source">
<p:inline>
<article xmlns="http://docbook.org/ns/docbook" version="5.0">
<title>Area enclosed by a circle</title>
<equation>
<mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>A</mml:mi><mml:mo>=</mml:mo><mml:mi>π</mml:mi><mml:msup><mml:mrow><mml:mi>r</mml:mi></mml:mrow><mml:mrow><mml:mn>2</mml:mn></mml:mrow></mml:msup></mml:math>
</equation>
</article>
</p:inline>
</p:input>
<p:output port="result"/>
<p:option name="debug" select="'no'"/> <!-- store debug files: yes | no -->
<p:option name="debug-dir-uri" select="'debug'"/><!-- store debug files to this URI -->
<p:import href="http://transpect.io/mml2tex/xpl/mml2tex.xpl"/>
<p:import href="http://transpect.io/xproc-util/store-debug/xpl/store-debug.xpl"/>
<mml2tex:convert>
<p:with-option name="debug" select="$debug"/>
<p:with-option name="debug-dir-uri" select="$debug-dir-uri"/>
</mml2tex:convert>
</p:declare-step> Run the pipelineWe provide frontend scripts for XML Calabash which look after the XML catalogs, make some paths suitable for XProc and add some Java libraries to the class path. There is a Bash script for Unix-like operating systems as well as an Batch file for Windows. You can find them in the calabash directory.
Alternative XSLT-only invocation for KaTeX-compatible output
Assumptions: A Saxon front-end script is present in the current (project) directory, for example by
And the additional transpect libraries xslt-util, xproc-util, cascade, and normalize-mml are present (all from https://github.com/transpect/[library]) in the project directory, see above. And there is an xmlcatalog/catalog.xml that imports the library catalogs using The Saxon front-end script will look for and use this catalog by default. Input: <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML">
<mml:mi>Γ</mml:mi>
<mml:mo>=</mml:mo>
<mml:mi>π</mml:mi>
<mml:msup>
<mml:mrow>
<mml:mi>r</mml:mi>
</mml:mrow>
<mml:mrow>
<mml:mn>2</mml:mn>
</mml:mrow>
</mml:msup>
</mml:math> Output:
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论