micromark / micromark-extension-math

micromark extension to support math (`$C_L$`)
https://unifiedjs.com
MIT License
15 stars 7 forks source link

Can't escape `$` in math #7

Closed nvlang closed 6 months ago

nvlang commented 6 months ago

Initial checklist

Affected packages and versions

micromark-extension-math@3.0.0

Link to runnable example

https://github.com/nvlang/micromark-extension-math-bug

Steps to reproduce

  1. Clone https://github.com/nvlang/micromark-extension-math-bug
  2. Run npm i (or pnpm i)
  3. Run node index.js

Expected behavior

$ a \$ b $ should be parsed as an inline math node with content a \$ b.

Actual behavior

$ a \$ b $ is parsed as follows:

Runtime

Node v16

Package manager

pnpm

OS

macOS

Build and bundle tools

No response


Edit

I just looked at this package's unit tests and noticed that this seems to be the expected behavior. I'm guessing the idea is to replicate the behavior from backticks. I suppose that this makes this not a bug report, but rather a matter of personal preference. However, I do believe that there is an argument in favor of the behavior I expected: it mirrors the behavior inside TeX documents.

I understand that there are advantages to having $ behave like backticks; the main one that comes to mind is the ability to have math within text within math, i.e., $$\text{$x$}$$ $\text{$x$}$. However, that behavior is still reconcilable with the behavior I expected.

wooorm commented 6 months ago

Right, you already answered this yourself. This is intended behavior. It is documented clearly: https://github.com/micromark/micromark-extension-math#syntax.

People probably know how code works in markdown. Or if they don’t, but then they can learn it, and it applies to both code and math.

I love not having to use escapes in code (and math). And it annoys me to have to do it in HTML.

You can use $$a $ b$$ for your case.

github-actions[bot] commented 6 months ago

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