Skip to content

Fragments in MathJax #1365

@mungerd

Description

@mungerd

I wanted to be able to use fragments (with specific indices) inside MathJax contents.
I added the following lines to plugin/math/math.js:

        MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
            var TEX = MathJax.InputJax.TeX;
            TEX.Definitions.Add({macros: {'fragment': 'FRAGMENT_INDEX_attribute'}});
            TEX.Parse.Augment({
             FRAGMENT_INDEX_attribute: function (name) {
                 var index = this.GetArgument(name);
                 var arg   = this.ParseArg(name);
                 this.Push(arg.With({
                    'class': 'fragment',
                    attrNames: ['data-fragment-index'],
                    attr: {'data-fragment-index':index}
                 }));
             }
            });
        });

So now I can type in equations like \[ x \fragment{2}{+ y} \fragment{1}{= z} \], where "x" appears first, followed by "x = z" and then "x + y = z".
Would it make sense to include something like this in math.js?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions