MathJax-node icon indicating copy to clipboard operation
MathJax-node copied to clipboard

xyjax compatibility

Open pkra opened this issue 8 years ago • 11 comments

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

pkra avatar Dec 29 '15 12:12 pkra

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)}
});
  • First error can be solved by disabling xypic's own browser test https://github.com/sonoisa/XyJax/blob/master/extensions/TeX/xypic.js#L5144
  • Second error comes down to bbox; not sure how to overcome that.
$ 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)

pkra avatar Feb 18 '16 12:02 pkra

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.

dpvc avatar Feb 22 '16 09:02 dpvc

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.

pkra avatar Feb 22 '16 10:02 pkra

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 avatar Feb 22 '16 10:02 dpvc

There is also another instance of this at line 16713

dpvc avatar Feb 22 '16 10:02 dpvc

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

pkra avatar Feb 22 '16 10:02 pkra

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.

pkra avatar Feb 22 '16 11:02 pkra

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.

ysulyma avatar Feb 20 '17 06:02 ysulyma

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.

pkra avatar Feb 20 '17 08:02 pkra

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.

PatrickMassot avatar Feb 20 '17 13:02 PatrickMassot

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 avatar Feb 22 '17 10:02 pkra

Cleaning up my old issues.

pkra avatar Dec 01 '22 08:12 pkra