These files illustrate how to open a process running MathJax from perl, using pipes to send TeX commands to be typeset and receveing SVG output (or error messages) back.
- main.pl is the main file. It calls
MathJax::Typeset()to typeset some examples and output the resulting SVG. - MathJax.pl implements the
MathJax::Typeset()andMathJax::ResetTeX()commands by opening a node.js process that runs MathJax behind the scenes. Perl communicates with this process using pipes: commands are written on one pipe and the results from MathJax are recevied on the other. - pipe-handler.js implements a simple handle for the commands that are piped to it from perl. Each line on the pipe
should start with a command (the current ones are
LINE,TYPESET,RESETandEND). TheLINEcommand is used to collect lines of TeX code to be typeset. TheTYPESETcommand causes the previous lines to be typeset and the SVG output returned. TheRESETcommand reset's TeX's label and equation numbering (if automatic numbering is used). TheENDcommand ends the MathJax process. - mathjax.js configures MathJax and sets up the commands used by the pipe-handler. I kept these separate to isolate the MathJax portion from the pipe handling portion, to make it easier to understand (I hope).
- package.json is the file used by
npmto know what node modules you need.
To install, copy these files to a directory, CD to the directory and use the comand
npm install
to set everything up. Then
perl main.pl
should get you two SVG images from MathJax.