pragdave / earmark

Markdown parser for Elixir
Other
866 stars 135 forks source link

Does Earmark have any support for entering latex math into markdown #461

Closed CharlesIrvineKC closed 1 year ago

CharlesIrvineKC commented 1 year ago

In my LiveView app, I am displaying markdown text as HTML using Earmark. I would like to now support entering math symbols, for example, an equation, etc, into my markdown text, and getting that displayed properly in the Earmark translation to HTML. I had hoped that there was support for this but I’m not finding any. Does Earmark have any support for this?

RobertDober commented 1 year ago

I am afraid this is not on the radar.

CharlesIrvineKC commented 1 year ago

Darn. Well, maybe I'll switch over to something like Quill. Thanks for letting me know.

CharlesIrvineKC commented 1 year ago

Regarding this issue, I did find what seems like a good solution. Latex math symbols are nice rendered using MathJax. Instructions are here. For your Earmark container element, you will need to specify phx-update="ignore".

RobertDober commented 1 year ago

I do not know if a full fledged HTML parser will solve this issue, but I guess it might, this is on the radar for 1.5 and I will work on it in my free time. (Target v1.5)

However ETA ???, I dunno, if I win the lottery, 2 weeks 😅

RobertDober commented 1 year ago

BTW what does not work right now? If you put all tags in one line

 λ cat tmp/math.md                                                                                                                                                   [8:16:41]
# Some Math
<p>
 When \(a \ne 0\), there are two solutions to \(ax^2 + bx + c = 0\) and they are
  \[x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\]
</p>

╭─>robert@aude ~/gh/elixir/earmark                                                                                                            ❰1.14➤25.0.4❱ [±ed1642d ●]
╰─> λ earmark tmp/math.md                                                                                                                                               [8:16:51]
<h1>Some Math</h1>
<p>
 When \(a \ne 0\), there are two solutions to \(ax^2 + bx + c = 0\) and they are
  \[x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\]
</p>
CharlesIrvineKC commented 1 year ago

@RobertDober Don't know if you saw my previous post, but I do have what seems like a nice solution. Latex math symbols are nicely rendered using MathJax. Instructions are here. This is the same library that GitHub uses to render math symbols in markdown files. https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/writing-mathematical-expressions

For my template container element, I need to specify phx-update="ignore".

<p>$$\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)$$</p>

renders as this:

Untitled

RobertDober commented 1 year ago

Great, yes I was not concerned about the template as you have full control but only if Earmark might unescape characters or other stuff which might cause problems.

Happy it does not.

Thanx for the update.

RobertDober commented 1 year ago

And thanx too for the example which is a formula of a French mathematicien IIRC 🤣