mhchem / mathjax-mhchem Goto Github PK
View Code? Open in Web Editor NEW3rd-party extension to MathJax for typesetting chemical equations
License: Apache License 2.0
3rd-party extension to MathJax for typesetting chemical equations
License: Apache License 2.0
It would be great to use benzene ring in chemical formulas.
For info: Benzene ring is available in unicode as
In manual, KaTeX scripts URL is:
https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/mhchem.min.js
But it throws me a 404.
Please change it to
https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/mhchem.min.js
In MathJax equations can be made to use the sans serif-font by encapsuling the math withing a {\sf [math]}
, it'd be great if something like that could be done with mathjax-mhchem as well, perhaps if something like the mhchem \mhchemoptions{font=sf}
was possible.
I've made a very ugly 'permanent' implementation of this in my fork swantzter/MathJax-mhchem@845ee5e
https://github.com/mhchem/MathJax-mhchem/blob/master/unpacked/mhchem.js#L200
if (Array.isArray(b)) ...
Array.isArray
was added in ES5 and some of the oldest browsers won't support it (See the compatibility table). This might be important as one of MathJax's features is legacy browser support. Polyfill it and all goes well. (Tested on IE8)
See also mathjax/MathJax#2110
Hi, we received an error t.slice is not a function
in our sentry server. Sorry, I didn't find the TeX script to trigger this issue.
But I guess it happens in
MhchemMethods.Machine = function(parser: TexParser, name: string, machine: string) {
try {
let arg = parser.GetArgument(name);
let data = mhchemParser.go(arg, machine);
// TODO: Harvest chemical information here from data, test looping through
// the array.
let tex = texify.go(data);
parser.string = tex + parser.string.substr(parser.i);
parser.i = 0;
} catch (err) {
throw new TexError(err[0], err[1], err.slice(2));
}
};
where err
is not an Array
in some cases (maybe Error
thrown in some of the logic inside)
The README seems to suggest that the formatting for dissociation constants pKa and pKb have been corrected. They have not.
The K
needs to be italicized, while the p
and a / b
stay upright. a / b
need to be subscripts.
mhchem now does not seem to work on mathjax3
See https://jsbin.com/cadobasoho/edit?html,js,console,output
Example HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>MathJax + mhchem example</title>
<script>
window.MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']],
packages: {'[+]': ['mhchem']}
},
loader: {load: ['[tex]/mhchem', 'ui/safe']},
};
</script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg-full.js"></script>
</head>
<body>
$\ce{<=>}$
</body>
</html>
In the rendered result, the upper arrow is shorter than the bottom arrow.
But if I remove "ui/safe", it looks fine.
What are the actual dependencies for MathJax-mhchem from MathJax library? I am using minified version of MathJax from here. Its working fine but not with this extension. I want to use this for mobile app development so MathJax is a huge library to work with therefore I am using minified version.
Once mathjax/MathJax-node#391 lands, it would be great to be able to pull in mhchem from npm.
MathJax output from mhchem builds up several arrows because there is no Unicode equivalent. This leads to poor speech without extra effort. E.g., for <=>
, SRE generates
left harpoon with barb down minus under minus right harpoon with barb up
as opposed to "in equilibrium with". I suspect an actual font character would produce a superior visual rendering also, but that of course depends on the font implementation.
I saw missing characters for <=>
, <<=>
, and <=>>
and asked some people on the Unicode Technical committee whether I missed spotting those characters given how many arrow chars they already have. The answer was that they are missing and encouraged me to submit a proposal to include any missing characters. Specifically one person said
...good idea looking for "macros" that build up symbols. If such use is widespread, with reasonably established usage, character encoding would seem appropriate.
@mhchem or @dpvc: if you can you list come up with a list of those chars, I'll work on getting a proposal together for them. If there are only three, it was suggested that they fill in the three remaining empty slots in "2B00 Miscellaneous Symbols and Arrows block".
Hi all!
I having some troubles with the mhchem arrows.
If I write some code like:
\ce{<=>[{some text}][{Some text}]}
--> Mathjax bring me a little arrow not adjusted with the text.
With other arrows:
\ce{<=>>[{some text}][{Some text}]}
\ce{<<=>[{some text}][{Some text}]}
Both of them bring me the same arrow like the example below (\ce{<=>}) instead of the correct arrow.
I write this using the documentation available at ftp://www.ctan.org/tex-archive/macros/latex/contrib/mhchem/mhchem.pdf
Hello,
Describe the bug:
<mphantom>
in chemical notation (\ce{}
) are being read out as "X" in JAWS screen reader.To Reproduce:
\ce{SO4}
Expected behavior:
Read out as "S O sub 4"
Environment:
Thanks for your time.
The mchem packages produces very ugly MathML when there is a much better (and better for assistive technology) solution. Solving this would solve #22. Technically, this is not a bug report, but the upshot is that with the current output, recognition and proper voicing of the chemistry output is extremely difficult.
At the end of this issue is a relatively simple example that generates poor MathML output. It has (at least) four problems:
mrow
s,mi
mphantom
and mpadded
are needlessly usedLet me go through these one by one...
The first one (extra mrow
s) is pretty obvious. In the output below, there is:
<mrow data-mjx-texclass="ORD">
<mi data-mjx-auto-op="false">SO</mi>
</mrow>
There is no need for the mrow
.
The second is also pretty obvious -- "SO" is in a single mi
. That's a misuse of mi
and is equivalent to putting x
and y
into a single mi
and then making that italic (via mathvariant="italic"
) so that it looks ok. Given this is a chemistry package, is it hard to recognize an element and put it in its own mi
? If it is a single letter, then the default italics are overridden with mathvariant
as in
<mi mathvariant="normal">S</mi>
It is valid to add mathvariant="normal"
to <mi>Na</mi>
if that makes generation simpler (i.e., you can always add it to any chemical element).
The third problem's solution is maybe less obvious. mphantom
and mpadded
are being used to force the scripts to all have the same vertical position. But MathML has a much simpler solution for this usage: mmultiscripts
. From the MathML spec:
This element allows the representation of any number of vertically-aligned pairs of subscripts and superscripts, attached to one base expression. It supports both postscripts and prescripts. Missing scripts must be represented by the empty element none. All of the upper scripts should be baseline-aligned and all the lower scripts should be baseline-aligned.
Since all chemical elements have a capital letter, all scripts will be horizontally aligned.
An example of the better output, which also attaches the scripts to the element (and therefore solves the last problem) is:
<math>
<mi>S</mi>
<mmultiscripts>
<mi>O</mi>
<mn>4</mn>
<mrow>
<mn>2</mn>
<mo>−</mo>
</mrow>
</mmultiscripts>
</math>
I've removed the MathJaX generated attributes for clarity. Compare this to the mchem/MathJax output below.
This is also a better solution for the prescripts used in nuclear chemistry.
There is a problem for electron, proton, etc., and scripts because the base doesn't have a capital letter.
The mphantom
/mpadded
trick could be used here (inside an mrow
around the base element), but is not ideal.
This leads to an alternative to mmultiscripts
: use msub
/msup
/msubsup
with the attributes subscriptshift
and superscriptshift
. There are two problems with this approach:
Finally, here is the example: \ce{SO4^2−}
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mstyle mathcolor="#a33e00">
<mrow data-mjx-texclass="ORD">
<mrow data-mjx-texclass="ORD">
<mi data-mjx-auto-op="false">SO</mi>
</mrow>
<msub>
<mrow data-mjx-texclass="ORD">
<mrow data-mjx-texclass="ORD">
<mpadded width="0">
<mphantom>
<mi>A</mi>
</mphantom>
</mpadded>
</mrow>
</mrow>
<mrow data-mjx-texclass="ORD">
<mrow data-mjx-texclass="ORD">
<mpadded height="0">
<mn>4</mn>
</mpadded>
</mrow>
</mrow>
</msub>
<msup>
<mrow data-mjx-texclass="ORD">
<mrow data-mjx-texclass="ORD">
<mpadded width="0">
<mphantom>
<mi>A</mi>
</mphantom>
</mpadded>
</mrow>
</mrow>
<mrow data-mjx-texclass="ORD">
<mn>2</mn>
<mo>−</mo>
</mrow>
</msup>
</mrow>
</mstyle>
</math>
How would I get this to work with Ankidroid?
It would be nice to have a shorthand for using the degree symbol, in particular one that "overlaps" with subscripts. AFAIK, the right way to do this is like:
\ce{\Delta S\rlap\degree_{rxn}}
:
I guess *
is already used, but maybe something like S^*
does not conflict with any commonly used notation?
Currently the engine interprets the state of aggregation indicated with a v as a downward arrow for precipitation, i.e. \ce{H2O (v)}
= H2O ↓, it should be H2O(v) instead. I think in general the usage of 'v' is not standard, it should be 'g' instead, it might be good to support states of aggregation as a special rule, given that they are set in parenthesis. See the Green Book (pdf) p. 54.
Mathjax has an option to introduce to it our own number patterns through regex. Here, @dpvc kindly modified some codes from mhchem for it to adapt with another number pattern /^(?:[\d۰-۹]+(?:[,٬'][\d۰-۹]{3})*(?:[\.\/٫][\d۰-۹]*)?|[\.\/٫][\d۰-۹]+)/
. In response to my request here regarding publishing the modifications to find their way up to the mainstream version of mhchem, @dpvc directed me to open an issue here and ask if it is possible to make number patterns configurable in mhchem, as is configurable in the TeX input jax?
thanks
Currently, the thousands separator added by \pu
is 2 mu = 1/9 em wide, and looks like this:
I think that's too narrow: I can't pick the thousands apart at a glance. It's even worse in smaller sizes - even looking quite closely, I was barely able to tell where the spaces between groups were and what was just a wide-looking kerning pair.
The Unicode character usually used for this is either U+2009 THIN SPACE or U+202F NARROW NO-BREAK SPACE, but that's not applicable to mhchem (it doesn't insert a character, but instead formats with spaces). Those glyphs are typically 1/5 to 1/6 em wide, which is significantly wider. Here's a mock-up of what 3 mu = 1/6 em looks like:
For me, that's much better!
It would be great to have the cancel extension somehow supported. Here is a real world example on chemistry.se: Why did they ‘split’ this H2+ ion in the ionic equation?
The current work-around for me was to nest the commands:
\ce{Mg(s) + H2+(aq) + \cancel{\ce{SO4^{2-} (aq)}}
&-> Mg^{2+}(aq) + \cancel{\ce{SO4^{2-} (aq)}} + H2(g)}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.