I'm trying to follow the examples documented at https://docs.moodle.org/27/en/Chemistry_notation_using_mhchem#via_MathJax for enabling the mhchem extension. I've created a custom configuration at admin/config/content/mathjax which looks like this:
{
TeX: {
extensions: ["mhchem.js","color.js","AMSmath.js","AMSsymbols.js","noErrors.js","noUndefined.js"]
},
"tex2jax":{
"inlineMath":[
["$","$"],
["\\(","\\)"],
["\[\ce{","}\]"],
["$$\ce{","}$$"],
["\(\ce{","}\)"]
],
"processEscapes":"true"
},
"showProcessingMessages":"true",
"messageStyle":"none"
}
This isn't working, so two questions:
- Does this module support extensions?
- Any advice for getting mhchem working properly?
Comments
Comment #2
cilefen commentedNote, the default CDN URL is https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTM.... You may need to adjust that for this extension as per http://docs.mathjax.org/en/latest/start.html. Let us know what you find.
Comment #3
cilefen commentedThere is this message in the docs:
About the common configurations: http://docs.mathjax.org/en/latest/config-files.html#common-configurations
If you don't mind testing this on a plain HTML file you can probably figure out what is needed.
Comment #4
cilefen commentedComment #5
rominronin commentedI'm also trying to enable the mhchem extension, just started out now and found this issue thread.
I need to access the 'extensions' array of the Mathjax configuration. It seems that custom configuration text box in the Drupal configuration page is not the right place for this, since any attempts to add the mhchem extension in this box just leads to Mathjax failing to work.
Any help would be appreciated.
Comment #6
cilefen commentedIf you were to post the things you tried and linked to any reference docs followed that would help.
Comment #7
rominronin commentedFollowing the suggested method for including mhchem here: https://mhchem.github.io/MathJax-mhchem/
and following the instructions from the documentation here: http://docs.mathjax.org/en/latest/configuration.html#using-in-line-confi...
I embedded the following configuration file:
into the header, as a library:
On a page with regular maths expressions and chemical expressions, nothing was rendered (it all rendered as plain text). I tried the same thing with both the default cdn statement and also with just the plain MathJax.js loaded (without config query).
IF I remove the type attribute from the library definition, and also load it at the bottom of the file, THEN math statements are rendered, but chemical equations are not - which contradicts the advice given on the MathJax documentation link above, which recommends to embed the config before the mathjax.js file is loaded.
For absolute clarity, I'm using the following statements to confirm if it has loaded or not:
Maths statement:
$C_nH_m + n H_2O+\rightarrow nCO + (n + m/2)H_2$Chemical statement:
Any ideas what is happening or what I'm doing wrong?
Comment #8
rominronin commentedI think I know why the maths statement was being rendered : When the Custom Configuration box on the module configuration page is deleted and saved, the default entry is reloaded.
Comment #9
rominronin commentedOK, I just renamed my config file to config.js, in case that was causing conflicts.
I just pasted the default module configuration code into my custom config js
{"tex2jax":{"inlineMath":[["$","$"],["\\(","\\)"]],"processEscapes":"true"},"showProcessingMessages":"false","messageStyle":"none"}Again, this gives nothing.
The Page Source confirms that this is being loaded in the header, on line 101, and that mathjax.js is being loaded afterwards on line 1851. What's INTERESTING is that on line 1850, the config file from the module is being loaded:
Is this overriding any other configuration that I'm setting?
Comment #10
cilefen commentedJust guessing on a mobile here (take with appropriate grain of salt in that context) but instead of setting MathJax.Ajax.config.path perhaps you should change the URL in the module settings.
Other things to try:
Check the browser console for errors.
Try a proof of concept in a plain HTML page.
Ping me next week in Drupal’s #general Slack channel. I am in the New York City time zone.
Comment #11
rominronin commentedThe module appears to behave as expected, that is to say that any URL placed in the 'MathJax CDN URL' field will be loaded. However, if I replace the default URL for the mathjax cdn with the URL of the mhchem cdn, then the MathJax library itself will not be loaded (since there is only a single URL field for a CDN, this makes sense).
I tried this and it was confirmed (view the page source to see what libraries are loaded and in what order).
Normally, to load MathJax AND other extensions, you can enter a URL that contains a combined configuration into the CDN field. However, as pointed out in #3, there IS no combined configuration of MathJax and mhchem.
The browser console gives no error.
I'll give this a go next...
Sure thing, thanks for the support so far!
Comment #12
cilefen commentedComment #13
shuklasp commentedI want to integrate mhchem on my site. Please guide me how to do that. I am using drupal 9 on my site http://www.vshiksha.com
Comment #14
cilefen commentedComment #15
shuklasp commentedAny luck?
Comment #16
cilefen commentedComment #17
cilefen commentedComment #18
fishfree commented+1 pls.