stathissideris / ditaa

ditaa is a small command-line utility that can convert diagrams drawn using ascii art ('drawings' that contain characters that resemble lines like | / - ), into proper bitmap graphics.
GNU Lesser General Public License v3.0
924 stars 87 forks source link

LaTeX math mode support #39

Open dakusui opened 5 years ago

dakusui commented 5 years ago

It will be very useful if we can use LaTeX's math mode inside ditaa's ascii art. That is, if we have a following ascii art,


$Box_1$                    $Box^2$
+---------------------+    +------+   /---------\
|$\sum_{i=0}^{n}x^i$  |    |$cBLU$|   |         |
|                     +--->|cRED  +-=-+cGRE$C_k$|
|{io}                 |    |cXYZ  |   |{o}      |
+----------+----------+    +---+--+   \---------/
           |                   |
           |                   :
           |                   V
           |           +-----------------+
           +---------->|$A_i$ hello $B^i$|
                       +-----------------+

$Q_u^i$, $C_k$, $B_r^{own}$, $F_{ox}$ jumps

over a lazy $d\cdot\frac{o}{g}$.

$\forall x \in X, \quad \exists y \leq \epsilon$

$\sin A \cos B =$

    $ \frac{1}{2}\left[ \sin(A-B)+\sin(A+B) \right]$

$\frac{d}{dx}\left( \int_{0}^{x} f(u)\,du\right)=f(x).$

 $v \sim \mathcal{N} (m,\sigma^2)$

I would see it rendered like this.

art-latexmath-1

I have already implemented this feature in my forked repository and am going to open a pull request soon. Please kindly consider merging it when it's opened.

stathissideris commented 5 years ago

This is amazing, I would gladly merge it when it's ready!

stathissideris commented 5 years ago

Do you think it would work with SVG output as well?

dakusui commented 5 years ago

It's a great point. It will need to be a limitation for the time being. My enhancement relies on jlatexmath for LaTeX math rendering and it does not support .svg output apparently. There seems to be other libraries that can output .svg but not in Java (or JVM based languages), which means we'll need to figure out how to integrate such libraries in ditaa's 'uber' jar.

I would suggest supporting this feature for only .png in this pull request rather than making the change too big.

dakusui commented 5 years ago

I have opened a pull request for this feature to have a discussion about its detail. Please have a look at it and leave your thoughts.

paulvi commented 5 years ago

I wonder if it is possible to make this as addon or option? (if not merging directly because of some limitations)

paulvi commented 5 years ago

https://github.com/dakusui/ditaa/tree/issue-39-latex-math-support

dakusui commented 5 years ago

@paulvi , what do you mean by "option"? My current plan is to make it a feature enabled by the "--latex-math" option otherwise defaulting to original behavior.

Making it an addon would be quite a bit challenging, actually.

Actually, I came to think that it might be better to go back to original code base and re-work this pull request since unless otherwise it's difficult to review the enhancement. And if you want to try this feature, you can simply clone the repo and build it using leiningen (lein uberjar). The artifact should work fine. (If not, please just let me know. I will fix the bug.)

paulvi commented 5 years ago

OK, so if thi Latext support is optional that is only enabled when "--latex-math" option is passed, than I would like to see it merged as it is. As will / should not affect users who are not aware about it

dakusui commented 4 years ago

Hi, after long period of busy days, I could finally find a time to work on this. I have reworked the feature from the fresh branch and created a pull request #54 . Please kindly have a review on it.