MathML::itex2MML - Convert itex to MathML
use MathML::itex2MML; $text = 'This is an inline equation: $\sin(\pi/2)=1$.'; # convert embedded itex equations to MathML: $converted = itex_html_filter($text); # This is an inline equation: <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>sin</mi><mo stretchy="false">(</mo><mi>π</mi><mo stretchy="false">/</mo><mn>2</mn><mo stretchy="false">)</mo><mo>=</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>\sin(\pi/2)=1</annotation></semantics></math>. # just the equations: $converted = itex_filter($text); # <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>sin</mi><mo stretchy="false">(</mo><mi>π</mi><mo stretchy="false">/</mo><mn>2</mn><mo stretchy="false">)</mo><mo>=</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>\sin(\pi/2)=1</annotation></semantics></math> $text = '\sin(\pi/2)=1'; # inline equation (without the $'s) $converted = itex_inline_filter($text); # <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>sin</mi><mo stretchy="false">(</mo><mi>π</mi><mo stretchy="false">/</mo><mn>2</mn><mo stretchy="false">)</mo><mo>=</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>\sin(\pi/2)=1</annotation></semantics></math> # block equation (without the $$'s) $converted = itex_block_filter($text); # <math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mi>sin</mi><mo stretchy="false">(</mo><mi>π</mi><mo stretchy="false">/</mo><mn>2</mn><mo stretchy="false">)</mo><mo>=</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>\sin(\pi/2)=1</annotation></semantics></math>
MathML::itex2MML converts itex (a dialect of LaTeX) equations into MathML. Inline equations are demarcated by $..$ or \(...\). Display equations are demarcated by $$...$$ or \[...\]. The syntax supported is described here.
MathML::itex2MML
$..$
\(...\)
$$...$$
\[...\]
It is strongly suggested that you run the output through MathML::Entities, to convert named entities into either numeric character references or UTF-8 characters, if you intend putting the result on the Web.
MathML::Entities
MathML::itex2MML is based on the commandline converter, itex2MML.
The following functions are exported by default.
itex2MML_html_filter
Take a text string, with embedded itex equations, and convert all the equations to MathML, passing through the rest of the text.
itex2MML_filter
Take a text string, with embedded itex equations, and convert all the equations to MathML, dropping the rest of the text.
itex2MML_inline_filter
Convert a single equation (without the enclosing $'s) to inline MathML.
itex2MML_block_filter
Convert a single equation (without the enclosing $$'s) to block-display MathML.
Jacques Distler <distler@golem.ph.utexas.edu>
Copyright (c) 2018-19 Jacques Distler. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
MathML::Entitities
https://golem.ph.utexas.edu/~distler/blog/itex2MMLcommands.html
https://rubygems.org/gems/itextomml
To install MathML::itex2MML, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MathML::itex2MML
CPAN shell
perl -MCPAN -e shell install MathML::itex2MML
For more information on module installation, please visit the detailed CPAN module installation guide.