From 3264b158f316ec89d9dfc28a43f2d7d8728133d7 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Wed, 4 Feb 2015 09:24:44 -0500 Subject: [PATCH 01/18] Fix missing factor of 1000 for lineWidth, and allow dpi to be computed automatically to get pixel size right in PNG images. Resolves issue #62. --- bin/am2png | 6 ++++-- bin/mml2png | 6 ++++-- bin/page2png | 10 ++++++---- bin/tex2png | 6 ++++-- lib/mj-single.js | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/bin/am2png b/bin/am2png index 43324ff7..05af7a39 100755 --- a/bin/am2png +++ b/bin/am2png @@ -34,8 +34,8 @@ var argv = require("yargs") describe: "perform automatic line-breaking" }, dpi: { - default: 144, - describe: "dpi for image" + default: 0, + describe: "dpi for image (0 = calculate automatically)" }, font: { default: "TeX", @@ -56,6 +56,8 @@ if (argv.font === "STIX") argv.font = "STIX-Web"; mjAPI.config({MathJax: {SVG: {font: argv.font}}}); mjAPI.start(); +if (argv.dpi === 0) {argv.dpi = argv.ex * 16} // pixels properly sized + mjAPI.typeset({ math: argv._[0], format: "AsciiMath", diff --git a/bin/mml2png b/bin/mml2png index b65c36b7..4e67e14a 100755 --- a/bin/mml2png +++ b/bin/mml2png @@ -33,8 +33,8 @@ var argv = require("yargs") describe: "perform automatic line-breaking" }, dpi: { - default: 144, - describe: "dpi for image" + default: 0, + describe: "dpi for image (0 = calculate automatically)" }, font: { default: "TeX", @@ -55,6 +55,8 @@ if (argv.font === "STIX") argv.font = "STIX-Web"; mjAPI.config({MathJax: {SVG: {font: argv.font}}}); mjAPI.start(); +if (argv.dpi === 0) {argv.dpi = argv.ex * 16} // pixels properly sized + mjAPI.typeset({ math: argv._[0], format: "MathML", diff --git a/bin/page2png b/bin/page2png index f3c7d7cd..2a43d179 100755 --- a/bin/page2png +++ b/bin/page2png @@ -65,12 +65,12 @@ var argv = require("yargs") describe: "equation number style (none, AMS, or all)" }, img: { - default: "", - describe: "make external svg images with this name prefix" + default: "", + describe: "make external svg images with this name prefix" }, dpi: { - default: "144", - describe: "the dpi for the PNG images" + default: 0, + describe: "dpi for image (0 = calculate automatically)" }, font: { default: "TeX", @@ -92,6 +92,8 @@ if (argv.font === "STIX") argv.font = "STIX-Web"; mjAPI.config({MathJax: {SVG: {font: argv.font}}}); mjAPI.start(); +if (argv.dpi === 0) {argv.dpi = argv.ex * 16} // pixels properly sized + // // Process an HTML file: // diff --git a/bin/tex2png b/bin/tex2png index 8770ee20..213b679c 100755 --- a/bin/tex2png +++ b/bin/tex2png @@ -38,8 +38,8 @@ var argv = require("yargs") describe: "perform automatic line-breaking" }, dpi: { - default: 144, - describe: "dpi for image" + default: 0, + describe: "dpi for image (0 = calculate automatically)" }, font: { default: "TeX", @@ -60,6 +60,8 @@ if (argv.font === "STIX") argv.font = "STIX-Web"; mjAPI.config({MathJax: {SVG: {font: argv.font}}}); mjAPI.start(); +if (argv.dpi === 0) {argv.dpi = argv.ex * 16} // pixels properly sized + mjAPI.typeset({ math: argv._[0], format: (argv.inline ? "inline-TeX" : "TeX"), diff --git a/lib/mj-single.js b/lib/mj-single.js index fe8c22d5..92f6bffc 100644 --- a/lib/mj-single.js +++ b/lib/mj-single.js @@ -261,7 +261,7 @@ function ConfigureMathJax() { // jax.SVG.ex = ex = (data||defaults).ex; jax.SVG.cwidth = width; jax.SVG.em = em = ex / SVG.TeX.x_height * 1000; // scale ex to x_height - jax.SVG.lineWidth = (linebreak ? width / em : 1000000); + jax.SVG.lineWidth = (linebreak ? width / em * 1000 : 1000000); } // // Set state variables used for displaying equations in chunks From aa15fbebe0f50b87a01121755ef3c96db22baf70 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Wed, 4 Feb 2015 14:55:00 -0500 Subject: [PATCH 02/18] Make cwidth be in units of em*1000 rather than px. Resolves issue #65. --- lib/mj-single.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/mj-single.js b/lib/mj-single.js index 92f6bffc..3b9d4a3c 100644 --- a/lib/mj-single.js +++ b/lib/mj-single.js @@ -259,8 +259,9 @@ function ConfigureMathJax() { // // Set SVG data for jax // - jax.SVG.ex = ex = (data||defaults).ex; jax.SVG.cwidth = width; + jax.SVG.ex = ex = (data||defaults).ex; jax.SVG.em = em = ex / SVG.TeX.x_height * 1000; // scale ex to x_height + jax.SVG.cwidth = width / em * 1000; jax.SVG.lineWidth = (linebreak ? width / em * 1000 : 1000000); } // From 43937d21366b73a2933bd3c5154ecae189ad8083 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Thu, 5 Feb 2015 10:35:16 -0500 Subject: [PATCH 03/18] Make the same adjustements to mj-page.js. Issues #62 and #65. --- lib/mj-page.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/mj-page.js b/lib/mj-page.js index c877aba2..43831c20 100644 --- a/lib/mj-page.js +++ b/lib/mj-page.js @@ -264,9 +264,10 @@ function ConfigureMathJax() { // // Set SVG data for jax // - jax.SVG.ex = ex = (data||defaults).ex; jax.SVG.cwidth = width; + jax.SVG.ex = ex = (data||defaults).ex; jax.SVG.em = em = ex / SVG.TeX.x_height * 1000; // scale ex to x_height - jax.SVG.lineWidth = (linebreak ? width / em : 1000000); + jax.SVG.cwidth = width / em * 1000; + jax.SVG.lineWidth = (linebreak ? width / em *1000 : 1000000); } // // Set state variables used for displaying equations in chunks From 696438c8f32c715fc77d68a23296ae3766e3cd96 Mon Sep 17 00:00:00 2001 From: Peter Krautzberger Date: Fri, 6 Feb 2015 12:15:18 +0100 Subject: [PATCH 04/18] Update for #64 * Update MathJax dependency to v2.5 * Update info of organization --- package.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 30393d50..0b6a24d1 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,9 @@ "description": "API's for calling MathJax from node.js", "keywords": ["MathJax","math","svg","MathML","TeX","AsciiMath"], "maintainers": [ - "Davide P. Cervone (http://www.math.union.edu/locate/Cervone/)" + "MathJax Consortium (http://www.mathjax.org)" ], "bugs": { - "email": "dpvc@union.edu", "url": "http://github.com/mathjax/MathJax-node/issues" }, "license": { @@ -22,7 +21,7 @@ "jsdom": "1.0.2", "speech-rule-engine": "*", "yargs": "*", - "MathJax": "https://github.com/mathjax/MathJax/tarball/mathjax-node" + "MathJax": "https://github.com/mathjax/MathJax/tarball/mathjax-node-2.5" }, "main": "./lib/mj-page.js" } From 4fa4927591163a4d6491875969e533442edecf50 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Mon, 9 Feb 2015 19:08:19 -0500 Subject: [PATCH 05/18] Update version number and fix some spacing --- package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 0b6a24d1..8b26332b 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "MathJax-node", - "version": "0.2.0", + "version": "0.3.0", "description": "API's for calling MathJax from node.js", "keywords": ["MathJax","math","svg","MathML","TeX","AsciiMath"], "maintainers": [ - "MathJax Consortium (http://www.mathjax.org)" + "MathJax Consortium (http://www.mathjax.org)" ], "bugs": { "url": "http://github.com/mathjax/MathJax-node/issues" @@ -18,10 +18,10 @@ "url": "git://github.com/mathjax/MathJax-node.git" }, "dependencies": { - "jsdom": "1.0.2", - "speech-rule-engine": "*", - "yargs": "*", - "MathJax": "https://github.com/mathjax/MathJax/tarball/mathjax-node-2.5" + "jsdom": "1.0.2", + "speech-rule-engine": "*", + "yargs": "*", + "MathJax": "https://github.com/mathjax/MathJax/tarball/mathjax-node-2.5" }, "main": "./lib/mj-page.js" } From 1346ceb3d8cef7508632f79a0ebefcbc375f9817 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Wed, 11 Feb 2015 15:35:11 -0500 Subject: [PATCH 06/18] Fix AddError() to handle errors with no prefixes. --- lib/mj-page.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/mj-page.js b/lib/mj-page.js index 43831c20..4308637f 100644 --- a/lib/mj-page.js +++ b/lib/mj-page.js @@ -376,9 +376,15 @@ function ReportError(message,currentCallback) { // Add an error to the error list and display it on the console // function AddError(prefix,message,nopush) { - var n = MathJax.ElementJax.ID + 1; - if (prefix !== "") {prefix += " ("+n+"): "} - message = prefix+message; + if (message != null) { + if (MathJax && MathJax.ElementJax) { + var n = MathJax.ElementJax.ID + 1; + if (prefix !== "") {prefix += " ("+n+"): "} + } + message = prefix+message; + } else { + message = prefix; + } if (displayErrors) console.error(message); if (!nopush) errors.push(message); } From c9c691b32f087ad0af9d1b1cc40d0b5a08e95642 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Wed, 11 Feb 2015 15:36:17 -0500 Subject: [PATCH 07/18] Add error if MathJax doesn't load. --- lib/mj-page.js | 1 + lib/mj-single.js | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/mj-page.js b/lib/mj-page.js index 4308637f..5ab6e3f6 100644 --- a/lib/mj-page.js +++ b/lib/mj-page.js @@ -359,6 +359,7 @@ function StartMathJax() { serverState = STATE.STARTED; var script = document.createElement("script"); script.src = MathJaxPath; + script.onerror = function () {AddError("Can't load MathJax.js from "+MathJaxPath)} document.head.appendChild(script); } diff --git a/lib/mj-single.js b/lib/mj-single.js index 3b9d4a3c..0c98739e 100644 --- a/lib/mj-single.js +++ b/lib/mj-single.js @@ -332,6 +332,7 @@ function StartMathJax() { serverState = STATE.STARTED; var script = document.createElement("script"); script.src = MathJaxPath; + script.onerror = function () {AddError("Can't load MathJax.js from "+MathJaxPath)} document.head.appendChild(script); } From cb689f5abb98989d0d1f12864eb49d4e60447f9d Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Wed, 11 Feb 2015 15:48:06 -0500 Subject: [PATCH 08/18] Work around bug in node's url.resolve that damages file:// URLs when the base is about:blank. This allows jsdom 3.x to be used. --- lib/mj-page.js | 6 ++++++ lib/mj-single.js | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/lib/mj-page.js b/lib/mj-page.js index 5ab6e3f6..c84794ae 100644 --- a/lib/mj-page.js +++ b/lib/mj-page.js @@ -116,6 +116,12 @@ function GetWindow() { content = document.body.appendChild(document.createElement("div")); content.id = "MathJax_Content"; content.innerHTML = "$x$ `x` x"; + // + // Node's url.resolve() has a problem with resolving a file:// URL when + // the base URL is "about:blank", so force it to be something else (HACK) + // since jsdom 3.x sets the base to "about:blank". + // + if (document._URL === "about:blank") document._URL = "file:///blank.html"; } // diff --git a/lib/mj-single.js b/lib/mj-single.js index 0c98739e..74b09fab 100644 --- a/lib/mj-single.js +++ b/lib/mj-single.js @@ -117,6 +117,12 @@ function GetWindow() { content = document.body.appendChild(document.createElement("div")); content.id = "MathJax_Content"; content.innerHTML = "$x$ `x` x"; + // + // Node's url.resolve() has a problem with resolving a file:// URL when + // the base URL is "about:blank", so force it to be something else (HACK) + // since jsdom 3.x sets the base to "about:blank". + // + if (document._URL === "about:blank") document._URL = "file:///blank.html"; } // From 487d65516ee85c6774438cfcf2e3ab1cd2259f6e Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Wed, 11 Feb 2015 15:49:46 -0500 Subject: [PATCH 09/18] Fix use of options to jsdom calls. (Is this changed from jsdom 1.0.2, or was it never right?) --- bin/page2mml | 2 +- bin/page2png | 2 +- bin/page2svg | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/page2mml b/bin/page2mml index 7ae0d359..6ff2e4b4 100755 --- a/bin/page2mml +++ b/bin/page2mml @@ -84,7 +84,7 @@ mjAPI.start(); // Process an HTML file: // function processHTML(html,callback) { - var document = jsdom(html,null,{features:{FetchExternalResources: false}}); + var document = jsdom(html,{features:{FetchExternalResources: false}}); var xmlns = getXMLNS(document); mjAPI.typeset({ html:document.body.innerHTML, diff --git a/bin/page2png b/bin/page2png index 2a43d179..f9aef1d7 100755 --- a/bin/page2png +++ b/bin/page2png @@ -98,7 +98,7 @@ if (argv.dpi === 0) {argv.dpi = argv.ex * 16} // pixels properly sized // Process an HTML file: // function processHTML(html,callback) { - var document = jsdom(html,null,{features:{FetchExternalResources: false}}); + var document = jsdom(html,{features:{FetchExternalResources: false}}); var xmlns = getXMLNS(document); mjAPI.typeset({ html: document.body.innerHTML, diff --git a/bin/page2svg b/bin/page2svg index 16cf55b5..bd966af5 100755 --- a/bin/page2svg +++ b/bin/page2svg @@ -100,7 +100,7 @@ mjAPI.start(); // Process an HTML file: // function processHTML(html,callback) { - var document = jsdom(html,null,{features:{FetchExternalResources: false}}); + var document = jsdom(html,{features:{FetchExternalResources: false}}); var xmlns = getXMLNS(document); mjAPI.typeset({ html: document.body.innerHTML, From af95c007de92a796e08ee64c38cda49cb0a1af2d Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Wed, 11 Feb 2015 15:50:23 -0500 Subject: [PATCH 10/18] Move to jsdom 3.1.1 (current latest version) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8b26332b..c57ad442 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "url": "git://github.com/mathjax/MathJax-node.git" }, "dependencies": { - "jsdom": "1.0.2", + "jsdom": "3.1.1", "speech-rule-engine": "*", "yargs": "*", "MathJax": "https://github.com/mathjax/MathJax/tarball/mathjax-node-2.5" From 8fc997be6adef61c82d4c2a1f073290175a53c04 Mon Sep 17 00:00:00 2001 From: sam marshall Date: Thu, 12 Feb 2015 17:26:01 +0000 Subject: [PATCH 11/18] Use OS temp directory os.tmpdir() rather than hard-coded /tmp This makes it easier to use on operating systems (Windows) where /tmp does not exist (and is probably the right thing to do anyhow). --- lib/mj-page.js | 3 ++- lib/mj-single.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/mj-page.js b/lib/mj-page.js index c84794ae..0e8d90b2 100644 --- a/lib/mj-page.js +++ b/lib/mj-page.js @@ -32,6 +32,7 @@ var fmt = require('util').format; var jsdom = require("jsdom").jsdom; var exec = require('child_process').exec; var speech = require('speech-rule-engine'); +var os = require('os'); var displayMessages = false; // don't log Message.Set() calls var displayErrors = true; // show error messages on the console @@ -81,7 +82,7 @@ var MathJax; // filled in once MathJax is loaded var serverState = STATE.STOPPED; // nothing loaded yet var timer; // used to reset MathJax if it runs too long -var tmpfile = "/tmp/mj-single-svg"; // file name prefix to use for temp files +var tmpfile = os.tmpdir() + "/mj-single-svg"; // file name prefix to use for temp files var document, window, content, html; // the DOM elements diff --git a/lib/mj-single.js b/lib/mj-single.js index 74b09fab..8e994ecd 100644 --- a/lib/mj-single.js +++ b/lib/mj-single.js @@ -33,6 +33,7 @@ var fmt = require('util').format; var jsdom = require('jsdom').jsdom; var exec = require('child_process').exec; var speech = require('speech-rule-engine'); +var os = require('os'); var displayMessages = false; // don't log Message.Set() calls var displayErrors = true; // show error messages on the console @@ -79,7 +80,7 @@ var MathJaxConfig; // configuration for when starting MathJax var MathJax; // filled in once MathJax is loaded var serverState = STATE.STOPPED; // nothing loaded yet var timer; // used to reset MathJax if it runs too long -var tmpfile = "/tmp/mj-single-svg"; // file name prefix to use for temp files +var tmpfile = os.tmpdir() + "/mj-single-svg"; // file name prefix to use for temp files var document, window, content, html; // the DOM elements From c6a12cbe899946d5ab9f61e4ec0192c17ef4194a Mon Sep 17 00:00:00 2001 From: sam marshall Date: Thu, 12 Feb 2015 18:01:06 +0000 Subject: [PATCH 12/18] Changed Batik calls to use execFile instead of exec In addition to being more secure, execFile (with arguments as an array) should work on all platforms because it does not require a hardcoded quote character. (On windows, quoting with the single ' causes this call to fail.) --- lib/mj-page.js | 6 +++--- lib/mj-single.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/mj-page.js b/lib/mj-page.js index c84794ae..7003d733 100644 --- a/lib/mj-page.js +++ b/lib/mj-page.js @@ -30,7 +30,7 @@ var fs = require('fs'); var path = require('path'); var fmt = require('util').format; var jsdom = require("jsdom").jsdom; -var exec = require('child_process').exec; +var execFile = require('child_process').execFile; var speech = require('speech-rule-engine'); var displayMessages = false; // don't log Message.Set() calls @@ -659,7 +659,7 @@ function MakeIMG() { function MakePNG() { if (data.renderer === "PNG") { var synch = MathJax.Callback(function () {}); // for synchronization with MathJax - var batikCommand = fmt("java -jar %s -dpi %d '%s.svg'",BatikRasterizerPath,data.dpi,tmpfile); + var batikCommands = ['-jar', BatikRasterizerPath, '-dpi', data.dpi, tmpfile + '.svg']; var tmpSVG = tmpfile+".svg", tmpPNG = tmpfile+".png"; var nodes = document.getElementsByClassName("MathJax_SVG"); var check = function (err) {if (err) {AddError(err.message); return true}} @@ -677,7 +677,7 @@ function MakePNG() { ].join("\n"); fs.writeFile(tmpSVG,svg,function (err) { if (check(err)) return PNG(i-1); - exec(batikCommand, function (err,stdout,stderr) { + execFile('java', batikCommands, function (err,stdout,stderr) { if (check(err)) {fs.unlinkSync(tmpSVG); return PNG(i-1)} fs.readFile(tmpPNG,null,function (err,buffer) { if (!check(err)) { diff --git a/lib/mj-single.js b/lib/mj-single.js index 74b09fab..2e96a802 100644 --- a/lib/mj-single.js +++ b/lib/mj-single.js @@ -31,7 +31,7 @@ var fs = require('fs'); var path = require('path'); var fmt = require('util').format; var jsdom = require('jsdom').jsdom; -var exec = require('child_process').exec; +var execFile = require('child_process').execFile; var speech = require('speech-rule-engine'); var displayMessages = false; // don't log Message.Set() calls @@ -456,13 +456,13 @@ function GetSVG(result) { function GetPNG(result) { var svgfile = result.svgfile; delete result.svgfile; if (data.png) { - var batikCommand = fmt("java -jar %s -dpi %d '%s.svg'",BatikRasterizerPath,data.dpi,tmpfile); + var batikCommands = ['-jar', BatikRasterizerPath, '-dpi', data.dpi, tmpfile + '.svg']; var synch = MathJax.Callback(function () {}); // for synchronization with MathJax var check = function (err) {if (err) {AddError(err.message); synch(); return true}} var tmpSVG = tmpfile+".svg", tmpPNG = tmpfile+".png"; fs.writeFile(tmpSVG,svgfile,function (err) { if (check(err)) return; - exec(batikCommand, function (err,stdout,stderr) { + execFile('java', batikCommands, function (err,stdout,stderr) { if (check(err)) {fs.unlinkSync(tmpSVG); return} fs.readFile(tmpPNG,null,function (err,buffer) { result.png = "data:image/png;base64,"+(buffer||"").toString('base64'); From 3ca651a1db27a73ed4af77f2833494495962a66d Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Sat, 14 Feb 2015 09:43:21 -0500 Subject: [PATCH 13/18] Fix MathJax.js URL to work with Windows. Resolves issue #70. --- lib/mj-page.js | 6 +++++- lib/mj-single.js | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/mj-page.js b/lib/mj-page.js index c84794ae..f71d9abb 100644 --- a/lib/mj-page.js +++ b/lib/mj-page.js @@ -28,6 +28,7 @@ var http = require('http'); var fs = require('fs'); var path = require('path'); +var url = require('url'); var fmt = require('util').format; var jsdom = require("jsdom").jsdom; var exec = require('child_process').exec; @@ -74,7 +75,10 @@ var STATE = { BUSY: 4 // MathJax currently processing math }; -var MathJaxPath = "file://"+require.resolve('MathJax/unpacked/MathJax'); +// +// The MathJaxPath is normaized against file:/// so that Windows paths are correct +// +var MathJaxPath = url.resolve("file:///","file:"+require.resolve('MathJax/unpacked/MathJax')); var BatikRasterizerPath = path.resolve(__dirname,'..','batik/batik-rasterizer.jar'); var MathJaxConfig; // configuration for when starting MathJax var MathJax; // filled in once MathJax is loaded diff --git a/lib/mj-single.js b/lib/mj-single.js index 74b09fab..c4ac9963 100644 --- a/lib/mj-single.js +++ b/lib/mj-single.js @@ -29,6 +29,7 @@ var http = require('http'); var fs = require('fs'); var path = require('path'); +var url = require('url'); var fmt = require('util').format; var jsdom = require('jsdom').jsdom; var exec = require('child_process').exec; @@ -73,7 +74,10 @@ var STATE = { BUSY: 4 // MathJax currently processing math }; -var MathJaxPath = "file://"+require.resolve('MathJax/unpacked/MathJax'); +// +// The MathJaxPath is normaized against file:/// so that Windows paths are correct +// +var MathJaxPath = url.resolve("file:///","file:"+require.resolve('MathJax/unpacked/MathJax')); var BatikRasterizerPath = path.resolve(__dirname,'..','batik/batik-rasterizer.jar'); var MathJaxConfig; // configuration for when starting MathJax var MathJax; // filled in once MathJax is loaded From 524458c9f79ac0fb0753d4ab408c2e409d34e7c0 Mon Sep 17 00:00:00 2001 From: sam marshall Date: Fri, 13 Feb 2015 10:40:51 +0000 Subject: [PATCH 14/18] Allow extensions to be specified on command line Adds an 'extensions' option to config which takes a comma-separated list of extensions to add to the default set. Then adds --extensions parameter to each command-line tool to specify this value. This allows use of MathJax features such as displaying invalid TeX instead of failing to render (--extensions TeX/noUndefined), and stripping out dangerous links from MathML (--extensions Safe). --- bin/am2mml | 7 ++++++- bin/am2png | 6 +++++- bin/am2svg | 6 +++++- bin/mml2mml | 6 +++++- bin/mml2png | 6 +++++- bin/mml2svg | 6 +++++- bin/mml2svg-html5 | 6 +++++- bin/page2mml | 6 +++++- bin/page2png | 6 +++++- bin/page2svg | 6 +++++- bin/tex2mml | 7 ++++++- bin/tex2png | 6 +++++- bin/tex2svg | 6 +++++- bin/tex2svg-filter | 6 +++++- lib/mj-page.js | 18 ++++++++++++++++-- lib/mj-single.js | 20 +++++++++++++++++--- 16 files changed, 105 insertions(+), 19 deletions(-) diff --git a/bin/am2mml b/bin/am2mml index 1ebcc0ec..71bcd43c 100755 --- a/bin/am2mml +++ b/bin/am2mml @@ -43,6 +43,10 @@ var argv = require("yargs") semantics: { boolean: true, describe: "add AsciiMath code in tag" + }, + extensions: { + default: "", + describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'" } }) .argv; @@ -52,7 +56,8 @@ mjAPI.config({ menuSettings: { semantics: argv.semantics } - } + }, + extensions: argv.extensions }); mjAPI.start(); diff --git a/bin/am2png b/bin/am2png index 05af7a39..0328d6c4 100755 --- a/bin/am2png +++ b/bin/am2png @@ -48,12 +48,16 @@ var argv = require("yargs") width: { default: 100, describe: "width of container in ex" + }, + extensions: { + default: "", + describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'" } }) .argv; if (argv.font === "STIX") argv.font = "STIX-Web"; -mjAPI.config({MathJax: {SVG: {font: argv.font}}}); +mjAPI.config({MathJax: {SVG: {font: argv.font}}, extensions: argv.extensions}); mjAPI.start(); if (argv.dpi === 0) {argv.dpi = argv.ex * 16} // pixels properly sized diff --git a/bin/am2svg b/bin/am2svg index 25916f67..e9f7b7dc 100755 --- a/bin/am2svg +++ b/bin/am2svg @@ -55,12 +55,16 @@ var argv = require("yargs") width: { default: 100, describe: "width of container in ex" + }, + extensions: { + default: "", + describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'" } }) .argv; if (argv.font === "STIX") argv.font = "STIX-Web"; -mjAPI.config({MathJax: {SVG: {font: argv.font}}}); +mjAPI.config({MathJax: {SVG: {font: argv.font}}, extensions: argv.extensions}); mjAPI.start(); mjAPI.typeset({ diff --git a/bin/mml2mml b/bin/mml2mml index 45e6d794..33daeb0d 100755 --- a/bin/mml2mml +++ b/bin/mml2mml @@ -40,11 +40,15 @@ var argv = require("yargs") speechstyle: { default: "default", describe: "style to use for speech text (default, brief, sbrief)" + }, + extensions: { + default: "", + describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'" } }) .argv; -mjAPI.config({}); +mjAPI.config({extensions: argv.extensions}); mjAPI.start(); mjAPI.typeset({ diff --git a/bin/mml2png b/bin/mml2png index 4e67e14a..d97471db 100755 --- a/bin/mml2png +++ b/bin/mml2png @@ -47,12 +47,16 @@ var argv = require("yargs") width: { default: 100, describe: "width of container in ex" + }, + extensions: { + default: "", + describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'" } }) .argv; if (argv.font === "STIX") argv.font = "STIX-Web"; -mjAPI.config({MathJax: {SVG: {font: argv.font}}}); +mjAPI.config({MathJax: {SVG: {font: argv.font}}, extensions: argv.extensions}); mjAPI.start(); if (argv.dpi === 0) {argv.dpi = argv.ex * 16} // pixels properly sized diff --git a/bin/mml2svg b/bin/mml2svg index ee7e2af6..fd7348b9 100755 --- a/bin/mml2svg +++ b/bin/mml2svg @@ -55,12 +55,16 @@ var argv = require("yargs") width: { default: 100, describe: "width of container in ex" + }, + extensions: { + default: "", + describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'" } }) .argv; if (argv.font === "STIX") argv.font = "STIX-Web"; -mjAPI.config({MathJax: {SVG: {font: argv.font}}}); +mjAPI.config({MathJax: {SVG: {font: argv.font}}, extensions: argv.extensions}); mjAPI.start(); mjAPI.typeset({ diff --git a/bin/mml2svg-html5 b/bin/mml2svg-html5 index 7592631c..6788d7aa 100755 --- a/bin/mml2svg-html5 +++ b/bin/mml2svg-html5 @@ -63,12 +63,16 @@ var argv = require("yargs") width: { default: 100, describe: "width of container in ex" + }, + extensions: { + default: "", + describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'" } }) .argv; if (argv.font === "STIX") argv.font = "STIX-Web"; -mjAPI.config({MathJax: {SVG: {font: argv.font}}}); +mjAPI.config({MathJax: {SVG: {font: argv.font}}, extensions: argv.extensions}); mjAPI.start(); // diff --git a/bin/page2mml b/bin/page2mml index 6ff2e4b4..3ceec26c 100755 --- a/bin/page2mml +++ b/bin/page2mml @@ -71,13 +71,17 @@ var argv = require("yargs") width: { default: 100, describe: "width of container in ex" + }, + extensions: { + default: "", + describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'" } }) .argv; argv.format = argv.format.split(/ *, */); -mjAPI.config({MathJax: {menuSettings: {semantics: argv.semantics}}}); +mjAPI.config({MathJax: {menuSettings: {semantics: argv.semantics}}, extensions: argv.extensions}); mjAPI.start(); // diff --git a/bin/page2png b/bin/page2png index f9aef1d7..4b526d2a 100755 --- a/bin/page2png +++ b/bin/page2png @@ -83,13 +83,17 @@ var argv = require("yargs") width: { default: 100, describe: "width of container in ex" + }, + extensions: { + default: "", + describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'" } }) .argv; argv.format = argv.format.split(/ *, */); if (argv.font === "STIX") argv.font = "STIX-Web"; -mjAPI.config({MathJax: {SVG: {font: argv.font}}}); +mjAPI.config({MathJax: {SVG: {font: argv.font}}, extensions: argv.extensions}); mjAPI.start(); if (argv.dpi === 0) {argv.dpi = argv.ex * 16} // pixels properly sized diff --git a/bin/page2svg b/bin/page2svg index bd966af5..95de942f 100755 --- a/bin/page2svg +++ b/bin/page2svg @@ -87,13 +87,17 @@ var argv = require("yargs") width: { default: 100, describe: "width of container in ex" + }, + extensions: { + default: "", + describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'" } }) .argv; argv.format = argv.format.split(/ *, */); if (argv.font === "STIX") argv.font = "STIX-Web"; -mjAPI.config({MathJax: {SVG: {font: argv.font}}}); +mjAPI.config({MathJax: {SVG: {font: argv.font}}, extensions: argv.extensions}); mjAPI.start(); // diff --git a/bin/tex2mml b/bin/tex2mml index 029265bd..e6a3f597 100755 --- a/bin/tex2mml +++ b/bin/tex2mml @@ -51,6 +51,10 @@ var argv = require("yargs") notexhints: { boolean: true, describe: "don't add TeX-specific classes" + }, + extensions: { + default: "", + describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'" } }) .argv; @@ -61,7 +65,8 @@ mjAPI.config({ semantics: argv.semantics, texHints: !argv.notexhints } - } + }, + extensions: argv.extensions }); mjAPI.start(); diff --git a/bin/tex2png b/bin/tex2png index 213b679c..1129d4ad 100755 --- a/bin/tex2png +++ b/bin/tex2png @@ -52,12 +52,16 @@ var argv = require("yargs") width: { default: 100, describe: "width of container in ex" + }, + extensions: { + default: "", + describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'" } }) .argv; if (argv.font === "STIX") argv.font = "STIX-Web"; -mjAPI.config({MathJax: {SVG: {font: argv.font}}}); +mjAPI.config({MathJax: {SVG: {font: argv.font}}, extensions: argv.extensions}); mjAPI.start(); if (argv.dpi === 0) {argv.dpi = argv.ex * 16} // pixels properly sized diff --git a/bin/tex2svg b/bin/tex2svg index de69e79c..30475576 100755 --- a/bin/tex2svg +++ b/bin/tex2svg @@ -59,12 +59,16 @@ var argv = require("yargs") width: { default: 100, describe: "width of container in ex" + }, + extensions: { + default: "", + describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'" } }) .argv; if (argv.font === "STIX") argv.font = "STIX-Web"; -mjAPI.config({MathJax: {SVG: {font: argv.font}}}); +mjAPI.config({MathJax: {SVG: {font: argv.font}}, extensions: argv.extensions}); mjAPI.start(); mjAPI.typeset({ diff --git a/bin/tex2svg-filter b/bin/tex2svg-filter index e103475a..19c6db46 100755 --- a/bin/tex2svg-filter +++ b/bin/tex2svg-filter @@ -63,12 +63,16 @@ var argv = require("yargs") width: { default: 100, describe: "width of container in ex" + }, + extensions: { + default: "", + describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'" } }) .argv; if (argv.font === "STIX") argv.font = "STIX-Web"; -mjAPI.config({MathJax: {SVG: {font: argv.font}}}); +mjAPI.config({MathJax: {SVG: {font: argv.font}}, extensions: argv.extensions}); mjAPI.start(); var prefix = argv._[0]; // the file prefix diff --git a/lib/mj-page.js b/lib/mj-page.js index c84794ae..acf8a37e 100644 --- a/lib/mj-page.js +++ b/lib/mj-page.js @@ -36,6 +36,7 @@ var speech = require('speech-rule-engine'); var displayMessages = false; // don't log Message.Set() calls var displayErrors = true; // show error messages on the console var undefinedChar = false; // unknown characters are not saved in the error array +var extensions = ''; // no additional extensions used var defaults = { ex: 6, // ex-size in pixels @@ -341,6 +342,16 @@ function ConfigureMathJax() { } }; + if (extensions) { + // + // Parse added extensions list and add to standard ones + // + var extensionList = extensions.split(/s*,\s*/); + for (var i = 0; i < extensionList.length; i++) { + var matches = extensionList[i].match(/^(.*?)(\.js)?$/); + window.MathJax.extensions.push(matches[1] + '.js'); + } + } if (MathJaxConfig) {Insert(window.MathJax,MathJaxConfig)} } @@ -797,17 +808,20 @@ exports.start = function () {RestartMathJax()} // Configure MathJax and the API // You can pass additional configuration options to MathJax using the // MathJax property, and can set displayErrors and displayMessages -// that control the display of error messages +// that control the display of error messages, and extensions to add +// additional MathJax extensions to the base or to sub-categories. // // E.g. -// mjAPI.congif({ +// mjAPI.config({ // MathJax: {SVG: {font: "STIX-Web"}}, // displayErrors: false +// extensions: 'Safe,TeX/noUndefined' // }); // exports.config = function (config) { if (config.displayMessages != null) {displayMessages = config.displayMessages} if (config.displayErrors != null) {displayErrors = config.displayErrors} if (config.undefinedCharError != null) {undefinedChar = config.undefinedCharError} + if (config.extensions != null) {extensions = config.extensions} if (config.MathJax) {MathJaxConfig = config.MathJax} } diff --git a/lib/mj-single.js b/lib/mj-single.js index 74b09fab..268cf7d2 100644 --- a/lib/mj-single.js +++ b/lib/mj-single.js @@ -37,6 +37,7 @@ var speech = require('speech-rule-engine'); var displayMessages = false; // don't log Message.Set() calls var displayErrors = true; // show error messages on the console var undefinedChar = false; // unknown characters are not saved in the error array +var extensions = ''; // no additional extensions used var defaults = { ex: 6, // ex-size in pixels @@ -315,6 +316,16 @@ function ConfigureMathJax() { } }; + if (extensions) { + // + // Parse added extensions list and add to standard ones + // + var extensionList = extensions.split(/s*,\s*/); + for (var i = 0; i < extensionList.length; i++) { + var matches = extensionList[i].match(/^(.*?)(\.js)?$/); + window.MathJax.extensions.push(matches[1] + '.js'); + } + } if (MathJaxConfig) {Insert(window.MathJax,MathJaxConfig)} } @@ -660,17 +671,20 @@ exports.start = function () {RestartMathJax()} // Configure MathJax and the API // You can pass additional configuration options to MathJax using the // MathJax property, and can set displayErrors and displayMessages -// that control the display of error messages +// that control the display of error messages, and extensions to add +// additional MathJax extensions to the base or to sub-categories. // // E.g. -// mjAPI.congif({ +// mjAPI.config({ // MathJax: {SVG: {font: "STIX-Web"}}, -// displayErrors: false +// displayErrors: false, +// extensions: 'Safe,TeX/noUndefined' // }); // exports.config = function (config) { if (config.displayMessages != null) {displayMessages = config.displayMessages} if (config.displayErrors != null) {displayErrors = config.displayErrors} if (config.undefinedCharError != null) {undefinedChar = config.undefinedCharError} + if (config.extensions != null) {extensions = config.extensions} if (config.MathJax) {MathJaxConfig = config.MathJax} } From 0e8143e6d11c67ed9c407c33593e45d0cd6045a6 Mon Sep 17 00:00:00 2001 From: Peter Krautzberger Date: Thu, 19 Mar 2015 11:33:30 +0100 Subject: [PATCH 15/18] Update mathjax branch to 2.5.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c57ad442..a24e4034 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "jsdom": "3.1.1", "speech-rule-engine": "*", "yargs": "*", - "MathJax": "https://github.com/mathjax/MathJax/tarball/mathjax-node-2.5" + "MathJax": "https://github.com/mathjax/MathJax/tarball/mathjax-node-2.5.1" }, "main": "./lib/mj-page.js" } From 0b4b10ff578932e15c461649238aab2e7dbe1008 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Mon, 30 Mar 2015 17:44:56 -0400 Subject: [PATCH 16/18] Compensate for removed MathEvents.js. Resolves issues #85, #66, and #82. --- lib/mj-page.js | 4 ++++ lib/mj-single.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/mj-page.js b/lib/mj-page.js index 457d475d..4356d991 100644 --- a/lib/mj-page.js +++ b/lib/mj-page.js @@ -158,6 +158,10 @@ function ConfigureMathJax() { delete MathJax.Hub.config.styles; // don't need any styles MathJax.Hub.Startup.MenuZoom = function () {}; // don't load menu or zoom code + MathJax.Extension.MathEvents = { + Event:{}, Touch:{}, Hover:{} // fake structure to avid errors + }; + MathJax.Ajax.loaded[MathJax.Ajax.fileURL("[MathJax]/extensions/MathEvents.js")] = true; // // When creating stylesheets, no need to wait for them diff --git a/lib/mj-single.js b/lib/mj-single.js index ef949ce3..87293420 100644 --- a/lib/mj-single.js +++ b/lib/mj-single.js @@ -159,6 +159,10 @@ function ConfigureMathJax() { delete MathJax.Hub.config.styles; // don't need any styles MathJax.Hub.Startup.MenuZoom = function () {}; // don't load menu or zoom code + MathJax.Extension.MathEvents = { + Event:{}, Touch:{}, Hover:{} // fake structure to avid errors + }; + MathJax.Ajax.loaded[MathJax.Ajax.fileURL("[MathJax]/extensions/MathEvents.js")] = true; // // When creating stylesheets, no need to wait for them From 0ba92ef897495683bd7bad0e6e693b6f232768f5 Mon Sep 17 00:00:00 2001 From: Peter Krautzberger Date: Wed, 1 Apr 2015 10:00:10 +0200 Subject: [PATCH 17/18] Update installation instructions (to use npm) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ed0e11c8..63a398fc 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ of calling the MathJax API. Use - npm install https://github.com/mathjax/MathJax-node/tarball/master + npm install MathJax-node to install MathJax-node and its dependencies. From 09f85fca97ee82a68739f7618b683d2d1d921090 Mon Sep 17 00:00:00 2001 From: Peter Krautzberger Date: Wed, 1 Apr 2015 10:04:21 +0200 Subject: [PATCH 18/18] Update Batik instructions Fixes #84 --- batik/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/batik/README.md b/batik/README.md index e4ea519a..31eef190 100644 --- a/batik/README.md +++ b/batik/README.md @@ -2,4 +2,6 @@ If you intend to use MathJax-node's ability to create PNG images, you should install [batik](http://xmlgraphics.apache.org/batik/download.html) in this directory. Just download it and unpack it here. You need `batik-rasterizer.jar` and the `lib` directory to be in the top level -of this directory. +of this directory. Since Batik v1.8 you have to either create a symlink +to `batik-rasterizer-1.8.jar` or change `mj-page.js` and `mj-single.js` +to point to the version-specific file name.