mathjax / MathJax-node

MathJax for Node
Apache License 2.0
609 stars 96 forks source link

xyjax compatibility #135

Closed pkra closed 1 year ago

pkra commented 8 years ago

Just a note to look into xyjax compatibility. I ran into issues when trying it out; will add more information later.

pkra commented 8 years ago

Some notes.

Sample:

// xytest.js 
var mjAPI = require("./lib/mj-single.js");
mjAPI.config({
  MathJax: {
    // place https://github.com/sonoisa/XyJax/blob/master/extensions/TeX/xypic.js in `./node_modules/mathjax/unpacked/extensions/tex/`
    TeX: { extensions: ["xypic.js"]}
  }
});
mjAPI.start();

var yourMath = '\\begin{xy} \\xymatrix { U \\ar@/_/[ddr]_y \\ar@{.>}[dr]|{\\langle x,y \\rangle} \\ar@/^/[drr]^x \\\\ & X \\times_Z Y \\ar[d]^q \\ar[r]_p & X \\ar[d]_f \\\\ & Y \\ar[r]^g & Z } \\end{xy}';

mjAPI.typeset({
  math: yourMath,
  format: "TeX",
  svg:true,
}, function (data) {
  if (!data.errors) {console.log(data.svg)}
});
$ node xytest.js 
Error: TypeError: Cannot read property 'Get' of undefined
    at MML.mbase.Augment.SVGgetScale (file:///tmp/MathJax-node/node_modules/mathjax/unpacked/jax/output/SVG/jax.js?rev=2.6.1:1358:66)
    at MML.mbase.Augment.SVGhandleSpace (file:///tmp/MathJax-node/node_modules/mathjax/unpacked/jax/output/SVG/jax.js?rev=2.6.1:1226:16)
    at xypic.Shape.TextShape.Augment._draw (file:///tmp/MathJax-node/node_modules/mathjax/unpacked/extensions/TeX/xypic.js?rev=2.6.1:16617:16)
    at xypic.Shape.TextShape.xypic.Shape.Subclass.getBoundingBox (file:///tmp/MathJax-node/node_modules/mathjax/unpacked/extensions/TeX/xypic.js?rev=2.6.1:6815:19)
    at memo [as getBoundingBox] (file:///tmp/MathJax-node/node_modules/mathjax/unpacked/extensions/TeX/xypic.js?rev=2.6.1:1103:26)
    at AST.ObjectBox.Text.Augment.toDropShape (file:///tmp/MathJax-node/node_modules/mathjax/unpacked/extensions/TeX/xypic.js?rev=2.6.1:12385:25)
    at AST.Object.Augment.toDropShape (file:///tmp/MathJax-node/node_modules/mathjax/unpacked/extensions/TeX/xypic.js?rev=2.6.1:12211:39)
    at AST.Command.Xymatrix.Entry.SimpleEntry.Augment.toShape (file:///tmp/MathJax-node/node_modules/mathjax/unpacked/extensions/TeX/xypic.js?rev=2.6.1:15411:52)
    at file:///tmp/MathJax-node/node_modules/mathjax/unpacked/extensions/TeX/xypic.js?rev=2.6.1:15006:33
    at FP.List.Cons.FP.List.Subclass.map (file:///tmp/MathJax-node/node_modules/mathjax/unpacked/extensions/TeX/xypic.js?rev=2.6.1:164:27)
dpvc commented 8 years ago

Note that XyJax is HTML-CSS specific (e.g., line16288), so it is not going to work with mathjax-node. It also uses offsetHeight (e.g., line 16327), so it will not work in jsdom. It might be possible to update XyJax to use CommonHTML and use its measurements of heights and widths, but I haven't looked at how deeply the connection between XyJax and HTML-CSS runs.

pkra commented 8 years ago

Thanks for looking into it.

Note that XyJax is HTML-CSS specific

Hm, I thought it supports SVG output (http://sonoisa.github.io/xyjax/xyjax.html claims this and seems to be doing fine.)

It might be possible to update XyJax to use CommonHTML and use its measurements of heights and widths, but I haven't looked at how deeply the connection between XyJax and HTML-CSS runs.

Right.

I had contacted the author when I opened this; maybe there's a chance for some downstream improvements or advice.

dpvc commented 8 years ago

I thought it supports SVG output

It does seem to say that. I didn't look real closely, but did look for where it got the bounding box information for the TextShape, and came on the HTML-CSS output. Perhaps there is also support for the SVG output farther down in the file.

Ah, it turns out that there is. It looks like the problem may be line 16598, which should be

var scale = this.SVGgetScale(svg);

(the addition of the parameter may have come after XyJax was developed). See if that helps things out.

dpvc commented 8 years ago

There is also another instance of this at line 16713

pkra commented 8 years ago

Thanks for the pointers. I'll take another look.

pkra commented 8 years ago

It looks like the problem may be line 16598, which should be var scale = this.SVGgetScale(svg);

I tried that and got the same errors.

Then I poked around the code and got nowhere. Then my example suddenly rendered and I finally noticed that I had accidentally commented out https://github.com/sonoisa/XyJax/blob/master/extensions/TeX/xypic.js#L16617 (with or without @dpvc's suggested change (var scale = this.SVGgetScale(svg);).

But that sounds like a bad idea :smile:. I'll update this when I have the time to work more on this.

ysulyma commented 7 years ago

I'm also interested in this—I've been looking at prerendering MathJax and am pleased with the results so far, but I make heavy use of xyjax. I could try hacking it myself, but I'm worried about it becoming fragile (and don't have that much time to spend on it either).

For that matter (this discussion should probably take place somewhere else, but I'm not sure where), would it be possible for MathJax to adopt xyjax and maintain it officially? For myself and may other users (e.g. Stacks Project), not having commutative diagrams is unthinkable, and xyjax is a godsend. Unfortunately, it doesn't seem to be maintained anymore.

pkra commented 7 years ago

would it be possible for MathJax to adopt xyjax and maintain it officially

I'm afraid we don't have the resources for this at this time.

(this discussion should probably take place somewhere else, but I'm not sure where)

Probably the mathjax-dev list.

PatrickMassot commented 7 years ago

would it be possible for MathJax to adopt xyjax and maintain it officially?

To me it would be feel very strange to see a lot of efforts going into allowing MathJax to support a complicated obsolete LaTeX package. If there is suddenly a lot of available developer time (not very likely I guess) it would probably be much better spent trying to port tikz, or at least tikz-cd.

In the mean time, one can use the standalone class and pdf2svg to convert commutative diagams (specified using any package you want) into svg images. It should even be possible to include the original source code somewhere for accessibility purposes.

pkra commented 7 years ago

Please move the discussion to a mailing list (and perhaps avoid speculation).

Note that the MathJax development priorities are set by the team in coordination with the MathJax Consortium, as well as our steering and technical committees.

pkra commented 1 year ago

Cleaning up my old issues.