Giter VIP home page Giter VIP logo

markdown-it-amsmath's People

Contributors

chrisjsewell avatar rowanc1 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

isabella232

markdown-it-amsmath's Issues

Consistent Rule name and token meta information

For the default rule name, it would be great if we could have some consistency with dollarmath package? Maybe math_block_amsmath? Or simply make it a math_block and add some metadata to the token to indicate that it is AMS?

It would be great to have consistency between:

$$
\begin{equation}
Ax = b
\end{equation}
$$ (math)

and

\begin{equation}
\label{math}
Ax = b
\end{equation}

and

```{equation}
:label: math
Ax = b
```

and

$$
Ax = b
$$ (math)

In terms of downstream packages not having to know the intricacies of how the math was parsed, this would mean the tokens in all cases would be something close to:

token.type = 'math_block'
token.content = 'Ax = b' || '\begin{...'
token.meta = {amsmath: true, label: 'math', numbered: true}

Maybe optionally strip out equation environments and parse simple label information. In the future as well, as packages may want to label things on their own.

More permissive AMS math parsing to match mathjax

Describe the bug

Mathjax, which is the default parser in jupyter notebooks is much more permissive when parsing environments than the list here:
https://github.com/executablebooks/markdown-it-amsmath/blob/main/src/index.ts#L53

For example cases is required to be in an ams environment, but mathjax picks up the \begin and \end tags fine, and then wraps it in a \begin{equation*} if it is not in the list above.

When using this to parse notebooks written in jupyter, many people use this shortcut and so the myst parsing fails, and often gets very messy because of underscores in the math being matched outside of the math environment.

Reproduce the bug

Parse:

\begin{cases}
0& \text{if $r-j$ is odd},\\
r!\,(-1)^{(r-j)/2}& \text{if $r-j$ is even}.
\end{cases}

In Jupyter (using mathjax)
image

List your environment

No response

Default HTML tags

Is your feature request related to a problem? Please describe.

Looking at the default renderer here: https://github.com/executablebooks/markdown-it-amsmath/blob/master/src/index.ts#L45

It is currently <section class="amsmath"><eqn>{content}</eqn></section>.

Reading the HTML spec, sections require a header in most situations and generally have more content than a single element. Also note that eqn is not a valid tag and I don;t think we should be providing this as the default.

Describe the solution you'd like

I would propose we use a div with a class for the default.

Either:

<div class="amsmath">{content}</div>

Or simply:

<div class="math amsmath">{content}</div>

Which might work better with dollarmath (math inline and math display) and keep css classes simple/shared.

Describe alternatives you've considered

This can be overridden through the renderer, however, the default should provide good basics and valid html - sticking to semantic rules if possible!

Additional context

In the previous js implementation of this, we were adding a \[ before and after the div, this allowed the default script of mathjax and katex to render when this HTML was output. The class chosen was math rather than amsmath because from a rendering perspective there isn't a difference, so class selection seemed easier with that choice.

Simplify IOptions

I was a bit confused first looking at the interface what the options in both this package and dollarmath that the options we pass in correspond to the user defined renderer function, rather than the package. amsmath does not modify the options, and then calls the renderer with a specific call signature. I feel like these should be the responsibility of the optional renderer, not the package.

export interface IOptions {
  // the render function to use
  renderer?: (content: string, options?: { [key: string]: any }) => string
  // options to parse to the render function
  options?: { [key: string]: any }
}

I would suggest simplifying this interface and encouraging users to deal with the options themselves. Passing them to the package gives me the impression that the library is doing something with them. For example, I am telling amsmath to throwOnError rather than katex.

For example:

const katexOptions = { throwOnError: false, displayMode: true }
const renderer = (mathString, maybeTheToken) => katex.renderToString(mathString, katexOptions)
const md = window.markdownit().use(amsmath, { renderer })

This simplifies the interface to the package, and the options that we may decide to pass into amsmath are actually options of amsmath, that may change in the future.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.