how to configure mathjax-node to support chemical equations, such as \ce{H2SO4}.

56 views
Skip to first unread message

hjya...@gmail.com

unread,
Aug 18, 2017, 8:39:37 PM8/18/17
to MathJax Users
  • I try to use mathjax-node to generate svg for chemical equations, following is the snippet:
===========
// a simple TeX-input example
var mjAPI = require("mathjax-node");
// dont know how to configure adding mhchem3/mhchem.js
mjAPI.config({
MathJax: {
extesnions:["https://cdnjs.cloudflare.com/ajax/libs/mathjax-mhchem/3.2.0/mhchem.js"]
}
});
mjAPI.start();

var yourMath = 'E = mc^2 \ce{H2SO4}';

mjAPI.typeset({
math: yourMath,
format: "TeX", // "inline-TeX", "MathML"
svg: true, // svg:true,mml:true
}, function (data) {
if (!data.errors) {
console.log(data.svg)
}
});
===========
  • result of \ce{H2SO4} not as expected, just look like ceH2SO4
My question is how to configure mathjax-node to support chemical equations such as \ce{H2SO4}.

albert....@gmail.com

unread,
Aug 20, 2017, 4:30:10 AM8/20/17
to MathJax Users, hjya...@gmail.com

Disclaimer: I didn't try anything

I think that at least  extesnions should read extensions

Albert
Message has been deleted

hjya...@gmail.com

unread,
Aug 20, 2017, 8:40:08 PM8/20/17
to MathJax Users, hjya...@gmail.com
Now I guess, NO need to configure mhchem.js at all, mathjax-node auto load mhchem.js if need.

My mistake is : I need to escape backslash in javascript strings. So I need to type '\\ce{H2SO4}' instead of '\ce{H2SO4'.

Following is my snippet, it works.
=======================
// a simple TeX-input example
var mjAPI = require("mathjax-node");
// No need to configure adding mhchem3/mhchem.js at all.
mjAPI.config({
MathJax: {
TeX:{
}
}
});
mjAPI.start();
// \\ce{...} double \\ is important, because we need to escape backslash in javascript string.
var yourMath = '\\ce{H2SO4}';


mjAPI.typeset({
math: yourMath,
format: "TeX", // "inline-TeX", "MathML"
svg: true, // svg:true,mml:true
}, function (data) {
if (!data.errors) {
console.log(data.svg)
}
});
===============
Reply all
Reply to author
Forward
0 new messages