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

How to access MathJax #63

Open
zcysxy opened this issue Aug 1, 2023 · 2 comments
Open

How to access MathJax #63

zcysxy opened this issue Aug 1, 2023 · 2 comments

Comments

@zcysxy
Copy link

zcysxy commented Aug 1, 2023

Sorry I am not very familiar with web development. I want to configure MathJax following the official document like the following example
image

However, it requires to access MathJax within the configure. I tried the following code

const markdownIt = require("markdown-it");
const mathjax = require("markdown-it-mathjax3");

let markdownLib = markdownIt({
  breaks: true,
  html: true,
})
  .use(require("markdown-it-mathjax3"), {
    tex: {
      inlineMath: [["$", "$"]],
    },
    options: {
      skipHtmlTags: { "[-]": ["pre"] },
    },
    startup: {
      ready: () => {
        mathjax.startup.defaultReady();
        mathjax.tex2chtml('\\def\\R{\\mathbb{R}}');
        console.log('hi mathjax');
      }
    }
  })

But it does not seem to work. Thanks!

@zcysxy
Copy link
Author

zcysxy commented Aug 1, 2023

The use case is that I want to render some TeX commands at startup, e.g., defining some macros like \def\R{\mathbb{R}} for every document.

@bill-ion
Copy link

If you read the source code of this plugin, you will find that it only receive tex option and svg option. So the answer is simply that the startup option is not supported so far.

function plugin(md: MarkdownIt, options: any) {
  // Default options

  const documentOptions = {
    InputJax: new TeX({ packages: AllPackages,  ...options?.tex }),
    OutputJax: new SVG({ fontCache: 'none',  ...options?.svg })
  }
  const convertOptions = {
    display: false
  }

  // set MathJax as the renderer for markdown-it-simplemath
  md.inline.ruler.after("escape", "math_inline", math_inline);
  md.block.ruler.after("blockquote", "math_block", math_block, {
    alt: ["paragraph", "reference", "blockquote", "list"],
  });
  md.renderer.rules.math_inline = function (tokens: Token[], idx: number) {
    convertOptions.display = false;
    return renderMath(tokens[idx].content, documentOptions, convertOptions)
  };
  md.renderer.rules.math_block = function (tokens: Token[], idx: number) {
    convertOptions.display = true;
    return renderMath(tokens[idx].content, documentOptions, convertOptions)
  };
};

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

No branches or pull requests

2 participants