mathjax / MathJax

Beautiful and accessible math in all browsers
http://www.mathjax.org/
Apache License 2.0
10.12k stars 1.16k forks source link

[STIX-web] bold-italic glyphs no longer found (in 2.7.5) #2035

Closed pkra closed 4 years ago

pkra commented 6 years ago

E.g., <math><mi mathvariant="bold-italic">x</mi></math> fails to locate a glyph in the STIX-web fonts (in both SVG and HTML-CSS).

Possibly a regression after #1923 (since 2.7.4 uses STIXWEBMAINBI).

dpvc commented 6 years ago

Argh! I used the wrong offset for the bold-italic letters. You can fix this using

MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready", function () {
  var HTMLCSS = MathJax.OutputJax["HTML-CSS"];
  HTMLCSS.Augment({FONTDATA: {VARIANT: {'bold-italic': {offsetA: 0x1D468}}}});
});
MathJax.Hub.Register.StartupHook("SVG Jax Ready", function () {
  var SVG = MathJax.OutputJax.SVG;
  SVG.Augment({FONTDATA: {VARIANT: {'bold-italic': {offsetA: 0x1D468}}}});
});

which will set up the correct values. You should be able to put these into a local extension that you load into mathjax-node via the --extensions option until the data is fixed officially.

pkra commented 6 years ago

Thanks, Davide!

pkra commented 5 years ago

@dpvc I recently ran into the same problem with bold italic greek characters reported as unknown characters. I believe STIX 1 has those as well. If you could share a similar patch, that'd be great.

dpvc commented 5 years ago

@pkra, I'm not able to reproduce that. With

#! /usr/bin/env node

var mjAPI = require("./lib/main.js");

mjAPI.config({MathJax: {SVG: {font: "STIX-Web"}}});

mjAPI.typeset({
  math: '<math><mtext mathvariant="bold-italic">&#x393;&#x3B3;</mtext></math>',
  format: "MathML",
  svg: true,
  ex: 6, width: 100,
}, function (data) {
  if (!data.errors) {
    console.log(data.svg);
  }
});

I get the output of

<svg xmlns:xlink="http://www.w3.org/1999/xlink" width="2.461ex" height="2.509ex" style="vertical-align: -0.671ex; margin-left: -0.029ex; margin-right: -0.053ex;" viewBox="-12.5 -791.3 1059.5 1080.4" role="img" focusable="false" xmlns="http://www.w3.org/2000/svg" aria-labelledby="MathJax-SVG-1-Title">
<title id="MathJax-SVG-1-Title">Equation</title>
<defs aria-hidden="true">
<path stroke-width="1" id="E1-STIXWEBMAINBI-393" d="M670 669l-43 -190l-27 5c0 51 -4 80 -20 100c-32 40 -83 53 -167 53c-41 0 -53 -10 -63 -48l-125 -457c-8 -30 -15 -50 -15 -63c0 -31 15 -40 71 -44v-25h-294v25c58 6 67 24 82 79l121 442c6 23 10 46 10 61c0 20 -11 29 -42 33l-31 4v25h543Z"></path>
<path stroke-width="1" id="E1-STIXWEBMAINBI-3B3" d="M461 449l-263 -411c0 -77 -18 -242 -112 -242c-44 0 -52 41 -52 63c0 60 63 141 118 229c10 73 12 86 12 141c0 68 -17 136 -66 136c-18 0 -52 -4 -68 -68h-27c16 88 64 165 125 165c71 0 78 -65 78 -135c0 -33 -2 -102 -5 -135l136 257h124Z"></path>
</defs>
<g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)" aria-hidden="true">
 <use xlink:href="#E1-STIXWEBMAINBI-393"></use>
 <use xlink:href="#E1-STIXWEBMAINBI-3B3" x="585" y="0"></use>
</g>
</svg>

which does have the proper paths for the characters, not unknown characters, which would be in <text> nodes.

I've also checked that the the offsets for the bold-italic Greek letters are correct, and they work properly in a browser as well, both in HTML-CSS and SVG with the STIX-Web font.

Can you give an example that is not working for you?

pkra commented 5 years ago

Thanks for checking, @dvpc. It turns out that we had raw Unicode in TeX, e.g., $𝜶$. Those do trigger the problem for me but I'm not sure if that's a relevant use case. In any case, I think I can fix that on our end.

dpvc commented 5 years ago

Ok, thanks for the additional information, @pkra. This turns out to be another instance of the bad font data for the STIX-Web font. The characters in the Math Alphabets unicode block are broken into separate files, and the bold italic Greek are in the STIXMathJax_Normal-BoldItalic font, but that font is only searched as part of the bold-italic mathvariant, and not as part of the normal variant, which is where a raw 𝜶 will be specified (it will produce <mo>𝜶</mo>, which has mathvariant="normal" by default). All the Math Alphabet characters should be part of the normal variant (and every other variant, for that matter), but they aren't in STIX-Web.

The list of fonts to use for each of the variants is incomplete in STIX-Web (and the other web fonts). For example, the fraktur variant only searches the Fraktur font, so if any non-fraktur characters are use in that variant, they will end up being unknown, even if they are available in the normal variant. The font lists for the MathJax TeX (and HTML-CSS local STIX) fonts were carefully arranged to make the variants work even when characters that aren't the natural ones for those variants are used. Unfortunately, that is not the case for the other web fonts.

pkra commented 5 years ago

Thanks for the additional information, Davide.

dac514 commented 5 years ago

Hi. I'm having this problem too!

Can someone give me more info about https://github.com/mathjax/MathJax/issues/2035#issuecomment-407879570 please?

If I copy paste the startup hooks into:

https://github.com/mathjax/MathJax-node/blob/c7e5bf3baf4af820e68be58cb93ade38b8e19cbe/lib/main.js#L224

It works.

If I try to write my own extensions and load it from a directory in my own node app, MathJax fails to load. I looked at tutorials, code example, and I don't get it yet...

As an aside. I also tried https://github.com/mathjax/MathJax/pull/2038 That fixes the issue. I'm already using a dev branch for a previous issue and i'm reluctant to keep pointing at things that are not released / forking. Is there an ETA for the linked, PR opened last year?

Edit / PS: PS: Here's a test case:

\boldsymbol{\Delta{p}_1=F_1\Delta{t},}
pkra commented 5 years ago

If I try to write my own extensions and load it from a directory in my own node app, MathJax fails to load.

Without having the code, it's hard to help.

The following is roughly what should happen:

MathJax.Extension['mypatch'] = {
  version: '1.0.0'
};

MathJax.Hub.Register.StartupHook("SVG Jax Ready", function () {
  var SVG = MathJax.OutputJax.SVG;
  SVG.Augment({FONTDATA: {VARIANT: {'bold-italic': {offsetA: 0x1D468}}}});
});

MathJax.Callback.Queue(['loadComplete', MathJax.Ajax, '[mypatch]/mypatch.js']);

Its filename must match the loadcomplete, i.e., mypatch.js.

Then in mathjax-node's configuration, e.g.,

mathjax.config({
  paths: {
    'mypatch': path.dirname(require.resolve('mypatch')) // if the patch is installed via npm but you get the idea
  },
  extensions: '[mypatch]/mypatch'
...
}
dpvc commented 4 years ago

In testsuite:

MathMLToDisplay/Characters/issue2035.html