bytesparadise / libasciidoc

A Golang library for processing Asciidoc files.
Apache License 2.0
197 stars 23 forks source link

Support for equations and formulas. #608

Open bwklein opened 4 years ago

bwklein commented 4 years ago

Many technical documents require the presentation of mathematical equations and formulas. Right now, I am using the mathematical extension for Asciidoctor because it generates images (PNG or SVG) that work in the HTML and PDF output and doesn't require MathJax for the HTML output to render. https://github.com/asciidoctor/asciidoctor-mathematical

gdamore commented 4 years ago

No doubt this would be useful to some. However, I have to think this is a likely to be a huge project. The issue is that I don't think anyone has written code in go to process these, so we would wind up having both create and render this ourselves right now. Of course if someone creates some Go package(s) to process latex math stuff externally, that would help.

I wonder if we could get there via a docbook backend. That's kind of crummy, but it could at least be a gateway?

The other thing is that right now the backends for libasciidoc are very focused on SGML languages.

xiayulu commented 2 years ago

I plan to write tutorials using asciidoc. My articles contains many mathematical equations and formulas.

Here is my Mathjax solution:

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<h1>This is a Heading</h1>
<p>This is a paragraph. $f(x)=x^2+1$ Inline math is ok.</p>
<p> 
What about display math
$$
f(x)=\sum_{i=0}^n x_i\quad \text{for}\quad x\not =2
$$

Oh, that's awesome.

$$
\begin{align}
F(x,y)&=F_X(x)F_Y(y)\\
f(x,y)&=f_X(x)f_Y(y)
\end{align}
$$
</p>
<script>
MathJax = {
  tex: {
    inlineMath: [['$', '$'], ['\\(', '\\)']]
  }
};
</script>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
</body>
</html>

Open in browser: image

So, If we can translate inline math

Inline math latex:[f(x)=x^2+1] 

to

Inline math $f(x)=x^2+1$

and display math

[latex]
----
sqrt(4) = 2 \\
e^_{i\pi}+1=0
----

to

$$
sqrt(4) = 2 \\
e^_{i\pi}+1=0
$$

Then we can take math to asciidoc.