Skip to content

Conversation

@charliez0
Copy link

#1356

this pr breaks contents with html minification, however normal works well with or without html minification

@charliez0
Copy link
Author

image

when using pre with html minification

@dpvc
Copy link
Member

dpvc commented Jan 8, 2026

Can you say what the HTML minified is actually doing to the MathJax output? I assume that it is changing the newlines to spaces? (Not really much minimization from that.) I also assume you are pre-processing the page, though you don't indicate which mechanism you are using for that.

One of the reasons that the pre CSS is used is to guarantee that the individual pieces of the extender are each on a new line (the normal setting doesn't guarantee that, as the widths of the extenders might not be enough to force a line break at the newline in that case).

You can, of course, include the needed CSS in your page to change the pre to normal in your case. Alternatively, you could use something like

MathJax = {
  chtml: {
    postFilters: [
      ({data, document}) => {
        const adaptor = document.adaptor;
        for (const node of adaptor.tags(data, 'mjx-spacer')) {
          const text = adaptor.textContent(node).replace(/\n/g, '
');
          adaptor.replace(adaptor.text(text), adaptor.firstChild(node));
        }
      }
    ]
  }
};

as part of your MathJax configuration to convert the newlines to entity references that should not be altered by your minimizer. Again, you haven't given the mechanism you are using to process the page, so I can't tell you where to put this in your code. If that is not easy to do, you could use post-processor on the whole page that does something like

html = html.replace(/<mjx-spacer>(.*?)</mjx-spacer>/g, (_, text) => '<mjx-spacer>' + text.replace(/\n/g, '&#10;') + '</mjx-space>');

to do the modification after the fact.

We are probably not going to merge this PR because pre is the better value, here. The fact that the minification has caused a change in the result suggests that it is making some unreliable assumptions about what it can change in the HTML, not that MathJax's output is at fault.

@charliez0
Copy link
Author

Yes, \n was changed into spaces, and the html minification is post processing, I render the math in the background (nodejs) then do html minification

Most users render the math on the browser, with and without HTML compression it would render correctly.

I still don't know if there are any examples that normal would break but pre would render correctly, thanks!

@charliez0
Copy link
Author

And 4.1.0 is the first version to add pre in Mathjax code, and the first one breaks HTML minification without any documentation warning

@charliez0
Copy link
Author

charliez0 commented Jan 9, 2026

@dpvc If you are concerned about this, can I make another PR, change newline into <br> so that compression won't alter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants