Skip to content

Thanks #41

@williamstein

Description

@williamstein

I'm not aware of a discussion board, but just wanted to say thanks for this plugin. I just integrated it extensively into https://cocalc.com in this commit.

Regarding "Why doesn't markdown-it-texmath work with other engines ?" from the README, I needed to make this also work with mathjax (though we mainly use katex), and found it very easy to do so by using this option when creating the plugin:

engine: {
        renderToString: (tex, options) => {
          // We need to continue to support rendering to MathJax as an option,
          // but texmath only supports katex.  Thus we output by default to
          // html using script tags, which are then parsed later using our
          // katex/mathjax plugin.
          return `<script type="math/tex${
            options.displayMode ? "; mode=display" : ""
          }">${tex}</script>`;
        },
      },

I also needed to parse math environments that is determined by \begin/\end environments, but no dollar signs at all, e.g.,

Consider
\begin{equation}
x^3
\end{equation}

None of the delimiters you have support that, so I just extended the built in dollars one via a new delimiter called "cocalc" that does right after loading as follows. This didn't require changing the code of this extension at all. The regular expression below took me a while to come up with:

// The markdown-it-texmath plugin is very impressive, but it doesn't parse
// things like \begin{equation}x^3$\end{equation} without dollar signs.
// However, that is a basic requirement for cocalc in order to preserve
// Jupyter classic compatibility.  So we monkey patch the plugin
// and extend the regexps to also recognize these.  We do this with a new
// delim object, to avoid any potential conflicts.
texmath.rules["cocalc"] = { ...texmath.rules["dollars"] };
texmath.rules["cocalc"].block.push({
  name: "math_block",
  rex: /(\\(?:begin)\{[a-z]*\*?\}[\s\S]*?\\(?:end)\{[a-z]*\*?\})/gmy, // regexp to match \begin{...}...\end{...} environment.
  tmpl: "<section><eqn>$1</eqn></section>",
  tag: "\\",
});

In any case, many thanks for writing (and maintaining!) this plugin.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions