mathoid
v0.7.6
Published
Render TeX to SVG and MathML using MathJax. Based on svgtex.
Downloads
149
Readme
Mathoid
Mathoid is a service that renders mathematical formuale on the server side. It accepts Wikimedias LaTeX dialect texvc, MathML or AsciiMath as input and outputs MathML, fallback images with dimension meta-information and a textual representation of the input.
Under the hood Mathoid uses texvcjs, MathJax node, librsvg, and the [speech-rule-engine] for the verification, rendering, conversion and the generation of the textual description. Mathoid was forked from svgtex.
An in-depth discussion of Mathoid can be in the following publications:
Mathoid: Robust, Scalable, Fast and Accessible Math Rendering for Wikipedia
M Schubotz, G Wicke
Intelligent Computer Mathematics - International Conference, CICM 2014, Coimbra, Portugal, July 7-11, 2014. Proceedings
Preprint | Bibtex | DOI: 10.1007/978-3-319-08434-3_17A Smooth Transition to Modern mathoid-based Math Rendering in Wikipedia with Automatic Visual Regression Testing
M Schubotz, AP Sexton
Joint Proceedings of the FM4M, MathUI, and ThEdu Workshops, Doctoral Program, and Work in Progress at the Conference on Intelligent Computer Mathematics 2016 co-located with the 9th Conference on Intelligent Computer Mathematics (CICM 2016), Bialystok, Poland, July 25-29, 2016.
Preprint | Bibtex | PDF
Installation
Mathoid currently supports node version 6,8 or 10. To check your node version run
node --version
from the commandline.
In addition the prerequisites from librsvg are needed.
For Debian based systems installing the librsvg2-dev
should be sufficient.
sudo apt-get install librsvg2-dev
Thereafter, clone and install Mathoid by running
git clone https://github.com/wikimedia/mathoid/
cd mathoid
npm install
Run the tests
Before proceeding, we recommend running to run the tests via
npm test
The tests should pass in less than one minute. If you plan to use Mathoid to render formulae for your small to medium scale wiki you are done.
Service
For larger wikis using RESTbase, running mathoid as a service is desired. To install Mathoid as a unix service, you can use our startup script.
A community maintained page with OS specific installation instructions is available from MediaWiki.
API Description
The main entry point is '/' with one required POST parameter 'q'.
Additional entry points for individual formats are
- /texvcinfo does not do any rendering. Only displays information regarding the texvc input.
- /speech returns the speech output only
- /mml only MathML
- /svg only SVG
- /png only PNG
- /json (same as /)
- /complete (see below)
The 'complete' output format is equal to the 'json' one except that it also includes the headers for individual types in the response body as well. The output specification is identical, except that the 'mml', 'svg' and 'png' fields are now (JSON) objects containing the 'body' and 'headers' fields.
q (input to be converted)
- required parameter
- no $ for (La)TeX input
type (the input type)
- optional
- defalult 'tex'
- possible values
- tex (texvc input will be verified by texvccheck)
- inline-tex (texvc input will be rendered with small operators)
- mml (MathML input, used in latexml rendering mode)
- ascii (ascii mathml input, experimental)
nospeech
- optional
- if speech output is enabled this switch suppresses speech output for one particular request
Config
- svg: creates and svg image (turned on by default)
- img: creates a img element with dimension information about the svg image
- png: creates png images using java
- speech: creates speech output using speech rule engine
- texvcinfo: displays information regarding the texvc input (experimental)
- speechOn: default setting for speech output. 'true' is equivalent to the old speakText.
Performance
The performance tests can be run by executing the performance.sh script.
On our labs-vagrant test instance with 8 workers and 100 request the following results were obtained for the input $E = m c^2$:
|format |time| sd| |--------------------------------------------|----|------| | texvcinfo |0005|003.2| | mml |0334|061.2| | svg |0343|058.6| | png |0027|007.2|
|format (without speech support) |time| sd| |----------------------------------------------|----|------| | texvcinfo |0005|003.0| | mml |0030|004.5| | svg |0030|004.2| | png |0030|005.7| The time, i.e. "Total Connection Times" were measured in unit ms.
Run as service (with PM2)
PM2 is a process manager for Node.js. It supports starting applications on system startup. You can set up mathoid to run automatically using this process manager.
For example, run
npm install pm2 -g
pm2 start pm2.config.js
pm2 save
pm2 startup
Thereafter check the generated output and run it as with root permissions.
Create a new debian release
Checkout the latest version and switch to the master branch:
- git-dch -R -N version
- git-buildpackage --git-tag -S
see also https://wikitech.wikimedia.org/wiki/Git-buildpackage
publish as ppa
- dput ppa:physikerwelt/mathoid ../version.changes
Tests
Based on the Template for creating MediaWiki Services in Node.js The template also includes a test suite a small set of executable tests. To fire them up, simply run:
npm test
If you haven't changed anything in the code (and you have a working Internet connection), you should see all the tests passing. As testing most of the code is an important aspect of service development, there is also a bundled tool reporting the percentage of code covered. Start it with:
npm run-script coverage
Troubleshooting
In a lot of cases when there is an issue with node it helps to recreate the
node_modules
directory:
rm -r node_modules
npm install