parsedown-extra icon indicating copy to clipboard operation
parsedown-extra copied to clipboard

Feature Request: Math Equations

Open sbrl opened this issue 8 years ago • 12 comments

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.

sbrl avatar Nov 22 '15 15:11 sbrl

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 avatar Nov 23 '15 14:11 erusev

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';

erusev avatar Nov 23 '15 14:11 erusev

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

sbrl avatar Nov 30 '15 12:11 sbrl

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

con-f-use avatar Mar 24 '16 18:03 con-f-use

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

sbrl avatar Mar 24 '16 20:03 sbrl

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

sbrl avatar Mar 24 '16 20:03 sbrl

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

con-f-use avatar Mar 24 '16 20:03 con-f-use

@con-f-use Looks good, thanks!

sbrl avatar Mar 25 '16 08:03 sbrl

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

bys1123 avatar Dec 06 '18 18:12 bys1123

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

BenjaminHoegh avatar Dec 09 '18 07:12 BenjaminHoegh

@BenjaminHoegh WOW! nice work!

bys1123 avatar Dec 09 '18 11:12 bys1123

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

erusev avatar Dec 09 '18 11:12 erusev