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

Lazy Typesetting vs. JSXGraph #2720

Open
Mathebibel opened this issue Jun 26, 2021 · 5 comments
Open

Lazy Typesetting vs. JSXGraph #2720

Mathebibel opened this issue Jun 26, 2021 · 5 comments
Labels
Code Example Contains an illustrative code example, solution, or work-around Merged Merged into develop branch Needs Documentation v3
Milestone

Comments

@Mathebibel
Copy link

Mathebibel commented Jun 26, 2021

After activating lazy typesetting (BTW: What a great feature!) all MathJax formulas in my JSXGraph graphics lost their position. Most of the formulas seem to have moved down a little bit. I use LaTeX + CHTML and Firefox on Linux.

@dpvc
Copy link
Member

dpvc commented Jun 28, 2021

I don't know what mechanism is used to use MathJax in JSXGraph, so I can't really tell for sure, but I suspect that JSXGraph is delayed until MathJax runs and then it lays out the graph using the height/depth/width of the typeset math for positioning. but for lazy typesetting, the initial typeset doesn't fill in the math, so you get a zero-height, zero-depth, zero-width expression, and then that is later replaced by the typeset version when it scrolls into view. JSXGraph will have already placed the math based on the zero sizes and so the newly typeset math is misplaced.

One possible approach would be to give the lazy typesetting an option that allows some math to be typeset initially even before it is in view, so that the graphics would be processed as normal, but the rest of the page is lazy typeset.

@Mathebibel
Copy link
Author

I really like your proposed approach.

Let's say I want to process all formulas whose containers have the class render-normal as normal and rest of the page is lazy typeset. How would you do that?

@dpvc
Copy link
Member

dpvc commented Jun 30, 2021

Here is a configuration that I think will do the job.

MathJax = {
  loader: {load: ['ui/lazy']},
  startup: {
    elements: ['.render-normal'],
    ready() {
      MathJax.startup.defaultReady();
      const doc = MathJax.startup.document;
      doc.options.normalRender = true;
      class myMathItem extends doc.options.MathItem {
        constructor(...args) {
          super(...args);
          if (MathJax.startup.document.options.normalRender) {
            this.lazyCompile = this.lazyTypeset = false;
          }
        }
      }
      doc.options.MathItem = myMathItem;
    },
    pageReady() {
      return MathJax.startup.defaultPageReady().then(() => {
        MathJax.startup.document.options.normalRender = false;
        return MathJax.typesetPromise();
      });
    }
  }
};

This first renders all the render-normal elements (and their contents) without lazy typesetting, then goes back and renders the rest of the page using lazy typesetting. See of that works for you.

@dpvc dpvc added the Code Example Contains an illustrative code example, solution, or work-around label Jun 30, 2021
@Mathebibel
Copy link
Author

You added the tag v2. I think it should be v3.

@dpvc dpvc added v3 and removed v2 labels Jul 5, 2021
@dpvc
Copy link
Member

dpvc commented Jul 5, 2021

Thanks. Fixed it.

@dpvc dpvc self-assigned this Jan 11, 2022
@dpvc dpvc removed the Investigate label Jan 30, 2022
dpvc added a commit to mathjax/MathJax-src that referenced this issue Feb 10, 2022
@dpvc dpvc added Merged Merged into develop branch and removed Ready for Review labels Apr 6, 2022
@dpvc dpvc added this to the 3.3.0 milestone Aug 5, 2022
@dpvc dpvc removed their assignment Aug 6, 2022
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 Merged Merged into develop branch Needs Documentation v3
Projects
None yet
Development

No branches or pull requests

2 participants