remarkjs/remark-math

Option to accept double dollar ($$) for inline maths

SamyPesse opened this issue · 7 comments

Initial checklist

Problem

Single dollars can easily conflict with financial data in a Markdown content.

For example the following markdown content will be parsed with an inline math node:

The **Team** plan starts at $40 per month and includes your first 5 users. Every user after your first 5 users is charged an additional $8 per month.

Solution

For GitBook, we've solved this problem in our custom markdown parser by also using $$ for inline maths.

A math block:

$$
a = b
$$

An inline one $$a = b$$

It'd be great if remark-math could accept an option to use double dollars for inlines.

Alternatives

An alternative could be to only parse inline maths if there is no spaces in it. But it'd not be a great UX for people writing markdown.

Ex:

This is an inline math: $a=b$

This is not an inline math $a = b$

I modelled math after inline code, so escapes don’t work inside it, and spaces can be used to wrap just a single dollar, such as for $$ \$ $$, in which case they are stripped. The same can we done with code: `` ` `` .
So note that you can already use double dollars. Or more.

I also experienced the problem you have with financial data, so I think it’s fine to make this an option.

What name would you suggest?

(note: can you first think about a name before seeing these ideas?)

A similar option exists for strikethrough: https://github.com/micromark/micromark-extension-gfm-strikethrough#optionssingletilde.

  • singleDollarText (true to allow one, false for disallow, default true) — I dislike block and inline, hence text
  • singleDollar (true to allow one for text, false for disallow, default true) — downside is that it’s confusing whether this would affect block/flow

Hi! This was marked as ready to be worked on! Note that while this is ready to be worked on, nothing is said about priority: it may take a while for this to be solved.

Is this something you can and want to work on?

Team: please use the area/* (to describe the scope of the change), platform/* (if this is related to a specific one), and semver/* and type/* labels to annotate this. If this is first-timers friendly, add good first issue and if this could use help, add help wanted.

I'm probably biased by my experience with math formula in markdown at GitBook, but I think it should be the default to use $$ for text since it's a safer default option ($$ works for all content, while $ can conflict with financial data)

(Before looking at your suggestions) a few names i think could work:

  • forceDoubleDollars (default to false for compatibility, until a breaking change and then default to true)
  • acceptSingleDollarInlines (default to true for compatibility, until a breaking change and then default to false)

(After looking at your suggestions) using "text" instead of inline makes sense 👍 I like singleDollarText as an option, it's explicit and do not conflict with blocks.

Hmm, what do you think of singleDollarTextMath?
singleDollarText: true might sound to some as if single dollars would turn into text, but the actual result is the inverse.
singleDollarTextMath: true sounds much more like what’s going to happen? 🤔

Perfect 🙌

Hi! This was closed. Team: If this was fixed, please add phase/solved. Otherwise, please add one of the no/* labels.

Released!