Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font is italic for unicode text #2744

Closed
abnerlee opened this issue Jul 24, 2021 · 11 comments
Closed

Font is italic for unicode text #2744

abnerlee opened this issue Jul 24, 2021 · 11 comments
Labels
Code Example Contains an illustrative code example, solution, or work-around Feature Request Fixed Test Needed v3 v3.2
Milestone

Comments

@abnerlee
Copy link

MathJax v3

For math like $$数学$$, the Chinese characters are italic, its character is rendered as

<mjx-utext variant="italic" style="font-size: 84%; padding: 0.893em 0px 0.238em; font-family: MJXZERO, serif; font-style: italic;">学</mjx-utext>

but in v2, the character are not in italic.

So, is there a reason of this spec change, and is there any options to control this?

@GoBigorGoHome
Copy link

GoBigorGoHome commented Jul 24, 2021

@abnerlee Just upgraded to the latest Typora and noticed the change. The italic Chinese characters in my math formulas looks really bad (actually italic font shapes are just not for Chinese characters at all). Is it possible to change the font by solely configuring Typora, for example, using CSS?

A workaround is to wrap Chinese characters in math into \text{...}. But that's too much work for existing math formulas. I wish there is a way to change the font as I often include Chinese characters in math formulas for expository purpose. It is tedious for me to have to write \text{...}.

@abnerlee
Copy link
Author

@GoBigorGoHome If you don't need italic in math at all, then you can use css

[data-variant='italic'] {
    font-style: normal;
}

to force ignore italic texts, but that is just workaround with side effects.


still requires feedback from MathJax side.

@dpvc
Copy link
Member

dpvc commented Jul 26, 2021

In versions prior to 3.2, MathJax would place all characters that it doesn't think of as "letters" into <mo> elements. In version 3.2, that decision was made more nuanced so that the unicode block in which such characters occur is now taken into account to determine what MathML node to use. Now <mo> is used for symbols, while <mi> is used for letters and most language-specific characters. This improves the semantics of the underlying MathML (since these characters are not operators, as <mo> would indicate).

Since an <mi> with a single character is in italics, that is why your characters are now in italics. The expected encoding for your expression would be $$\text{数学}$$, since these two characters form a single word, just as you would use $$\text{mathematics}$$ rather than $$mathematics$$ (which would be typeset in italics with incorrect inter-character spacing). While it does take extra work to include \text{..}, that does properly indicate your intent, while leaving it out does not.

As a work-around, you could change the MathML node associated with the Chinese ranges to be <mtext> rather than <mi>, which would give you upright letters, but each in its own <mtext> element, which is still not correct, but at least will display as you prefer. To do that merge

MathJax = {
  startup: {
    ready() {
      const {RANGES} = MathJax._.core.MmlTree.OperatorDictionary;
      RANGES[28][3] = RANGES[30][3] = RANGES[33][3] = RANGES[47][3] = 'mtext';
      MathJax.startup.defaultReady();
    }
  }
};

into your current MathJax configuration.

@dpvc dpvc added Expected Behavior This is how MathJax works v3 Code Example Contains an illustrative code example, solution, or work-around labels Jul 26, 2021
@jtzwuwu
Copy link

jtzwuwu commented Jul 27, 2021

In versions prior to 3.2, MathJax would place all characters that it doesn't think of as "letters" into <mo> elements. In version 3.2, that decision was made more nuanced so that the unicode block in which such characters occur is now taken into account to determine what MathML node to use. Now <mo> is used for symbols, while <mi> is used for letters and most language-specific characters. This improves the semantics of the underlying MathML (since these characters are not operators, as <mo> would indicate).

Since an <mi> with a single character is in italics, that is why your characters are now in italics. The expected encoding for your expression would be $$\text{数学}$$, since these two characters form a single word, just as you would use$$\test{mathematics}$$ rather than $$mathematics$$ (which would be typeset in italics with incorrect inter-character spacing). While it does take extra work to include \text{..}, that does properly indicate your intent, while leaving it out does not.

As a work-around, you could change the MathML node associated with the Chinese ranges to be <mtext> rather than <mi>, which would give you upright letters, but each in its own <mtext> element, which is still not correct, but at least will display as you prefer. To do that merge

