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

unicode characters that behave different from the corresponding LaTeX macro #920

Open
kasperpeulen opened this issue Sep 15, 2014 · 7 comments
Labels
Code Example Contains an illustrative code example, solution, or work-around Feature Request Good first contribution

Comments

@kasperpeulen
Copy link

I've made a list of unicode symbols that behave different from the corresponding LaTeX macro:

\begin{align}
\alpha &=α\\
\Bbb R &=ℝ\\
\sum_{k=0}^n&=∑_{k=0}^n \\
\prod_{k=0}^n&=∏_{k=0}^n \\
\sqrt{2}&=√{2} \\
\sqrt[3]{2} &=∛{2} \\
\sqrt[4]{2} &=∜{2} \\
x^2&=x² \\
x_2&=x₂ \\
\mathscr{C}&=𝒞 \\ 
\mathcal{C}&=𝒞 \\
\overbrace{x+y} &= ⏞{x+y} \\
\underbrace{x+y} &= ⏟{x+y} \\
\end{align}

Demo: http://jsfiddle.net/4WvgA/6/

I made a unicode math typer here: http://kasperpeulen.github.io/PressAndHold/Unicode/
And there I use some Davide hack there, to make those unicode symbol behave like LaTeX macros, but I would like it if people can use my tool also at other places as well. There are probably same unicode characters where it is not obvious how mathjax should handle them. But for many cases, I think there is only one obvious option.

@pkra
Copy link
Contributor

pkra commented Sep 16, 2014

Thanks for posting this here, too.

@hbghlyj
Copy link

hbghlyj commented May 12, 2022

Also the unicode symbol behaves different from the corresponding LaTeX macro \infty
Below is $\infty ∞$ converted to MathML:

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mi mathvariant="normal">&#x221E;</mi>
  <mrow data-mjx-texclass="ORD">
    <mo>&#x221E;</mo>
  </mrow>
</math>

@hbghlyj
Copy link

hbghlyj commented May 12, 2022

Also, the behavior is different for unicode characters and the corresponding LaTeX macro \sum in display style (the LaTeX macro with sub/superscripts are converted to munderover but unicode characters with sub/superscripts are converted to msubsup). For example,

$$∑_{i=1}^n\sum_{i=1}^n$$

is converted to

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <msubsup>
    <mo>&#x2211;</mo>
    <mrow data-mjx-texclass="ORD">
      <mi>i</mi>
      <mo>=</mo>
      <mn>1</mn>
    </mrow>
    <mi>n</mi>
  </msubsup>
  <munderover>
    <mo data-mjx-texclass="OP">&#x2211;</mo>
    <mrow data-mjx-texclass="ORD">
      <mi>i</mi>
      <mo>=</mo>
      <mn>1</mn>
    </mrow>
    <mi>n</mi>
  </munderover>
</math>

Same for other symbols of TeX class OP with movesupsub: !0

$$∏_{i=1}^n\prod_{i=1}^n$$
$$∐_{i=1}^n\coprod_{i=1}^n$$
$$⋁_{i=1}^n\bigvee_{i=1}^n$$

@hbghlyj
Copy link

hbghlyj commented May 16, 2022

Also, the behavior is different for unicode uppercase greek letters and the corresponding LaTeX macros.
For example, $Σ\Sigma$ is converted to

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mi>&#x3A3;</mi>
  <mi mathvariant="normal">&#x3A3;</mi>
</math>

How to change "mathvariant" of unicode uppercase greek letters to "normal" by default? Thanks!

@dpvc
Copy link
Member

dpvc commented May 16, 2022

@hbghlyj, you are correct that MathJax doesn't handle raw unicode characters in the same way as it does the corresponding macros. it is possible, however, to map these characters to the appropriate macros if you wish. One possible version 3 configuration that does this would be the following:

MathJax = {
  startup: {
    ready() {
      const {Configuration} = MathJax._.input.tex.Configuration;
      const {MacroMap} = MathJax._.input.tex.SymbolMap;
      const BaseMethods = MathJax._.input.tex.base.BaseMethods.default;

      //
      //  Subclass the MacroMap to add ['Macro', ...] around the macro string
      //    in the definitions for each character
      //
      class MacroChars extends MacroMap {
        constructor(name, json, methods) {
          for (const [name, macro] of Object.entries(json)) {
            json[name] = ['Macro', macro];
          }
          super(name, json, methods);
        }
      }

      //
      //  Create a macro mapping for the characters to their TeX equivalents
      //
      new MacroChars('unicode-chars', {

        //
        //  Some larg operators
        //
        '\u220F': '\\prod',
        '\u2210': '\\coprod',
        '\u2211': '\\sum',
        '\u222B': '\\int',
        '\u222C': '\\iint',
        '\u222D': '\\iiint',

        //
        //  Greek capitals (you can add the rest)
        //
        '\u03A3': '\\Sigma',

        //
        //  Some other symbols
        //
        '\u221E': '\\infty',
        '\u221A': '\\sqrt',
        '\u221B': '\\sqrt[3]',
        '\u221C': '\\sqrt[4]',

        //
        //  Double-struck letters (add the rest)
        //
        '\u2102': '\\mathbb{C}',
        '\u211D': '\\mathbb{R}',

        //
        //  Over- and under-braces (could do over/under-parens, etc.)
        //
        '\u23DE': '\\overbrace',
        '\u23DF': '\\underbrace',

      }, BaseMethods);
      //
      //  Create the package containing these characters
      //
      Configuration.create(
        'unicode-chars', {handler: {character: ['unicode-chars']}}
      );

      MathJax.startup.defaultReady();
    }
  },
  tex: {
    //
    //  Tell TeX to use your new package
    //
    packages: {'[+]': ['unicode-chars']}
  }
}

I have not included every character that you will want, so you will need to augment this to suit your needs. Note also that the replacement string can be any TeX code, not just a single macro.

This could be the basis for a proper extension, and that would make a nice first effort for someone looking to contribute to MathJax.

@dpvc dpvc added Good first contribution Code Example Contains an illustrative code example, solution, or work-around labels May 16, 2022
@dpvc
Copy link
Member

dpvc commented Jun 21, 2024

This is not an appropriate place to post advertisement for your tool. Also, as it is KaTeX-based rather than MathJax-based, it's also not very tactful.

@dpvc
Copy link
Member

dpvc commented Jun 21, 2024

I just wanted to seek some guidance and be skillful enough for doing open source.

Not at all clear from your original post. Your statement that "I don't know if I can share it here or not, but I thought it might be of some help" suggests you are trying to point people to your tool and that it might be useful to them, which seems like an advertisement, not a request for help.

This issue tracker is for reporting bugs in MathJax or requesting new features, not general guidance for non-MathJax projects or other open-source projects. Since you are not reporting a bug or asking for a feature, and your project isn't even MathJax-based, this is not the right place for your post. It is also not good practice to attache your comment to an existing issue that really has nothing to do with your post, even if it were appropriate for this forum.

If you are looking for general programming or open-source advice, you might consider a forum like stack overflow.

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 Good first contribution
Projects
None yet
Development

No branches or pull requests

4 participants