mathjax / MathJax-node

MathJax for Node
Apache License 2.0
615 stars 97 forks source link

[mj-single] passing data through to the result object #239

Closed pkra closed 7 years ago

pkra commented 8 years ago

In the context of #205, #206, #207 and other work, I've been wondering about passing data through to the result object. I also wondered why the results do not include the input information (source, format etc)

Anyway, all I could come up with was abusing state but that seems like a limited and generally bad approach. Is there a better way? Is this just a terrible idea?

dpvc commented 8 years ago

I also wondered why the results do not include the input information (source, format etc)

The input data has properties like svg: true and so on, while the output has svg: "...", so the input data would be replace by the output in some cases, which is a bit confusing.

I've been wondering about passing data through to the result object

Sure, something like that would probably be a good idea. It would be possible to include an object within the input data that can be used to "seed" the output data. Something like

mathjax.typeset({
  math: "x+1",
  format: "TeX",
  mml: true,
  data: {
    i: 1
  }
}, function (data) {
  console.log(data.i+" => "+data.mml);
});

could be used.

You are right that state could be used for that, and while it is a bit of an abuse of its purpose, I can see where this information could be considered to be "state" information. But it would probably be better to have a way that is designed for this purpose.

pkra commented 8 years ago

the input data would be replace by the output in some cases, which is a bit confusing.

Right.

something like that would probably be a good idea.

Ok. Marking this a feature request for now.

dpvc commented 8 years ago

I'm thinking that passing the original data object as a second argument (in addition to the results object) to the typeset callback would do the trick. This would be backward compatible, and would still give access to the original data.

pkra commented 8 years ago

Oh, that'd be nice and simple. I'll make a PR.