remarkjs / remark-math

remark and rehype plugins to support math
https://remark.js.org
MIT License
378 stars 57 forks source link

Will \( \) style math formula be supported #39

Closed Ir1d closed 4 years ago

Ir1d commented 4 years ago

Subject of the feature

Describe your issue here.

in some mathjax configs people write \(a+b\) as formulas, will this be supported?

Problem

If the feature requests relates to a problem, please describe the problem you are trying to solve here.

Expected behaviour

What should happen? Please describe the desired behaviour.

parse \(\) as inline and \[\] as dispay

Alternatives

What are the alternative solutions? Please describe what else you have considered?

possible related #21

wooorm commented 4 years ago

While supporting this wouldn’t be too hard to implement (although brittle: the backslashes, parens, and square brackets will interfere with other Markdown constructs, whereas dollars are not in use), I’m not really in favor of adding it: I prefer that remark (and other markdown parsers) push a single way to do things. Having multiple ways to do a similar extension makes the Markdown you write less portable.

Ir1d commented 4 years ago

I totally agree with you. Lets stick with $ and $$

wooorm commented 4 years ago

If someone wants this btw, packages/remark-math can be forked to add that. rehype-katex and such will still work if you expose the same math node in Markdown!

Ir1d commented 4 years ago

yeah I understand, that's nice. I believe using $ only will be better, even though it takes more time to migrate, it's worth the effort.

twavv commented 4 years ago

I (a person on the internet) disagree with this decision.

Using \( is not a config option, it's part of LaTeX syntax and is actually ENCOURAGED: https://tex.stackexchange.com/questions/510/are-and-preferable-to-dollar-signs-for-math-mode.

I understand that TeX !== LaTeX but it still feels like a thing that should be supported.

wooorm commented 4 years ago

We’re not necessarily covering (la)tex here though: it’s about math in markdown in general, which could be mathml or asciimath syntax too.

And, see https://github.com/remarkjs/remark-math/issues/39#issuecomment-612572749: you can do this yourself if you want to!

twavv commented 4 years ago

I don't feel like users should have to fork the project to be able to do this. Is it really that complex to implement here? It seems like it's not (but I might be mistaken).

ChristianMurphy commented 4 years ago

@travigd there's a fine line here. Adding configuration for markers may have value to discuss on it's own.

The push back is on reason presented, which appears to be "it's in latex, so it should be here". That is a non-goal, markdown is not latex.

If you want a latex transformer, contributions towards https://github.com/syntax-tree/ideas/issues/6 are welcome! If there is a markdown focused reason, it may be worth exploring.

twavv commented 4 years ago

Sure, sure, I get it.

From my perspective, I'm just trying to give the best experience possible to the users of my editor (users who are at least partially accustomed to the \( syntax). I'm not arguing that this project should support all things LaTeX (e.g., supporting \begin{align}), but I am arguing that supporting \( is a very pragmatic thing to do.

wooorm commented 4 years ago

I don’t think it’d be good for markdown to standardize several syntaxes. I think we’re in a position to push for one syntax, as the most popular markdown parser, and I think we should do that. Again: you can do whatever you want with plugins, but I don‘t think we should make it easier.

danny-avila commented 10 months ago

If someone wants this btw, packages/remark-math can be forked to add that. rehype-katex and such will still work if you expose the same math node in Markdown!

Can you give some examples on how to do this exactly? Looking at the package code, I'm a little lost albeit I haven't made my own plugin before.

ChristianMurphy commented 10 months ago

@danny-avila see the guide to plugins and ASTs at https://unifiedjs.com/learn/ And extending the parser at https://github.com/micromark/micromark#creating-a-micromark-extension

xl0 commented 1 month ago

@wooorm It looks like OpenAI has decided to use the bracket syntax for its formulas:

https://chat.congusto.ai/public/9834ffd8-e15b-4d4f-83ad-057038e9239d (you can toggle md for the message)

Is there any chance you could reconsider the WONTFIX?

ChristianMurphy commented 1 month ago

https://chat.congusto.ai/public/9834ffd8-e15b-4d4f-83ad-057038e9239d (you can toggle md for the message)

@xl0 did you share the right example? The one you shared uses $ which is already supported.

Is there any chance you could reconsider the WONTFIX?

Not at this time, and not for LLMs. LLMs are masters of formatting things. If your LLM of choice uses non-standard markdown by default, prompt it to use standard markdown 🙂

xl0 commented 1 month ago

@ChristianMurphy, yes:

<prompt>Demonstrate the use of math in markdown</prompt>
<d>easy</d>

You can use LaTeX syntax for math in Markdown, typically supported by platforms like GitHub, Jupyter, or Markdown processors with math support.

Inline math:  
`$E = mc^2$` renders as \( E = mc^2 \).

Block math:  
\```
$$
\int_0^1 x^2 \, dx = \frac{1}{3}
$$
\```
renders as:

\[
\int_0^1 x^2 \, dx = \frac{1}{3}
\]

So it uses the $$ syntax in the example, but then uses the [ ( syntax actually to render the formulas.

I'm not saying, handle it by default, but an option would be great. I kind of see why they chose this style - it's less ambiguous. If it was just any LLM provider, I would not bother, but OpenAI kind of sets the tone for the ecosystem.

wooorm commented 1 month ago

It is recommending humans to use $ though?