{"id":20079533,"url":"https://github.com/transpect/mml2tex","last_synced_at":"2025-04-05T15:07:53.107Z","repository":{"id":30367585,"uuid":"33920138","full_name":"transpect/mml2tex","owner":"transpect","description":"Converts MathML to LaTeX","archived":false,"fork":false,"pushed_at":"2025-03-11T11:14:23.000Z","size":697,"stargazers_count":93,"open_issues_count":1,"forks_count":22,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-03-29T14:10:13.940Z","etag":null,"topics":["latex","mathml"],"latest_commit_sha":null,"homepage":null,"language":"XSLT","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/transpect.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-04-14T08:33:19.000Z","updated_at":"2025-03-11T11:14:26.000Z","dependencies_parsed_at":"2023-02-19T15:31:29.051Z","dependency_job_id":"b7e0590e-6d7a-465a-a5b7-c4a5bc8bbba1","html_url":"https://github.com/transpect/mml2tex","commit_stats":{"total_commits":445,"total_committers":13,"mean_commits":34.23076923076923,"dds":0.2741573033707865,"last_synced_commit":"d1cb68b1b32a87ec76a9589c2485393915dfe431"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/transpect%2Fmml2tex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/transpect%2Fmml2tex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/transpect%2Fmml2tex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/transpect%2Fmml2tex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/transpect","download_url":"https://codeload.github.com/transpect/mml2tex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247353746,"owners_count":20925329,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["latex","mathml"],"created_at":"2024-11-13T15:23:17.935Z","updated_at":"2025-04-05T15:07:53.086Z","avatar_url":"https://github.com/transpect.png","language":"XSLT","readme":"# mml2tex\n\nmml2tex is an XProc/XSLT-library to convert MathML to LaTeX.\n\nIt should currently support MathML 2 and 3 presentation markup. Content markup and some MathML 1 elements are not supported.\n\nYou 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 `mml2tex`.\n\nThis library is also used in [docx2tex](https://github.com/transpect/docx2tex) that converts Word docx files with OOMML (= new equation editor) formulas to LaTeX.\n\nConsider this XML input file …\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003carticle xmlns=\"http://docbook.org/ns/docbook\" version=\"5.0\"\u003e\n  \u003ctitle\u003eArea enclosed by a circle\u003c/title\u003e\n  \u003cequation\u003e\n    \u003cmml:math xmlns:mml=\"http://www.w3.org/1998/Math/MathML\"\u003e\n      \u003cmml:mi\u003eA\u003c/mml:mi\u003e\n      \u003cmml:mo\u003e=\u003c/mml:mo\u003e\n      \u003cmml:mi\u003eπ\u003c/mml:mi\u003e\n      \u003cmml:msup\u003e\n        \u003cmml:mrow\u003e\n          \u003cmml:mi\u003er\u003c/mml:mi\u003e\n        \u003c/mml:mrow\u003e\n        \u003cmml:mrow\u003e\n          \u003cmml:mn\u003e2\u003c/mml:mn\u003e\n        \u003c/mml:mrow\u003e\n      \u003c/mml:msup\u003e\n    \u003c/mml:math\u003e\n  \u003c/equation\u003e\n\u003c/article\u003e\n\n```\n\n… you should get this output:\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\u003carticle xmlns=\"http://docbook.org/ns/docbook\" version=\"5.0\"\u003e\n  \u003ctitle\u003eArea enclosed by a circle\u003c/title\u003e\n  \u003cequation\u003e\n    \u003c?mml2tex A=\\pi r^{2}?\u003e\n  \u003c/equation\u003e\n\u003c/article\u003e\n```\n\n\n## Invoke standalone\n\nmml2tex is a library rather than a standalone stylesheet. If you intend to run mml2tex standalone, you need to include the dependencies, add a proper XML catalog and invoke Saxon with XML resolver support.\n\n```\nmkdir myProjectDir\ncd myProjectDir\ngit clone git@github.com:transpect/mml2tex.git\ngit clone git@github.com:transpect/xslt-util.git\nmkdir xmlcatalog\ntouch xmlcatalog/catalog.xml\n```\n\nThen edit `xmlcatalog/catalog.xml` with your text editor of choice:\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003ccatalog xmlns=\"urn:oasis:names:tc:entity:xmlns:xml:catalog\"\u003e\n  \u003cnextCatalog catalog=\"../xslt-util/xmlcatalog/catalog.xml\"/\u003e\n\u003c/catalog\u003e\n```\n\nDownload [Apache XML Commons Resolver](https://xerces.apache.org/mirrors.cgi) and invoke Saxon:\n\n```\njava -cp \"C:/home/myUsername/xmltools/saxon/saxon9he.jar;C:/home/myUsername/xmltools/xml-commons-resolver/resolver.jar\" \\\n-Dxml.catalog.files=C:/home/myUsername/myProjectDir/xmlcatalog/catalog.xml \\\nnet.sf.saxon.Transform \\\n-catalog:xmlcatalog/catalog.xml \\\n-xsl:mml2tex/xsl/invoke-mml2tex.xsl \\\n-s:mml2tex/example/example.xml\n```\n\n\n## Include as XSLT library\n\nYou have to import `mml2tex.xsl` in your XSLT stylesheet and create a template that matches on the MathML equations. The MathML markup must be processed within the `mathml2tex` mode. You can take `xsl/mml2tex.xsl` as example:\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\" ?\u003e\n\u003cxsl:stylesheet version=\"2.0\" \n  xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" \n  xmlns:fn=\"http://www.w3.org/2005/xpath-functions\"\n  xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" \n  xmlns:saxon=\"http://saxon.sf.net/\" \n  xmlns:tr=\"http://transpect.io\"\n  xmlns:mml=\"http://www.w3.org/1998/Math/MathML\"\n  exclude-result-prefixes=\"saxon tr fn mml xs\"\u003e\n  \n  \u003cxsl:import href=\"mml2tex.xsl\"/\u003e\n  \n  \u003cxsl:output method=\"xml\" encoding=\"UTF-8\"/\u003e\n  \n  \u003cxsl:preserve-space elements=\"mml:mn mml:mi mml:mtext mml:mo mml:ms\"/\u003e\n  \n  \u003cxsl:param name=\"debug\" select=\"'no'\"/\u003e\n  \u003cxsl:param name=\"debug-dir-uri\" select=\"'debug'\"/\u003e\n  \n  \u003cxsl:template match=\"mml:math\"\u003e\n    \u003cxsl:processing-instruction name=\"mml2tex\"\u003e\n      \u003cxsl:apply-templates select=\".\" mode=\"mathml2tex\"/\u003e\n    \u003c/xsl:processing-instruction\u003e\n  \u003c/xsl:template\u003e\n  \n  \u003cxsl:template match=\"*|@*|processing-instruction()\"\u003e\n    \u003cxsl:copy\u003e\n      \u003cxsl:apply-templates select=\"@*|node()\"/\u003e\n    \u003c/xsl:copy\u003e\n  \u003c/xsl:template\u003e\n  \n  \u003cxsl:template match=\"/\"\u003e\n    \u003cxsl:copy\u003e\n      \u003cxsl:apply-templates/\u003e\n    \u003c/xsl:copy\u003e\n  \u003c/xsl:template\u003e\n  \n\u003c/xsl:stylesheet\u003e\n```\n\n*Note:* You may omit the `xsl:processing-instruction`. Then the LaTeX code will be issued as plain text. This method is not recommended, because subsequent text replacements may break your LaTeX code. It's better to leave the LaTeX code within the processing instruction and resolve it as last step.\n\n## Include as XProc library\n\n### Get dependencies\n\nRunning 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.\n\n#### Git\n\n```\n$ git clone https://github.com/transpect/calabash-frontend calabash --recursive\n$ git clone https://github.com/transpect/cascade\n$ git clone https://github.com/transpect/mml-normalize\n$ git clone https://github.com/transpect/mml2tex\n$ git clone https://github.com/transpect/xproc-util\n$ git clone https://github.com/transpect/xslt-util\n```\n\n#### SVN\n\n```\n$ svn co https://github.com/transpect/calabash-frontend/trunk calabash\n$ svn co https://github.com/transpect/cascade/trunk cascade\n$ svn co https://github.com/transpect/mml-normalize/trunk mml-normalize\n$ svn co https://github.com/transpect/mml2tex/trunk mml2tex\n$ svn co https://github.com/transpect/xproc-util/trunk xproc-util\n$ svn co https://github.com/transpect/xslt-util-util/trunk xslt-util\n```\n\n### Create an XML catalog\n\nAs a convention, our calabash frontend looks after an XML catalog file under `xmlcatalog/catalog.xml`. Therefore you have to create the directory and the file. \n```\n$ mkdir xmlcatalog\n$ touch xmlcatalog/catalog.xml\n```\nThe catalog is necessary to resolve canonical URIs in import statements, such as `http://transpect.io/mml2tex/xpl/mml2tex.xpl`. Therefore, you have to edit the file `catalog.xml` and add appropriate `rewriteURI` statements for your dependencies.\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003ccatalog xmlns=\"urn:oasis:names:tc:entity:xmlns:xml:catalog\"\u003e\n\n  \u003cnextCatalog catalog=\"../cascade/xmlcatalog/catalog.xml\"/\u003e\n  \u003cnextCatalog catalog=\"../mml-normalize/xmlcatalog/catalog.xml\"/\u003e\n  \u003cnextCatalog catalog=\"../mml2tex/xmlcatalog/catalog.xml\"/\u003e\n  \u003cnextCatalog catalog=\"../xproc-util/xmlcatalog/catalog.xml\"/\u003e\n  \u003cnextCatalog catalog=\"../xslt-util/xmlcatalog/catalog.xml\"/\u003e\n  \n\u003c/catalog\u003e\n```\n\n### Include mml2tex in your XProc pipeline\n\nThe step `mml2tex:convert` facilitates the use of the mml2tex library in your XProc pipeline. As prerequisites, you must add the namespace  `http://transpect.io/mml2tex` and a `p:import` statement. A sample `test.xpl` may look like this:\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cp:declare-step xmlns:p=\"http://www.w3.org/ns/xproc\"\n  xmlns:c=\"http://www.w3.org/ns/xproc-step\" \n  xmlns:mml2tex=\"http://transpect.io/mml2tex\"\n  version=\"1.0\"\u003e\n  \n  \u003cp:input port=\"source\"\u003e\n    \u003cp:inline\u003e\n      \u003carticle xmlns=\"http://docbook.org/ns/docbook\" version=\"5.0\"\u003e\n        \u003ctitle\u003eArea enclosed by a circle\u003c/title\u003e\n        \u003cequation\u003e\n          \u003cmml:math xmlns:mml=\"http://www.w3.org/1998/Math/MathML\"\u003e\u003cmml:mi\u003eA\u003c/mml:mi\u003e\u003cmml:mo\u003e=\u003c/mml:mo\u003e\u003cmml:mi\u003eπ\u003c/mml:mi\u003e\u003cmml:msup\u003e\u003cmml:mrow\u003e\u003cmml:mi\u003er\u003c/mml:mi\u003e\u003c/mml:mrow\u003e\u003cmml:mrow\u003e\u003cmml:mn\u003e2\u003c/mml:mn\u003e\u003c/mml:mrow\u003e\u003c/mml:msup\u003e\u003c/mml:math\u003e     \n        \u003c/equation\u003e\n      \u003c/article\u003e\n    \u003c/p:inline\u003e\n  \u003c/p:input\u003e\n  \n  \u003cp:output port=\"result\"/\u003e\n  \n  \u003cp:option name=\"debug\"         select=\"'no'\"/\u003e   \u003c!-- store debug files: yes | no --\u003e\n  \u003cp:option name=\"debug-dir-uri\" select=\"'debug'\"/\u003e\u003c!-- store debug files to this URI --\u003e\n  \n  \u003cp:import href=\"http://transpect.io/mml2tex/xpl/mml2tex.xpl\"/\u003e\n  \u003cp:import href=\"http://transpect.io/xproc-util/store-debug/xpl/store-debug.xpl\"/\u003e\n  \n  \u003cmml2tex:convert\u003e\n    \u003cp:with-option name=\"debug\" select=\"$debug\"/\u003e\n    \u003cp:with-option name=\"debug-dir-uri\" select=\"$debug-dir-uri\"/\u003e\n  \u003c/mml2tex:convert\u003e\n  \n\u003c/p:declare-step\u003e\n```\n### Run the pipeline\n\nWe 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. \n```\n$ ./calabash/calabash.sh test.xpl\n```\n\n### Alternative XSLT-only invocation for KaTeX-compatible output\n\n```\n$ saxon/saxon.sh -xsl:mml2tex/xsl/katexify.xsl -s:mml2tex/example/katexify-example.xml -im:mathml2tex\n```\nAssumptions: A Saxon front-end script is present in the current (project) directory, for example by\n\n```\n$ svn co https://subversion.le-tex.de/common/saxon-pe98/ saxon\n```\n\nAnd the additional transpect libraries xslt-util, xproc-util, cascade, and normalize-mml are present\n(all from https://github.com/transpect/[library]) in the project directory, see above.\n\nAnd there is an xmlcatalog/catalog.xml that imports the library catalogs using `nextCatalog` instructions.\n\nThe Saxon front-end script will look for and use this catalog by default.\n\nInput:\n\n```xml\n\u003cmml:math xmlns:mml=\"http://www.w3.org/1998/Math/MathML\"\u003e\n  \u003cmml:mi\u003eΓ\u003c/mml:mi\u003e\n  \u003cmml:mo\u003e=\u003c/mml:mo\u003e\n  \u003cmml:mi\u003eπ\u003c/mml:mi\u003e\n  \u003cmml:msup\u003e\n    \u003cmml:mrow\u003e\n      \u003cmml:mi\u003er\u003c/mml:mi\u003e\n    \u003c/mml:mrow\u003e\n    \u003cmml:mrow\u003e\n      \u003cmml:mn\u003e2\u003c/mml:mn\u003e\n    \u003c/mml:mrow\u003e\n  \u003c/mml:msup\u003e\n\u003c/mml:math\u003e\n```\n\nOutput:\n\n`\\Gamma = \\pi r ^{2}`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftranspect%2Fmml2tex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftranspect%2Fmml2tex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftranspect%2Fmml2tex/lists"}