[Tex/LaTex] Ditaa diagrams in TeX (LaTeX) document

diagramsembeddinggraphicstools

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.

Best Answer

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

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

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.