I would like to make Diagrams in AsciiArt style.

I've found Ditaa tool very usefull. I was happy to find, there is Eps output addoon for it.

What the easiest, but clear and elegant way (following KISS principle) do you suggest to

  • embed ditaa diagrams into Tex (LaTeX) documents?

Makefile with eps->pdf conversion and than including such pdf. Keep asciiart diagrams separated or integrate it somehow with Tex/LaTex (for asciidoc, I've found it easy).

I know it's more poweruser question, but related:

  • Unfortunatelly, I can figure out how to make it working with newest ditaa 0.9 (it's distributed with ditaa 0.6b)

I am new to group, so please forgive (kindly remind, I can delete it) if question is not appropriate.

I am Linux programmer, so command line, make, sed, awk and other tool can be combined.

  • 1
    Tikz can do a lot of great diagrams, too, natively! – ℝaphink Aug 8 '11 at 13:16
  • 1
    Simplest way (KISS) include the image as .png or .jpg with \includegraphics. – Yiannis Lazarides Aug 8 '11 at 14:44
  • So, I would like to {\includegraphics}. But to have ditaa diagram embedded in TeX document, so while compiling it, picture is vectorized externally and resulting vector (DitaaEps) Eps version is included. – Grzegorz Wierzowiecki Aug 8 '11 at 21:28

If you're interested in merely adding ascii-art diagrams to your document, you can dump the ascii-art content in the verbatim environment:

​\begin{document}% Taken from http://ditaa.sourceforge.net/
    +--------+   +-------+    +-------+
    |        | --+ ditaa +--> |       |
    |  Text  |   +-------+    |diagram|
    |Document|   |!magic!|    |       |
    |     {d}|   |       |    |       |
    +---+----+   +-------+    +-------+
        :                         ^
        |       Lots of work      |

The verbatim environment typesets its contents as-is using the \ttfamily font, keeping the alignment (whitespace).

Example of ditaa ascii-art code

If you're interested in a converted graphic/image (a ditaa-processed version of your ascii-art), then importing a PNG (or JPG/BMP) from your ditaa outpout would be easiest. This, however, comes with a loss of quality in the output. If the EPS add-on is readily available, then using it to produce EPS images (or even converted to PDF) would achieve the highest quality. Here's a graphic from the website illustrating the difference in quality when using rasterized vs vector graphics:

Difference in rasterized and vector graphics in ditaa output

Finally, TikZ/PGF and PStricks both provide a bounty of native drawing capabilities within (La)TeX. The TikZ/PGF documentation is filled with examples, as is many of the package documentations associated with PStricks. They each come with their own set of macros/commands that allow for drawing diagrams similar to those done by ditaa.

The advantage of using native packages as opposed to some external application (like ditaa) is that it provides the capability to alter an "image" within your (La)TeX code rather than using an external application as a stepping stone. Moreover, with (La)TeX being platform independent, such advantages of native programming add even more value.

| improve this answer | |
  • I would like to use vector version of DitaaEps, but with Ditaa 0.9. – Grzegorz Wierzowiecki Aug 8 '11 at 21:23

If you are an emacs user, you may consider using org-mode extension: http://orgmode.org/

I have been using org-mode for some to prepare documents and presentations in LaTeX/Beamer. You can use org-mode to generate both LaTeX files and html files.

To incorporate code from other languages (e.g. Python, Ruby, C++, ditaa, tikz, etc.), you will need to use the babel functionality: http://orgmode.org/worg/org-contrib/babel/
In particular, here, is an org-mode ditaa example from the babel extension.

| improve this answer | |
  • I am Vim user - about org-mode, I've read on webpage. But thanks :). – Grzegorz Wierzowiecki Aug 8 '11 at 21:18
  • 1
    There is, from time to time, some talk on the org-mode mailing list about making a Vim clone. I believe some users have started such a project, for example the VimOrganizer, just FYI. – cm2 Aug 8 '11 at 22:30
  • Thanks man. :). Even it's out of question , cause it doesn not solve vector rendering problem, it's interesting as editor tool :). – Grzegorz Wierzowiecki Aug 10 '11 at 18:33

I wanted exactly the feature asked by this question. I want to embed a ditaa asciiart in my latex files and at the same time embed an image rendered by ditaa by only doing pdflatex once.

Since I realized that there is no such a thing by this post, I have created it and am sharing it here. https://gist.github.com/dakusui/160dba81fb7dc53d24b3596ef21bd979

IMPORTANT: You need to compile it with --enable-write18 option. IMPORTANT: You need to install ditaa command beforehand. Please try this and I hope you can enjoy it.

% Preamble

% Packages

\graphicspath{ {\ImageResourcePath} }

  \immediate\write18{ditaa "\ditaafile" "\ditaadir/\ditaastem.png"}

    This is a ditaa diagramm example.
    \begin{ditaa}{ditaa caption example}{ditaaexample}
      +--------+   +-------+    +-------+
      |        | --+ ditaa +--> |       |
      |  Text  |   +-------+    |diagram|
      |Document|   |!magic!|    |       |
      |     {d}|   |       |    |       |
      +---+----+   +-------+    +-------+
          :                         ^
          |       Lots of work      |
| improve this answer | |
  • Welcome to TeX.SE. – CampanIgnis Sep 26 '18 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.