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

[tex2svg-page]-like processing: styles only included in first rendering #2678

Closed
pkra opened this issue Apr 27, 2021 · 3 comments
Closed

[tex2svg-page]-like processing: styles only included in first rendering #2678

pkra opened this issue Apr 27, 2021 · 3 comments
Labels
Accepted Issue has been reproduced by MathJax team Code Example Contains an illustrative code example, solution, or work-around Fixed Test Needed v3 v3.2
Milestone

Comments

@pkra
Copy link
Contributor

pkra commented Apr 27, 2021

Sorry for the convoluted title. I'm not sure if the following is expected or not.

Say you do the following (based on https://github.com/mathjax/MathJax-demos-node/blob/master/direct/tex2svg-page)

const { mathjax } = require('mathjax-full/js/mathjax.js');
const { TeX } = require('mathjax-full/js/input/tex.js');
const { SVG } = require('mathjax-full/js/output/svg.js');
const { RegisterHTMLHandler } = require('mathjax-full/js/handlers/html.js');

const {
  BaseConfiguration,
} = require('mathjax-full/js/input/tex/base/BaseConfiguration.js');
const { jsdomAdaptor } = require('mathjax-full/js/adaptors/jsdomAdaptor.js');
const { JSDOM } = require('jsdom');
const adaptor = jsdomAdaptor(JSDOM);
RegisterHTMLHandler(adaptor);

const tex = new TeX({
  packages: [
    BaseConfiguration.name,
  ],
});
const svg = new SVG({
  fontCache: 'global',
});

const run = (documentstring) => {
  const mj = mathjax.document(documentstring, {
    InputJax: tex,
    OutputJax: svg,
  });
  mj.render();
  return (
    adaptor.doctype(mj.document) + adaptor.outerHTML(adaptor.root(mj.document))
  );
};


console.log(run(`<!DOCTYPE html><html lang="en">$$x$$ </html>`))
console.log(run(`<!DOCTYPE html><html lang="en">$$x$$ </html>`))

Then the second output will not include the SVG output styles (<style id="MJX-SVG-styles">...</style>).

Is this expected? It makes it slightly difficult to test multiple page renderings.

@dpvc
Copy link
Member

dpvc commented Apr 27, 2021

Is this expected?

Well, yes and no. Because you are using the same instance of the output jax for both, the second run thinks it has already inserted the stylesheet into the page, and doesn't do it again. But that's probably not desired behavior.

One work-around for now would be to add svg.svgStyles = null; before the mj.render() call:

const run = (documentstring) => {
  const mj = mathjax.document(documentstring, {
    InputJax: tex,
    OutputJax: svg,
  });
  svg.svgStyles = null;
  mj.render();
  return (
    adaptor.doctype(mj.document) + adaptor.outerHTML(adaptor.root(mj.document))
  );
};

@dpvc
Copy link
Member

dpvc commented Apr 27, 2021

I've made a PR that should resolve the issue.

@pkra
Copy link
Contributor Author

pkra commented Apr 27, 2021

Thanks, Davide.

@dpvc dpvc added Ready for Review Test Needed Code Example Contains an illustrative code example, solution, or work-around labels May 13, 2021
dpvc added a commit to mathjax/MathJax-src that referenced this issue May 24, 2021
Clear the stylesheet when used in a new MathDocument.  (mathjax/MathJax#2678)
dpvc added a commit to mathjax/MathJax-src that referenced this issue May 24, 2021
Revert "Clear the stylesheet when used in a new MathDocument.  (mathjax/MathJax#2678)"
dpvc added a commit to mathjax/MathJax-src that referenced this issue May 24, 2021
Clear the stylesheet when used in a new MathDocument.  (mathjax/MathJax#2678)
@dpvc dpvc added Merged Merged into develop branch and removed Ready for Review labels May 24, 2021
@dpvc dpvc added this to the 3.2 milestone Jun 16, 2021
@dpvc dpvc added Fixed v3.2 and removed Merged Merged into develop branch labels Jul 6, 2021
@dpvc dpvc closed this as completed Jul 6, 2021
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 Code Example Contains an illustrative code example, solution, or work-around Fixed Test Needed v3 v3.2
Projects
None yet
Development

No branches or pull requests

2 participants