mathjax / MathJax-node

MathJax for Node
Apache License 2.0
616 stars 97 forks source link

Rendering problems of latex $$\cong$$ in SVG #469

Closed lyxabymxlc closed 3 years ago

lyxabymxlc commented 3 years ago

Question: In SVG, the congruent symbol rendered by latex \cong is opposite to the Chinese national standard. \cong after rendering is: . The Chinese national standard is: image

Environment: mathjax-node: 2.1.1 mathjax: 2.7.6 System: Win10 / Centos

Code:

mjAPI.config({
    extensions: 'MathML/content-mathml.js,TeX/mediawiki-texvc.js,[ext]/text-macros.js',
    paths: {
        'ext': path.resolve(__dirname, '../','ext/')
    },
    MathJax: {
        displayAlign: 'left',
        TeX: {
            Macros: {
                degree: '{°}',
            }
        },
        SVG: {
            linebreaks: {
                automatic: true
            }
        }
    }
});
mjAPI.start();
let data = await mjAPI.typeset({
        math: '\cong',
        format: "TeX",
        svg: true,
        speakText: false,
        useFontCache: false
});

Through comparison, it is found that: \cong after rendering is: . Unicode is \u2245. The Chinese national standard is: . Unicode is \u224C. I try to add the following code under mathjax - > tex - > macro: cong: '{≌}' But it's not ideal. Looking at SVG, we find that is rendered into the text tag, as follows:

<svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.417ex" height="3.343ex" style="vertical-align: -1.171ex;"
    viewBox="0 -934.9 610 1439.2" role="img" focusable="false" xmlns="http://www.w3.org/2000/svg">
    <g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">
        <text font-family="monospace" stroke="none" transform="scale(71.759) matrix(1 0 0 -1 0 0)">≌</text>
    </g>
</svg>

This will cause the display effect of the character \u224c to be inconsistent in different fonts. I want to get the display effect of congruent symbols in Chinese national standard. What should I do? image

dpvc commented 3 years ago

The default MathJax fonts don't include the U+224C character, so that is why you get a <text> element for that. You re correct that it will look different in different fonts, and MathJax won't know how much space to leave for it, so that is not optimal.

There are two possible solutions. First, you could switch to the STIX-web font rather than the default MathJax fonts, since they include many more characters, includuing U+224C. Then define cong: '\u224C' (do not use the braces as that will alter the spacing).

Alternatively, if you want to stick with the default MathJax fonts, you could use

cong: '\\stackrel{\\Large\\lower.2em\\backsim}{\\lower.1em=}'

which will use the back-sim character over an equal sign. That will give you a symbol that looks correct, but will not be read correctly by screen readers.

lyxabymxlc commented 3 years ago

@dpvc We have tested the font "STIX-web", the congruent symbol "≌" is normal, but the rendered other letter styles do not meet the requirements. Default Font ( Tex ): image STIX-web Font: image

Using "stackrel" mode, the display is normal in SVG and abnormal in web page. image

Finally, we adopt the "stackrel" approach to solve the SVG problem first. As for the web page, we will not make any changes for the time being. Thank you very much. ^_^

dpvc commented 3 years ago

Note that mathjax-node uses MathJax version 2, while the mathjax.org website uses MathJax version 3. Apparently, there is some inconsistency in the layout of \stackrel between the two versions. I will need to check into that. Since you were using MathJax-node, I gave you a version 2 solution. Are you using version 3 in your website? If so, you could use

\stackrel{\raise.03em{\Large\backsim}}{\smash{\lower.1em=}}

for SVG output. There also seems to be inconsistency between the SVG and CHTML output (in both v2 and v3). If you use CHTML output in v3, you should need to use

\stackrel{\lower.2em{\Large\backsim}}{\smash{\lower.1em=}}

instead.

lyxabymxlc commented 3 years ago

I see. Thank you very much!

dpvc commented 3 years ago

I forgot to mention:

the rendered other letter styles do not meet the requirements.

Not everyone likes the look of the STIX fonts, and they are different from the default MathJax TeX fonts, which are based on the TeX Computer Modern fonts (whereas STIX is supposed to be compatible with the Times font, if I recall correctly). But they do have the advantage of having much greater character coverage, so they help when you want to use characters that aren't in the MathJax TeX fonts. It is a choice you have to make one way or the other.