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

Implement LaTeX math support (WIP; Please do not merge this pull request yet) #42

Closed dakusui closed 5 years ago

dakusui commented 5 years ago

This is a pull request that offers an implementation of Issue-#39 (LaTeX math mode support) NOTE: Please do not look into this pull request anymore. Refer to this one for review. NOTE: This pull request is opened for review and discussions. Another pull request will be created when it becomes necessary.

README

Following is a documentation about this feature. This will appear in README.md after discussions are concluded.

Usage and syntax

Command line

(snip)

 -e,--encoding <ENCODING>       The encoding of the input file.
 -h,--html                      In this case the input is an HTML file.
                                The contents of the <pre
                                class="textdiagram"> tags are rendered as
                                diagrams and saved in the images directory
                                and a new HTML file is produced with the
                                appropriate <img> tags.
    --help                      Prints usage help.
-L,--latex-math                 Enable LaTeX math mode.

(snip)

Syntax

(snip)

LaTeX mode.

If you place LaTeX formulae inside 2 $s, it will be rendered using jlatexmath. That is, if you have a following input files.


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

$|Set| = o-*-Freunde-*-nicht=*=diese-=-*- * töne$

o Quick brown fox jumps over
* a lazy dog.

$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)$

This will be rendered as follows.

art-latexmath-1

Limitations

This feature is only available when you are generating .png files.

Discussions

stathissideris commented 5 years ago
  1. We can continue work with this PR, new commits to your branch will be included, no need for a separate PR
  2. I would like to keep backwards compatibility for the syntax, so if this feature introduces new semantics, it would need to be disabled by default and we should have a command-line option to enable it. Having it enabled by default would not work because some people use ditaa in an automated context and it may be hard for them to go and fix all invocations (and also it will create workload for them because they would have to check that everything renders the same way as before).
  3. We would also need some documentation to demonstrate this great feature too!
dakusui commented 5 years ago
  1. Thank you for that.
  2. Understood. I'll try to implement such an option which defaults to keep compatible behaviour.
  3. I've added an action item for that and the section "LaTeX mode" in the description will be the documentation and it should be integrated in "README.md" of ditaa in this pull request. Please feel free to edit it for improvement and give me feedbacks.
dakusui commented 5 years ago

@stathissideris , I tried hard to fix the code formatting issue, but I found it's quite a bit painful. Maybe we should reformat the entire project first and resume working on this feature if it's hard to review even if we use "Ignore white space changes" feature of GitHub. Can you please provide a code formatting style for some IDE such as Eclipse or IntelliJ? Or any style guideline if you have?

stathissideris commented 5 years ago

I have stopped working with Java for many years, so I don't have a preferred style. Are you using the Intellij defaults?

dakusui commented 5 years ago

I can use IntelliJ's default, but the one I am using daily basis is the following one which has 2 characters for indentation to save horizontal space, no tabs to be portable, etc.

https://github.com/dakusui/jcunit/tree/0.8.x-develop/src/site/resources/style

stathissideris commented 5 years ago

2 characters and spaces sounds like a reasonable default to me. Could you please send me a new PR on the current master that applies that to the whole project? Then you can git rebase this PR on the new master and continue work. Thanks!

dakusui commented 5 years ago

Understood, I have opened this pull request #43 for it.

dakusui commented 5 years ago

I've created another branch that contains this branch's content and pull request which is directed from it to a code formatted branch. The diff is available here. I think this is reviewable and we should create a new pull request to be merged from it eventually.

dakusui commented 5 years ago

Please do not look into this pull request anymore. Refer to this one for review.

dakusui commented 5 years ago

@stathissideris I have invited you to my forked repository as a collaborator for the review's sake. Please find an email from github or let me know to send it to you.