-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The configuration format for MathJax v3 is changed #8195
Comments
Sphinx 4 is coming out in a bit more than a month, are there any news on this issue? For starters, this should get the proper milestone assigned so that it isn't overlooked when the time comes ... |
Thank you for the reminder. I perfectly missed this. And I still don't understand what we should do. Can anybody send a pull request for this issue? |
I'm happy to try a fix. Is there interest in supporting both MathJax 2 and 3? Or can a fix be specific for MathJax 3? |
Is the default mathjax version going to change in Sphinx? Can the configuration be changed in a backwards compatible way, so that existing configuration will continue to work with mathjax 3 when upgrading? |
@asmeurer Yes, the default version is currently set to change (see #7961). It seems as though the configuration changes are non-trivial between v2 and v3 of MathJax, and trying to write a backwards compatible configuration format will be tricky. That's why I asked if there was interest in trying to support both. I think the easier way to retain "backwards compatibility" is for end-users who don't want to update to MathJax v3 to change their That's a good point though, that configuration for MathJax 3 could probably happen with a different variable name (the current is |
What about using
|
I don't know how many users want to keep using old versions. But it would be better if we can support both for a while. What's the difference in configurations between v2 and v3? If they are almost the same or very similar, it might be better to set up them via |
One way maintain backwards compatibility would be to maintain |
Version 3 is a complete rewrite. See https://docs.mathjax.org/en/latest/upgrading/whats-new-3.0.html. In particular, it completely changes the API for configuration, so it is not backwards compatible. Also, from https://docs.mathjax.org/en/latest/upgrading/v2.html#v2-configuration-changes:
So it makes sense to continue to support both versions for the time being. There will probably be some users who cannot easily upgrade to version 3. |
As @asmeurer mentions, the configuration format is completely different. I also posted an example of the new configuration in the OP of this thread. So direct translation of v2 to v3 configuration is non-trivial, unfortunately. I like the suggestion from @asmeurer to use MathJax v2 if MathJax v3 will then be configured by One slight modification of that approach would be to introduce a |
I like that my approach requires no changes to the config to continue working. Although if we can reliably detect the difference automatically that also sounds like it could be a good idea. Another thing that should be fixed is the link to the MathJax docs at https://www.sphinx-doc.org/en/master/usage/extensions/math.html#confval-mathjax_config (unfortunately, MathJax 404ed all old docs links at some point). |
@tk0miya I think the problem with What if they disagree?
This has the advantage that it will not be disruptive, but I fear that it might slow down adoption of MathJax 3. I think it would be better to to raise a warning (or even an error?) if |
Agreed. But, we need to configure both URL and configuration method ( And I suppose who want to control the version of mathjax via
What do you mean? I think About Personally, I prefer not to use a version number to the configuration name. It means we'll have to introduce |
I think @mgeier means what if the version set in
How would you feel about introducing a |
I don't think to deprecate Any contradiction will happen even if we don't introduce
Acceptable. Note: minor concerns:
|
The v3 configuration will be inserted into the HTML, and it will of course not work, as expected. If a user is already (pre-Sphinx-4) using If a user is using I think a
I expect it will take many years until MathJax 4 comes out. And if it doesn't change, there isn't really a problem with adding
This would break all instances that are currently using We haven't really talked about what should happen when both I think for a normal user that's fine, but how would a Sphinx extension be able to change the default MathJax settings for both versions? For example, I'm changing the default MathJax settings in my How can I do this without always inserting two configs into the HTML file? |
@mgeier This is predicated on being able to detect differences between a dictionary meant to configure v2 and one meant to configure v3. In the former case, a warning would be issued and users should change the variable name to
Why do you need to set config for both versions? IMO, you can upgrade nbsphinx to support v3 and put a note in your docs that if you want to keep using v2 you have to do X, Y, Z configuration in your (Off topic, thank you for developing nbsphinx, I've used it in several projects and it has always worked wonderfully!) |
According to the MathJax documentation, versions 2.3 and higher support assigning the configuration mapping to the window.MathJax object. See: https://docs.mathjax.org/en/v2.7-latest/configuration.html#using-plain-javascript and http://docs.mathjax.org/en/latest/web/configuration.html#configuration-using-an-in-line-script This commit changes to use the window.MathJax method. Users who prefer to use v2 will have to set the mathjax_path variable, but their configuration should continue to work. Fixes some outdated links to MathJax documentation. Closes sphinx-doc#8195
As it happens, there actually is a common way to configure both versions, at least in terms of the JavaScript assignment. So I don't think it's necessary to introduce two variables. The specific option names are different and can't really be converted (or at least, I don't want to try to do that), but it's easy enough to warn when something looks like v2. I made a PR this afternoon! #8971 |
To avoid breakage. Most If If
Even when assuming that the releases are perfectly timed (see above), this would still be very annoying for people who have selected MathJax v2 with Because those won't get any warning, but their equations will be broken (if they use single
Thanks, that's nice to hear! I've looked at #8971 and I didn't know that the |
PS: in case you want to try it out, I've just created an experimental PR for |
@mgeier I was thinking about adding a configuration option for "don't warn me, I really know what I'm doing," but I couldn't come up with a good name. But adding the logic for that would be trivial, just an extra condition on the |
There is no need for a custom option for suppressing warnings, because Sphinx already has suppress_warnings. If you add a warning type and subtype to your warning, it can be silenced without silencing all other warnings. However, silencing this warning isn't really a solution for my use case. |
@mgeier I'm not sure how this could work using the |
I guess it wouldn't work.
This sounds very much like a hack. I hope there is a better way. What about using This would be very simple, easy to use and no heuristics are needed to automatically detect the desired MathJax version. And let me quote the Zen of Python:
|
It doesn't to me... it sounds like a user is configuring their Sphinx build. In that sense, what you're already doing with
My personal preference is really to avoid version-specific configuration variables, especially ones that will be removed at some point in the future. It seems that @tk0miya also agrees with this perspective. If you feel very strongly that separate configuration variables are necessary, feel free to create your own pull request and the maintainers of the package can decide which they like. FWIW, I also don't put very much stock in appeals to arbitrary authority which support one's viewpoint. If that is your viewpoint, then just flat out state it, it's fine we can have different opinions. The Zen of Python is ambiguous enough to be interpreted to support any viewpoint, e.g.,
One configuration variable is less complex and less complicated than two/three for a user.
One configuration variable is more obvious for a user than two/three. |
Hi all. I'm catching up on this thread, and only skimmed things so I apologize if I am saying something that was already said.
I don't think this is a huge issue. The documentation can show how to configure MathJax 3, so that it becomes the default for new projects. I forget if there's a commented out section in conf.py, but if there is, that can be updated too. Given that MathJax 2 is itself not yet deprecated (#8195 (comment)), I am -1 to warning or erroring if it is being used. I expect there are some corner cases of things that don't yet work in MathJax 3 that may prevent some projects from updating. Regarding mathjax_path, It is not the same as mathjax_version. It can be used to set a custom path to the MathJax Javascript. For example, you may want to host the Javascript yourself to avoid hitting the CDN. As far as I understand mathjax_path is the only way to do that. If you want to add a mathjax_version as well to simplify the common configuration, I would suggest making it an error to specify both. As I said before, please make it so existing projects do not break. This means the MathJax version should not change out from under a project so that its mathjax_config stops being valid. This would be especially bad if it didn't result in any warnings from Sphinx, only math that doesn't render like it used to. That sort of thing happened to me once and I went weeks before noticing that none of my math was actually rendering on the page (this can easily happen, e.g., if you reconfigure the default math delimiters). If it's possible to automatically make the same config work with both versions, and a specific mathjax version isn't specified, I think it would be acceptable to automatically push a project to MathJax 3. It's not clear to me exactly, can one version's config be automatically translated to the other's or are they too different? |
At least in my PR (#8971), a warning is only issued when MathJax v3 at the default URL is being used with something that looks like a v2 configuration dictionary. This seems appropriate, and will prompt people to either change the
The config is quite different between the versions. MathJax provides a page that will do the conversion if you copy in your JavaScript code, so I don't think it's something that Sphinx should try to do automatically. However, it is possible to set a single variable that will configure v2 and v3. In v2.3 and up it's possible to shove the configuration mapping into a JavaScript object (I'm not sure of the correct name for that) called As it stands, since #7961 has already been merged, v3 will become the default version for all projects that haven't set a |
This sounds reasonable to me. |
You were talking about defining a "magic" dictionary key that causes a special behavior, while all others are systematically added to a JavaScript object. That simply sounds like a hack, and not like what a user would normally want to do.
Oh yes, very much so! If you know a better (less hacky) way to implement this, please let me know!
Well you shouldn't take hacks in other projects (e.g. And a hack in the implementation is much less bad than a hack that's exposed to the API surface (in form of a configuration value).
Exactly.
I agree. But it still might be the least bad option ...
I think collaboration would be better than competition in this case. And I don't feel strongly that separate configuration variables are necessary. I simply don't know yet. I don't have the feeling that they should be ruled out at this point. I have the feeling that there might be a better solution that hasn't been proposed yet. The problem for my use case is that (AFAICT) just having separate configuration values doesn't solve my problem either.
I'm not using the Zen of Python as an authority, and I don't think it has been created with that intention. I'm using it to provide food for discussions, and I think it's great for that.
I don't have a fully formed opinion yet. My viewpoint is that there hasn't been a proposal that's clearly better than two separate configuration values for MathJax version 2 and 3. I'm not saying the best solution will necessarily have those two configuration values, I'm just saying it would be good to stay open-minded and consider all suggestions that have been made in this discussion here.
Yes, that's why it is so great!
One configuration variable that's used for different things in different circumstances is in fact more complex than two separate configuration variables that each do their own thing.
According to this, there should be one obvious way to configure MathJax v2 and one obvious way to configure MathJax v3. I don't think this means that there should be one way to do two different things, depending on which Sphinx version is used (or some other non-obvious internal state). |
I just found a way to make #9094 work reasonably well with my I don't think a similar solution would be possible with #8971. |
Now I merged #9094 into the 4.0.x branch. So Sphinx-4.0.0 will support MathJax v3 perfectly. Thank you for your support, @mgeier, and @bryanwweber! |
Describe the bug
Pull request #7961 introduced MathJax v3, to be released in the next major version of Sphinx. However, there is not yet support for the new configuration format for MathJax. In particular, MathJax v3 no longer uses the nested
MathJax.Hub.Config
object, preferring instead to use simplyMathJax
.To Reproduce
Include some
mathjax_config
values inconf.py
and setmathjax_path
to point to MathJax v3 (or use the main branch).Following the conversion guide here: https://mathjax.github.io/MathJax-demos-web/convert-configuration/convert-configuration.html
This generated configuration using Sphinx 3 and MathJax v2:
with this config parameter:
MathJax.js?config=TeX-AMS-MML_HTMLorMML
results in this new MathJax v3 configuration:The last line there is handled by the
mathjax_path
, but the rest of it can't be handled by the currentmathjax_config
option, which assumes thatMathJax.Hub.Config
should be present. See also: https://www.sphinx-doc.org/en/master/usage/extensions/math.html#confval-mathjax_configExpected behavior
MathJax is configured properly.
Environment info
master
by default, but any version ismathjax_path
is set to point to v3.Additional context
The text was updated successfully, but these errors were encountered: