progsource / maddy

C++ Markdown to HTML header-only parser library
MIT License
194 stars 39 forks source link

latex support? #31

Open nkeonkeo opened 4 years ago

nkeonkeo commented 4 years ago

Can you add latex support?

inline formula: $...$ display formula: $$...$$

Don't escape the formula.

progsource commented 3 years ago

Yeah, can do that. Just have to find time for it ;)

NicusorN5 commented 1 year ago

I think it's easily possible by using https://www.mathjax.org/ .

In order to write support for a LaTeX rendering framework, it's needed to write a complete HTML generator (with both head and body tags).

progsource commented 1 year ago

With #42 the block format is supported, if you combine it with MathJax. For future versions it could be considered to parse the actual LaTeX code to svg directly.

Trying to add inline support resulted in non-backwards-compatible issues. For example, if the italic parser regex would be changed to something like

static std::regex re("(?!.*`.*|.*<code>.*|[^\\\\]*\\$.*)\\*(?!.*`.*|.*<\\/code>.*)([^\\*]*)\\*(?!.*`.*|.*<\\/code>.*|[^\\\\]*\\$.*)");

then writing Markdown like

some text \$a + b = 3\$ *test* \$a + b = 3\$

would make the italic still work, but

some text $a + b = 3$ *test* $a + b = 3$

would result in the italic text not being italic.

Because of that I postpone the introduction of LaTeX inline support for now, but hope, that adding the block support may help you already a little ;) If you happen to have an idea how to make it work via regex with inline support, feel free to open up a PR.