Open youngplayer2017 opened 1 year ago
If you do
npm list mathjax
you should get the version of MathJax that you have installed. Because the package.json
file has the version set at ^2.7.2
, you should get the latest 2.7.x version, which is 2.7.9, automatically. If you don't have that version, then
npm install mathjax@2.7.9
should update the version that you have. If you want to force it to 2.7.5, then use
npm install mathjax@2.7.5
MathJax does not have a message "missing open brace on subscript", but there are messages that say "Extra close brace or missing open brace", so perhaps that is what you are getting. That indicates a misbalanced brace, so there may be something wrong with the bracing in your expression. If that changes from one version to another, it may be because you haven't braced an argument to a macro properly. If you post the expression that is giving you trouble, we may be able to point out what is causing the issue.
Yes,as you said,Mathjax-node parser worked well without error. It happened on rendering the svg labels to the web,even through postman.
Let me show an example:
\\(∠AOB=50^{\circ}\\),\\(∠AOC=\\) ______ .
as shown, underline in the end is a blank position to fill by the answer student.
it would occurs "Undefined control sequence \\(
",but I've set \\(
as inlineMath(shown in the following picture, but doesn't work at all.
and then I remove '\(':
∠AOB=50^{\circ},∠AOC= ______ .
it would occr "Missing open brace for subscript" which cased by the underline in the end.
Thank you for your help.
The mathjax-node typeset()
command takes a TeX string as its input, not arbitrary text containing math delimiters an other text. So when you do something like
mathjax.typeset({
math: "\\(∠AOB=50^{\circ}\\),\\(∠AOC=\\) ______ .",
... (other parameters) ...
});
MathJax is treating the math string as TeX code to be processed. Note that for javascript strings, the backslash, \
is an escape character that can be used to produce things like newlines (\n
), tabs (\t
), and other special characters, so in order to have an actual backslash within the string, you use \\
. So when \\(
appears in a javascript string literal, the actual string that is produces only contains \(
. Since MathJax is taking your string as a TeX string (without the need for delimiters), it tries to process \(
as a TeX macro. But since that is not defined, you get the "Undefined control sequence error", which is the correct result.
When you remove the delimiters and try to do
mathjax.typeset({
math: "∠AOB=50^{\circ},∠AOC= ______ .",
... (other parameters) ...
});
The entire string is considered to be TeX code, including the underscores at the end. It is those underscores that are producing the error, as they are being interpreted to mean "produce a subscript", as that is the meaning of underscores in TeX's math mode. The first underscore starts a subscript, and then the second tries to make a second subscript, and that is not allowed (you need to use braces after the first underscore in order to have a second underscore with no preceding base character). So that is the source of the error you are getting, which is the correct result.
Note also that the \circ
will end up being just circ
in the string, as the backslash will be interpreted by javascript as trying to produce a special character, but \c
does not stand for anything special, so you just get c
from it. You would need to use \\circ
in the string literal in order to get \circ
in the resulting internal string.
So there is no problem with the MathJax version or with mathjax-node, it is just that you are not providing the right input for MathJax to process.
On a side note, most of your configuration is unnecessary for mathjax-node. The in-line and display delimiters are never used, since the string you pass mathjax.typeset()
does not use delimiters. Similarly, skipTags
is never used, since mathjax-node is not processing an HTML page. The menu gets turned off automatically, so there is no need for the showMathMenu
setting. The jax are already loaded, so no need to specify those. Finally, mathjax-node uses the CommonHTML output jax, not the HTML-CSS one (as CommonHTML output is browser-independent, while HTML-CSS's is not), so your HTML-CSS
configuration is ignored. That means that there is nothing in your configuration that is useful, so you can remove it entirely.
/
As you said,the underscore is a special charactor to Mathjax. and I'v tried to remove or replace them to its html code _ to avoid such error.
eg.
It does work. but underscores are missing. Could you tell me how to keep them in the result?
It's easy to convert underline(_) to backslash and underline(\_) to avoid parsing error. but, how many characters should be converted before parsing? Is there a list for the special characters?
Are the underscores really supposed to be part of the math expression? Or should that be part of the surrounding HTML? You need to process the math separately from plain text, in general. So I would expect you to process ∠AOB=50^{\circ}
separately, and ∠AOC=
separately, as you originally had them delimited by \(
and \)
, and then insert the results into the larger HTML string.
Alternatively, you could use \text{____________}
or \verb|______________|
.
Is there a list for the special characters?
The main special characters are _
, ^
, {
, }
, \
, %
, #
, &
, and ~
. Depending on what packages are loaded, some others may have special meaning, but most will produce something reasonable, whereas these 9 are used by TeX fin ways that don't produce those characters in the output. There are back-slashed versions of all of them except for ^
, \
, and ~
that produce the given character in the output.
I use Mathjax-node release version to parse to svg, and when displaying svg on web, “missing open brace on subscript” error occurs. But when I use Mathjax 2.7.5 to parse and display the same source senetences, there is no such error.
So,which version of Mathjax in Mathjax -node? How can I change version Mathjax in Mathjax-node to 2.7.5?