Download the PHP package latex2mathml/latex2mathml-php without Composer
On this page you can find all versions of the php package latex2mathml/latex2mathml-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package latex2mathml-php
Latex2MathML-PHP
Pure PHP 8.4 library for LaTeX to MathML conversion. This is a port of the Python library latex2mathml.
Features
- No external dependencies (only PHP 8.4+ and
ext-dom). - Supports a wide range of LaTeX commands and symbols.
- Outputs clean MathML.
- Supports inline and block display modes.
Installation
Usage
Simple conversion
By default, the converter produces inline MathML.
Display Mode
You can specify the display mode (inline or block) as the second argument. For clarity and to ensure future compatibility, using named arguments (PHP 8.0+) is recommended.
Custom XML namespace
The third argument allows you to specify a custom XML namespace. It defaults to the standard MathML namespace (http://www.w3.org/1998/Math/MathML). Pass an empty string if you don't want a namespace attribute. Again, named arguments are recommended.
Integration with DOMDocument
If you are already working with a DOMDocument, you can use convert_to_element to get a DOMElement instead of a string.
Visualization Script
A helper script display_math.php is included to visualize LaTeX conversion from .tex files.
- Place one or more
.texfiles in thetests/directory. -
Run the script and redirect the output to an HTML file:
- Open
output.htmlin your web browser to see the rendered MathML.
The script automatically:
- Finds the first
.texfile in thetests/directory. - Extracts math expressions delimited by
$,$$, or various LaTeX environments (e.g.,equation,align,split). - Converts them to MathML and displays them in a side-by-side view.
Architecture
The project is structured as follows:
Latex2MathML\Converter: Main entry point for conversion.Latex2MathML\Tokenizer: Breaks LaTeX string into tokens.Latex2MathML\Walker: Parses tokens into a tree ofNodeobjects.Latex2MathML\SymbolsParser: Handles conversion of LaTeX symbols to Unicode MathML entities usingunimathsymbols.txt.Latex2MathML\Commands: Contains definitions and maps for LaTeX commands.
Requirements
- PHP 8.4 or higher.
domextension.
License
MIT
All versions of latex2mathml-php with dependencies
ext-dom Version *