MathJax = {
  startup: {
    ready() {
      const {RANGES} = MathJax._.core.MmlTree.OperatorDictionary;
      RANGES[28][3] = RANGES[30][3] = RANGES[33][3] = RANGES[47][3] = 'mtext';
      MathJax.startup.defaultReady();
    }
  }
};

into your current MathJax configuration.

Frankly speaking, the biggest problem is that almost no one uses italicized Chinese characters.

@abnerlee
Copy link
Author

abnerlee commented Aug 3, 2021

I saw English letters and geek letters like α are also be put into <mi>, like $$aaa$$, but they are not italics as default

@dpvc
Copy link
Member

dpvc commented Aug 3, 2021

I saw English letters and geek letters like α are also be put into <mi>, like $$aaa$$, but they are not italics as default

They should be, and they are for me. Can you provide a minimal example page where they are not italic?

@abnerlee
Copy link
Author

abnerlee commented Aug 3, 2021

I see, so their italic are just font change?

Screen Shot 2021-08-03 at 23 27 31

@dpvc dpvc self-assigned this Feb 11, 2022
@dpvc dpvc added this to the 3.2.1 milestone Feb 11, 2022
dpvc added a commit to mathjax/MathJax-src that referenced this issue Feb 22, 2022
Add ability for TeX input to force normal variant for CJK input.  (mathjax/MathJax#2744)
@dpvc dpvc added Merged Merged into develop branch and removed Ready for Review labels Feb 22, 2022
@dpvc dpvc removed their assignment Jun 1, 2022
@dpvc dpvc closed this as completed Jun 1, 2022
@dpvc dpvc added Fixed v3.2 and removed Merged Merged into develop branch labels Jun 1, 2022
@njlarsson
Copy link

Could I get an explanation for how to get upper-case greek letters to be displayed upright in math mode?

In my setup, for instance $Σ$ is displayed upright, just like $\Sigma$, in PDF documents produced via LaTeX (more specifically, lualatex), but they are slanted by MathJax in web pages. The way I understand the above, there is a fix in 3.2 that should allow it to be displayed upright, but what do I do to activate this? If the workaround by @dpvc from July 2021 is still applicable, how do I make it apply to greek upper-case?

(I write documents in Org Mode, and would like the maths to be displayed in the same way whether it’s exported to HTML or LaTeX.)

@dpvc
Copy link
Member

dpvc commented Jul 31, 2023

@njlarsson, do you know the version of MathJax that you are using? (Use the "About MathJax" entry in the MathJax contextual menu to find out.) Older versions of org-mode used MathJax v2, but it looks like the current version of org-mode has been updated to use MathJax v3, so that should allow you to use v3.2, which should handle the Unicode characters properly for you.

@njlarsson
Copy link

@dpvc It’s 3.2. “Properly” may be different things for different people. I suppose some people want Σ to be slanted, and I don’t expect upright to be the default. But for instance, this small example,

<html>
    <head>
        <meta charset="UTF-8">
        <title>A web page</title>
    </head>
    <body>
        <script type="text/javascript" id="MathJax-script" async
                src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
        </script>
        
        LaTeX: \(\Sigma\), Unicode: \(Σ\).
    </body>
</html>

makes \Sigma come out upright but the Σ slanted:

Screenshot 2023-07-31 at 17 13 07

I would like to know how to configure MathJax to make them both look like the first one.

@dpvc
Copy link
Member

dpvc commented Jul 31, 2023

@njlarsson: OK, my fault. I was looking at 4.0.0-beta.3, which handles the Greek characters differently.

Here is a configuration for v3.2.2 that will make the upper-case Greek letters upright when entered as literal Unicode characters.

        MathJax = {
          startup: {
            ready() {
              const {RANGES} = MathJax._.core.MmlTree.OperatorDictionary;
              const {TEXCLASS} = MathJax._.core.MmlTree.MmlNode;
              RANGES.splice(4, 1,
                [0x0370, 0x0385, TEXCLASS.ORD, 'mi'],
                [0x0386, 0x3AB, TEXCLASS.ORD, 'mi', 'normal'],
                [0x03AC, 0x1A20, TEXCLASS.ORD, 'mi']
              );
              MathJax.startup.defaultReady();
            }
          }
        };

(at least all the plain ones; some explicitly accented ones are not fixed by this.)

See if that works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Example Contains an illustrative code example, solution, or work-around Feature Request Fixed Test Needed v3 v3.2
Projects
None yet
Development

No branches or pull requests

5 participants