erusev / parsedown-extra

Markdown Extra Extension for Parsedown
MIT License
817 stars 121 forks source link

Feature Request: Math Equations #81

Open sbrl opened 8 years ago

sbrl commented 8 years ago

I use Parsedown-Extra for my blog, and I would love to be able to use math equations in my posts.

Using stackedit.io, I can include math equations like this:

Here is a math equation that includes $x$:

$$
y=3x^2+4x+5
$$

They are then rendered using MathJax. There isn't a PHP version of this library I don't think, but simply having the inline MathML is enough as I can find and use a library to render the MathML in the user's browser.

I'm open to helping out wherever I can - I know some PHP, but I am not familiar with the parsedown codebase.

erusev commented 8 years ago

it shouldn't be too hard to implement this as an extension - u could check the example at https://github.com/erusev/parsedown/wiki/Tutorial:-Create-Extensions#add-multi-line-element - it was created by the community and i haven't tested it but it looks fine

erusev commented 8 years ago

p.s. since this math syntax uses a "$" and it is a special characters that the parser is unfamiliar with, u'll also need sth like this in the constructor:

$this->BlockTypes['$'] []= 'MathExpression';
sbrl commented 8 years ago

Right. Thanks! I'll take a look when I have some time.

con-f-use commented 8 years ago

I don't see the need to do it in php. If many people use your blog, it might create unnecessary strain to render the LaTeX math on the server.

Why not leave the equations alone and include something like this in the header of your blog:

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true,
      skipTags: ["script","noscript","style","textarea","pre","code"]
    }
  });
</script>
<script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"></script>

See here (markdown) or the image below for a demo:

demo

sbrl commented 8 years ago

@con-f-use That looks awesome! I think I'll take a look at including that in Pepperminty Wiki and my blog now.

sbrl commented 8 years ago

Oh and do you have any suggestions for a good LaTeX tutorial, @con-f-use?

con-f-use commented 8 years ago

I've found that the LaTeX Wikibook has just about all the information I need.

sbrl commented 8 years ago

@con-f-use Looks good, thanks!

bys1123 commented 5 years ago

@con-f-use thanks, very helpful, but I think now shold use: skipTags: ["<pre>","<code>"]

BenjaminHoegh commented 5 years ago

I do have this extension for Parsedown, there still need some work on the documentation but else it should work perfect. https://github.com/BenjaminHoegh/parsedown-extreme

bys1123 commented 5 years ago

@BenjaminHoegh WOW! nice work!

erusev commented 5 years ago

@BenjaminHoegh the extension looks great, you can list it at https://github.com/erusev/parsedown/wiki/Extensions-and-Related-Libraries