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

MathJax v4.0.0-beta.3 does not seem to support spreadlines environments #3072

Open
sebsciarra opened this issue Jul 25, 2023 · 5 comments
Open
Labels
Accepted Issue has been reproduced by MathJax team Merged Merged into develop branch Test Not Needed v4
Milestone

Comments

@sebsciarra
Copy link

I noticed that MathJax v4.0.0-beta.3 does not seem to support spreadlines environments. For example,

$$
\begin{spreadlines}{0.5em}
\begin{align*}
\mathbf{X} &= \[\mathbf{x}_1, \mathbf{x}_2\] \sim \mathcal{N}(\mu, \Sigma) \cdot \mathbb{I}(\mathbf{x}_1, \mathbf{x}_2 \in \[1, 10\]), \\\\
\mu &= \[5, 7\] \text{ and} \\\\
\sigma &= \[1.2, 1.4\] \\\\
\end{align*}
\end{spreadlines}
$$

gets rendered when using

<script src="https://cdn.jsdelivr.net/npm/mathjax@4.0.0-alpha.1/es5/tex-mml-chtml.js"></script>```

but not with

<script src="https://cdn.jsdelivr.net/npm/mathjax@4.0.0-beta.3/tex-mml-chtml.js"></script>
@dpvc
Copy link
Member

dpvc commented Jul 25, 2023

It works for me (once I change \[ to [ and \] to ], which I assume has to do with your content management system).

When you say the second doesn't get rendered, do you mean there is an error message, or that the spreadlines has no effect, or something else?

@sebsciarra
Copy link
Author

sebsciarra commented Jul 25, 2023

Hmm, removing the slashes does not seem to work for me.

Yes, on the rendered webpage, it says unknown environment 'spreadlines'.
Screenshot 2023-07-25 at 8 36 43 AM

@dpvc
Copy link
Member

dpvc commented Jul 26, 2023

The spreadlines environment is part of the mathtools package, which you need to load and configure explicitly. Are you loading [tex]/mathtools and have you added it to the TeX package configuration?

You don't provide your MathJax configuration that we requested in the template for bug reports, which you ignored. It is for situations like this that we request that information. IN future, it would help if you actually followed the bug report template that we provided.

@sebsciarra
Copy link
Author

I am really sorry about that (I have a bad habit of automatically highlighting text and deleting it). Just saw it now. Will definitely make sure to follow it in future reports!

Here is a more informative report:

Issue Summary

As mentioned above, I cannot seem to get spreadlines environments to render using MathJax 4.0.0-beta.3. I get highlighted red text saying unknown environment 'spreadlines'. For instance, even something as simple as

$$
\begin{spreadlines}{0.5em}
\begin{align}
x = 1
\end{align}
\end{spreadlines}
$$

does not render. I get this with Safari Version 16.4 and Chrome Version 114.0.5735.198 (Official Build, x86_64).

I am using the following MathJax configuration:

window.MathJax = {

  section: {
    n: -1,
    useLetters: false,
    letters: "AABCDEFGHIJKLMNOPQRSTUVWXYZ"
  },


  loader: {load: ['[tex]/tagformat', '[tex]/mathtools', 'output/chtml']},
  tex: {
    inlineMath: [['$', '$'], ['\\(', '\\)']], //allow inline math
    displaymath: [['$$','$$'], ['\\[','\\]']],
    tagSide: 'right', //location of equation numbers
    processEscapes: true,
    processEnvironments: true,
    tags: 'all',
    packages: {'[+]': ['tagformat', 'sections', 'autoload-all', 'mathtools']},
    tagformat: {
      number: (n) => {
        const section = MathJax.config.section;
        return (section.useLetters ? section.letters[section.n] : section.n) + '.' + n;
      }
    }},

  chtml: {
   mtextInheritFont: true,         // font to use for mtext, if not inheriting (empty means use MathJax fonts)
   displayOverflow: 'linebreak'
   },


  linebreaks: {                  // options for when overflow is linebreak
      inline: true,                   // true for browser-based breaking of inline equations
      width: '90%',                  // a fixed size or a percentage of the container width
      lineleading: 2,                // the default lineleading in em units
      LinebreakVisitor: null,         // The LinebreakVisitor to use
  },


  startup: {
    ready() {
      const {CommonWrapper} = MathJax._.output.common.Wrapper;
      const {LineBBox} = MathJax._.output.common.LineBBox;
       const {ChtmlMtable} = MathJax._.output.chtml.Wrappers.mtable;
      const Configuration = MathJax._.input.tex.Configuration.Configuration;
      const CommandMap = MathJax._.input.tex.SymbolMap.CommandMap;
      new CommandMap('sections', {
        nextSection: 'NextSection',
        setSection: 'SetSection',
      }, {
        NextSection(parser, name) {
          MathJax.config.section.n++;
          parser.tags.counter = parser.tags.allCounter = 0;
        },
        SetSection(parser, name) {
          const section = MathJax.config.section;
          const c = parser.GetArgument(name);
          const n = section.letters.indexOf(c);
          if (n >= 0) {
            section.n = n;
            section.useLetters = true;
          } else {
            section.n = parseInt(c);
            section.useLetters = false;
          }
        },
      });
      Object.assign(ChtmlMtable.prototype, {
        adjustWideTable() {
          const attributes = this.node.attributes;
          if (attributes.get('width') !== 'auto') return;
          const [pad, align] = this.getPadAlignShift(attributes.get('side'));
          const W = Math.max(this.containerWidth / 10, this.containerWidth - pad - (align === 'center' ? pad : 0));
          this.naturalWidth() > W && this.adjustColumnWidths(W);
        }
      });



      Configuration.create(
        'sections', {handler: {macro: ['sections']}}
      );
      MathJax.startup.defaultReady();
    }
  }
};

and loading MathJax via

<script src="https://cdn.jsdelivr.net/npm/mathjax@4.0.0-beta.3/tex-chtml.js"></script>

Note that the spreadlinesenvironment renders perfectly fine if I use MathJax 4.0.0-alpha using

 <script src="https://cdn.jsdelivr.net/npm/mathjax@4.0.0-alpha.1/es5/tex-mml-chtml.js"></script>

Supporting information:

I cannot provide a link to a live working example, but I have provided relevant screenshots of the console errors (see attached image below).

console_report

It seems math tools may not be loading?
mathtools

With respect to the point below
* Include the MathJax configuration you are using, and the script tag that loads MathJax itself., I believe I have provided it above, but do let me know if I am incorrect.

@dpvc
Copy link
Member

dpvc commented Jul 26, 2023

OK, thanks for the full report. That helps a lot.

It does look like mathtools isn't loading properly. I will need to look into it further before I can tell you want is happening.

@dpvc dpvc added Accepted Issue has been reproduced by MathJax team and removed Cannot Reproduce labels Aug 11, 2023
dpvc added a commit to mathjax/MathJax-src that referenced this issue Aug 11, 2023
dpvc added a commit to mathjax/MathJax-src that referenced this issue Aug 17, 2023
Change Symbol to Token to avoid conflict with native Symbol in webpacked files. (mathjax/MathJax#3072)
@dpvc dpvc added Merged Merged into develop branch Test Not Needed and removed Ready for Review labels Aug 17, 2023
@dpvc dpvc added this to the v4.0 milestone Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Issue has been reproduced by MathJax team Merged Merged into develop branch Test Not Needed v4
Projects
None yet
Development

No branches or pull requests

2 participants