MathJax icon indicating copy to clipboard operation
MathJax copied to clipboard

sre_browser.js is referencing jsdelivr which showing error when deploying in isolated environment

Open randomseed42 opened this issue 3 years ago • 9 comments

https://github.com/mathjax/MathJax/blob/be11806df1ae075508e33500c990497062ef3c5a/es5/sre/sre_browser.js#L98

I'm using npm install mathjax@3 in laptop and copied node_modules folder to isolated server, which failed to load en.js from jsdelivr CDN in chrome, I'm not quite familiar to js but thought may using relative path to resolve it. Thanks!

randomseed42 avatar Apr 26 '21 10:04 randomseed42

You can set the path used for the maps via

<script type="text/x-sre-config">
{
  "json": "path-to-mathmaps",
}
</script>

in your HTML file before loading MathJax itself.

The problem with a relative URL is what is it relative to? Relative URLs are taken relative to the HTML page location, bniut SRE doesn't know where it is located relative to that.

dpvc avatar Apr 26 '21 11:04 dpvc

As of MathJax v3.1.4 you can also set SRE options directly inside the MathJax configuration object, e.g.,

 <script>
  MathJax = {
      options: {
          sre: {
             json: 'http://localhost/node_modules/sre/speech-rule-engine/lib/mathmaps'
          }
      }
  }
</script>

zorkow avatar Apr 26 '21 15:04 zorkow

It would be helpful if one could use the [mathjax] prefix.

pkra avatar Apr 29 '21 19:04 pkra

@pkra, that is a good idea.

dpvc avatar Apr 29 '21 19:04 dpvc

Hello :wave:! Sorry to comment in an older issue, but I am also experiencing issues loading mathmap files from a local source.

We are attempting to load the tex-chtml-full package via the following async import statement: await import('mathjax/es5/tex-chtml-full')

This works fine, and loads all the files we expect it to. We are using something similar to the following config:

  window.MathJax = {
    tex: {
      inlineMath: [[INLINE_DELIMITER, INLINE_DELIMITER]],
      displayMath: [[DISPLAY_DELIMITER, DISPLAY_DELIMITER]]
    },
    chtml: {
      fontURL
    },
    startup: {
      typeset: false
    },
    options: {
      sre: {
        json: '/mathmaps'
      }
    }
  }

This config doesn't seem to have any impact on where the files are loaded from; sre still tries to load files from a CDN. Looking into the actual source code, I don't see anything in the SRE type defs that indicate that json is a valid field. I did a full-text search of the codebase and I didn't see any obvious place where this value was getting supplied to sre.

Any guidance in how to get this working would be much appreciated! Thanks in advance, and thanks for working on such a useful library 😄

el-mapache avatar May 02 '22 17:05 el-mapache

@el-mapache, the options are passed to SRE via

https://github.com/mathjax/MathJax-src/blob/2dd53ce6c8af3c9cceba0baf014ea9b065130774/ts/a11y/semantic-enrich.ts#L135

as a block, so you won't find the 'json' in the MathJax source specifically.

It looks like this worked in #2686, but the difference there is that the locale was set to 'es', and that meant that SRE had to load the mathmaps for a new language, and since the json path was also set in the same update, the maps were taken from the correct location.

In your case, since the locale is still en, and since that locale is loaded by default when SRE is loaded, the change of the json path comes too late, as the maps have already been loaded for en by the time that is set.

@zorkow, do you see a way around this in SRE pre-4.0?

The <script type="text/x-sre-config"> approach should work, as long as it is in place before SRE is loaded. Perhaps you could have your code create the needed script tag an insert it before you import MathJax?

There is a 3.2.1 update that is imminent that includes SRE v4, which now has a promise-based interface, and much better path handling. That should be out very soon (next week?), so perhaps that will resolve the issue.

dpvc avatar May 04 '22 14:05 dpvc

@dpvc Thanks for the reply! We're using the script tag config currently, although it's not ideal it does unblock us. Very interesting to hear that this is an issue with the way SRE is loading.

We'll be on the lookout for version 3.2.1!

el-mapache avatar May 04 '22 15:05 el-mapache

json is indeed one of the options that can be passed to SRE and since v3.2 this is no longer checked explicitly in MathJax. Effectively all of SRE's options can now be pushed through. For the list of options see here: https://github.com/Speech-Rule-Engine/speech-rule-engine#options-for-internal-control-of-the-engine (Note that some of these options, inparticular, delay and defaultLocale do not yet exist in the SRE versions <4.0.X that is included in MathJax. See the SRE release notes for details.)

The <script type="text/x-sre-config"> configuration should work, as it is picked up by SRE before it tries to set itself up. Alternatively, you could host your own version of SRE (<4.0) and set the sre paths option in the loader block of the MathJax configuration (https://docs.mathjax.org/en/latest/options/startup/loader.html?highlight=paths#the-configuration-block)

zorkow avatar May 04 '22 15:05 zorkow

@dpvc Thanks for the reply! We're using the script tag config currently, although it's not ideal it does unblock us. Very interesting to hear that this is an issue with the way SRE is loading.

Yes, the issue is that SRE tries to setup itself up as much as possible, so there will be at least one locale available to generate speech, without having to explicitly setting up the engine, with a call to setupEngine. But this can lead to timing issues, in particular since before v4 SRE did not use promises. The new version should iron out those kinks.

zorkow avatar May 04 '22 15:05 zorkow