mathjax / MathJax-node

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

[SVG ouptut] API for stylesheet #283

Closed pkra closed 7 years ago

pkra commented 7 years ago

This came up on https://github.com/pkra/mathjax-node-page/issues/18.

There's currently an API to get the stylesheet needed for the CommonHTML output but no API for the stylesheet used for SVG output. It used to be that mjpage added a slimmed down stylesheet when using the SVG output.

Should there be a way to generate it or should this be handled differently?

dpvc commented 7 years ago

A quick look at the code suggests that for the "self-contained" SVG images that were generated by mj-single, there are only three styles that affect the SVG elements themselves (the ones that handle the font for monospace and sans-serif fonts, and the one for the color of href links). The rest all have to do with the surrounding machinery of MathJax, and its preventing bleed-through of CSS from the surrounding page into the SVG.

Your current mjpage implementation does not incorporate the container elements that MathJax uses for things like centering displayed equations, and so on, so I'm not sure how useful obtaining the rest of the CSS would be. It seems that, under the new organization, it is the role of mjpage to insert whatever container elements it thinks are needed, and so the CSS to control them should be handled through mjpage, not MathJax itself. That is, mjpage should manage the stylesheet that handles centering and so on (though it should probably include the three rules needed for the fonts and the links) since it will depend on the DOM elements that it inserts; the CSS from MathJax probably won't be what is needed. Also, the selectors for the rules for the fonts probably will need to be modified (since they depend on the SVG being inside a MathJax container element with class MathJax_SVG, and that may not be what mjpage uses). So it might not even be useful to get those three rules from MathJax.

MissMyCat commented 7 years ago

@dpvc hi I wonder generate sgv from Latex which contains Chinese chacater, but the error is SVG - Unknown character: U+FF08 in STIXMathJax_SansSerif SVG - Unknown character: U+5728 in STIXMathJax_SansSerif SVG - Unknown character: U+8303 in STIXMathJax_SansSerif SVG - Unknown character: U+56F4 in STIXMathJax_SansSerif SVG - Unknown character: U+5185 in STIXMathJax_SansSerif SVG - Unknown character: U+5747 in STIXMathJax_SansSerif SVG - Unknown character: U+7ED9 in STIXMathJax_SansSerif SVG - Unknown character: U+5206 in STIXMathJax_SansSerif SVG - Unknown character: U+FF09 in STIXMathJax_SansSerif

cmd is node D:/node_modules/mathjax-node/bin/tex2svg2 "\text{1}.\text{844}\mathsf{(在}\text{1}.\text{842}\sim \text{1}.\text{846}\mathsf{范围内均给分)}" may I add new fonts to support it ? Or do something

pkra commented 7 years ago

@MissMyCat please don't post unrelated issues on existing issue threads.

the error is SVG - Unknown character: U+FF08 in STIXMathJax_SansSerif

that's only a warning; system fonts will be used for characters not provided by the chosen font.

may I add new fonts to support it ?

This is #80; that's a difficult problem though.

MissMyCat commented 7 years ago

@pkra thanks for your reply. I post problem here because when I used those characters Unknown for SVG, the result style is mess mess

As you can see, Characters overlap each other.

Is this relate to style or font?

dpvc commented 7 years ago

I post problem here because

I think Peter meant that you should start a new issue when you have a new problem rather than adding to an existing issue that has already been answered (and in this case is pretty much unrelated to the issue you are having).

As for the font warning messages, you could edit the bin/tex2svg file to change

mjAPI.config({MathJax: {SVG: {font: argv.font}}, extensions: argv.extensions});

to

mjAPI.config({
  MathJax: {SVG: {font: argv.font}},
  extensions: argv.extensions,
  undefinedCharError: false
});

to prevent them from being reported.

As for the characters themselves, mathjax-node will not be able to place these properly, because it doesn't have the bounding box data required to know how much space they take up (that is one reason you get the warning). Because mathjax-node can not find out the sizes as it can in a browser (that has a DOM whose elements can be measured), it tries to use a monospaced font for unknown characters, and assumes the width of those characters to all be the same and relatively small (1ex as I recall). Your characters probably aren't in your system's monospace font, and when you view the file, you are getting them from a variable-width font where they take up more space. So they aren't placed properly.

Unfortunately, there is very little that mathjax-node can do about that without having a more fully-featured DOM implementation to work with.

pkra commented 7 years ago

Realized I never responded to the actual topic.

mjpage should manage the stylesheet that handles centering and so on (though it should probably include the three rules needed for the fonts and the links)

Makes sense.