mathjax / MathJax-node

MathJax for Node
Apache License 2.0
614 stars 96 forks source link

Display ∑ issue #406

Closed xuanliao closed 6 years ago

xuanliao commented 6 years ago

I add ∑ in editor like picture 1. image

But display error symbol, like picture 2. error image

Questions: Why does it display error symbol? How can I display correctly?

dpvc commented 6 years ago

There are two styles of typesetting mathematics: text-style math (i.e., math inside a paragraph) and display-style math (math on a separate line between paragraphs). For text-style math, one goal is to disrupt the line spacing as little as possible, so tall vertical constructs are limited, and in particular, things like summations have their limits typeset to the right rather than above and below, as in the picture you provide. This is correct, not an error, for text-style math; the limits being above and below is only used in display-style math. Note also that even in a displayed equation, typesetting rules will switch to text-style rules in some situations. For example, the numerator and denominator of a fraction are typeset in text style, so summations inside fractions will have limits set to the right even in a displayed equation.

If you are using TeX as your input format, you can override the style using the \textstyle and \displaystyle macros. So using something like {\displaystyle \sum_{n-2}^\infty} would produce the summation with limits above and below even in a fraction or in math within a paragraph.

pkra commented 6 years ago

If you are using TeX as your input format, you can override the style using the \textstyle and \displaystyle macros. So using something like {\displaystyle \sum_{n-2}^\infty} would produce the summation with limits above and below even in a fraction or in math within a paragraph.

The format options (TeX vs inline-TeX) are another way to do this.

xuanliao commented 6 years ago

It's well done using Tex. But I'm using MathML. The code under <math xmlns="http://www.w3.org/1998/Math/MathML"><munderover><mo>&#x2211;</mo><mn>4</mn><mn>2</mn></munderover><mi>X</mi></math>

It should be right, but It display actually.

pkra commented 6 years ago

I'm afraid that's the expected rendering for your input.

You'll need to change to, e.g., <math display="block" ... if you want to have the movable limits as under/over scripts. Check the MathML spec regarding munderover and the operator dictionary if you want to understand why this is happening (and perhaps file a bug with the editing tool if it spits out unintended MathML).

dpvc commented 6 years ago

As Peter points out, the rendering in MathJax is correct for the MathML that you provided, since it is in-line math rather than display-style math. Peter provides one solution, which is to make the math into a display-style (block) math element. If you want to keep the math as an in-line expression (i.e., it is part of a sentence in a paragraph), then you can use <math displaystyle="true"> instead of <math display="block">. Note, however, that this will affect other layout, like fractions, and will use a larger size for summation signs and integrals. If you want to keep the same size summation but use limits that are above and below rather than to the right, you can use <math movablelimits="false"> so that limits will always be above and below.

I note that your "correct" image has 2 on the bottom and 4 on the top, but the MathML you provide would have 4 on the bottom and 2 on the top (as it is in the MathJax output). If that is the problem you are concerned about rather than the placement of the limits to the right, then that is because the MathML has the limits in the wrong order. If your editor has produced it that way (and it's not just a typo on your part), then that is a bug in the editor.

dpvc commented 6 years ago

Just to be clear: this is not an error in MathJax. The output is correct for the MathML that you provided. In order to get the layout you want, you need to change the MathML. If your editor is showing the math with limits above and below, it is displaying the MathML incorrectly.

xuanliao commented 6 years ago

Thanks. It's well done with code <math display="block" ...