MathJax \symbf vs Unicode-Math \symbf behavior for bold Greek

54 views
Skip to first unread message

Miles Moran

unread,
Feb 12, 2024, 2:21:18 PMFeb 12
to MathJax Users
Hi all,

I'm currently working on a Quarto/Pandoc website with MathJax as the math renderer of choice. I noticed that the behavior of the \symbf command as it's implemented in base MathJax differs from the behavior of the \symbf command as it's implemented in the Unicode-Math LaTeX package. Namely, it appears that MathJax always substitutes \symbf for \symbfup; but, Unicode-Math substitutes \symbf for either \symbfit (for lowercase Greek) or \symbfup (for everything else).

Is there a way to change the behavior of the MathJax \symbf to better match the Unicode-Math \symbf? More generally, does MathJax support custom commands whose outputs depend on the hex value / BMP block of the Unicode characters used as input?

Cheers,
Miles

Davide Cervone

unread,
Feb 17, 2024, 6:40:34 PMFeb 17
to mathja...@googlegroups.com
Because MathJax converts the TeX notation into MathML, and MathML has a very different idea of how to handle font styles than TeX does, MathJax has a rather different approach to fonts than TeX.  Currently, \symbf just sets its contents using mathvariant="bold", and that is why the Greek letters are not italic (as that would need to be mathvariant="bold-italic").  In v4, however, there is a new mechanism for setting how Latin and Greek letters are displayed using upright or italic, and it may be possible to use that mechanism within `\symbf` and related macros to italicize the Greek letters.  I will need to look into it.

Davide


--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mathjax-users/272fe096-d756-41f6-8a7c-f9002edb6a4en%40googlegroups.com.

Davide Cervone

unread,
Feb 18, 2024, 12:42:12 PMFeb 18
to mathja...@googlegroups.com
I've made a PR that implements this for the next v4 release.

Davide

Davide Cervone

unread,
Feb 18, 2024, 1:58:49 PMFeb 18
to mathja...@googlegroups.com
Here is a configuration that can be used to make \symbf and \symsf (the only two that seem to be affected) to apply the Latin and Greek italic styles specified by the mathStyle option in the tex block of the MathJax configuration.

MathJax = {
  tex: {packages: {'[+]': ['my-sym']}},
  startup: {
    ready() {
      const {Configuration} = MathJax._.input.tex.Configuration;
      const {CommandMap} = MathJax._.input.tex.TokenMap;
      const {MapHandler} = MathJax._.input.tex.MapHandler;
      const {TexConstant} = MathJax._.input.tex.TexConstants;
      const TexParser = MathJax._.input.tex.TexParser.default;
      const ParseUtil = MathJax._.input.tex.ParseUtil.default;
      const NodeUtil = MathJax._.input.tex.NodeUtil.default;
      const {getRange} = MathJax._.core.MmlTree.OperatorDictionary;
      const MATHVARIANT = TexConstant.Variant;
      
      function Other(parser, char) {
        const font = parser.stack.env['font'];
        const ifont = parser.stack.env['italicFont'];
        let def = font ? {mathvariant: font} : {};
        const remap = MapHandler.getMap('remap').lookup(char);
        const range = getRange(char);
        const type = range[3]
        let mo = parser.create('token', type, def, (remap ? remap.char : char));
        const style = (ParseUtil.isLatinOrGreekChar(char) ? parser.configuration.mathStyle(char, true) || ifont : '');
        const variant = (range[4] || (font && style === MATHVARIANT.NORMAL? '' : style));
        if (variant) {
          mo.attributes.set('mathvariant', variant);
        }
        if (type === 'mo') {
          NodeUtil.setProperty(mo, 'fixStretchy', true);
          parser.configuration.addNode('fixStretchy', mo);
        }
        parser.Push(mo);
      }
      
      new CommandMap('my-sym', {
        symbf: ['MathFont', MATHVARIANT.BOLD, MATHVARIANT.BOLDITALIC],
        symsf: ['MathFont', MATHVARIANT.SANSSERIF, MATHVARIANT.SANSSERIFITALIC]
      }, {
        MathFont(parser, name, variant, italic) {
          const text = parser.GetArgument(name);
          let mml = new TexParser(text, {
            multiLetterIdentifiers: parser.options.identifierPattern,
            ...parser.stack.env,
            font: variant,
            italicFont: italic,
            noAutoOP: true
          }, parser.configuration).mml();
          parser.Push(parser.create('node', 'TeXAtom', [mml]));
        }
      });
      
      Configuration.create('my-sym', {
        handler: {
          macro: ['my-sym']
        },
        fallback: {
          character: Other
        }
      });
      
      MathJax.startup.defaultReady();
    }
  }
};

it's a bit long, but should do the trick.

Davide
Reply all
Reply to author
Forward
0 new messages