I want to create diagrams. Preferable in LaTeX. Normally, I use the PlantUML language.
4 Answers
It is possible to use the PlantUML language direcly inside LaTeX using the plantuml package.
Here is a minimal example:
\documentclass{scrartcl}
\usepackage{plantuml}
\begin{document}
\begin{plantuml}
@startuml
Alice -> Bob: Hello
Alice <- Bob: Hi!
@enduml
\end{plantuml}
\end{document}
For building LaTeX with PlantUML the PLANTUML_JAR
environment variable has to be set and Java must be installed.
To build this document, run lualatex --shell-escape documentname
The result should look like this:
A more detailed example can be found here: https://koppor.github.io/plantuml/
Prerequisites
# to get tikz, install pgf
tlmgr install pgf
tlmgr install koma-script
tlmgr install xkeyval
tlmgr install adjustbox
tlmgr install collectbox
tlmgr install luacode
tlmgr install luatexbase
-
5Unfortunately this package does not work with
pdflatex
as of June 2020. Commented Jul 4, 2020 at 11:29 -
1This is a really useful post, I hope you don't mind me adding to it. I went through dependency hell and don't want people to give up. Commented Apr 22, 2021 at 3:33
I use the website https://www.planttext.com/ to export to/download as SVG (which btw includes the plantuml code as XML comment) and after that save as PDF with inkscape. This can be used with \includegraphics
You could also write the plantuml diagrams localy and convert them via plantuml -teps your-file
to lossless eps
files. These can be directly included in latex via the \includegraphics
command.
This way you do not have to go the way via inkscape.
-
-
No the with plantuml latex format generated tikz pictures have some spacing/padding/marigin issues and do not support all formatting.– OhmenCommented Mar 8, 2020 at 9:43
-
I have worked out a solution that works with pdflatex
as well. It produces vector graphics. I tested it with Ubuntu Linux 20.04 LTS and TeX Live. Should work with macOS as well.
My code requires, that you have installed:
- PlantUML (thus, also Java)
- Inkscape (converting svg to pdf)
Due to calling external commands, you have to use the -shell-escape
option to compile:
pdflatex -shell-escape my-file.tex
Depending of how you installed PlantUML, you might have to call it like this:
\immediate\write18{java -jar /home/NAME/Downloads/plantuml.jar -tsvg #1.txt}
... instead of ...
\immediate\write18{plantuml -tsvg #1.txt}
Here is the full code as minimal example:
\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx} % enables us to use graphics
\usepackage{fancyvrb} % enables us to write to disk
\usepackage{float} % enables us to use [H] for figures
% Define an verbatim environment for PlantUML:
\newenvironment{plantuml}[1]{\VerbatimOut{#1.txt}}{\endVerbatimOut}
% Process a PlantUML code:
\newcommand{\process}[3]{%
% Call PlantUML to produce a svg vector graphcis:
\immediate\write18{plantuml -tsvg #1.txt}
% Call Inkscape to convert the svg to a pdf (pdflatex cannot use svg):
\immediate\write18{inkscape #1.svg --export-filename=#1.pdf}
% Include the pdf:
\begin{figure}[H]
\includegraphics[width=#2]{#1.pdf}
\caption{#3}
\end{figure}
% Remove all intermediate files:
\immediate\write18{rm #1.txt #1.svg #1.pdf}
}
\begin{document}
% Note: timeline1 gets used as filename.
% You must re-use this name for the
% corresponding \process command!
\begin{plantuml}{timeline1}
@startgantt
[Prototype design] lasts 15 days
[Test prototype] lasts 10 days
@endgantt
\end{plantuml}
\process{timeline1}{0.8\textwidth}{The proposed timeline.}
\begin{plantuml}{activity1}
@startuml
:Hello world;
:This is on defined on
several **lines**;
@enduml
\end{plantuml}
\process{activity1}{5cm}{An activity diagram.}
\end{document}
I hope this is helpful to someone.
-
1It's nice that the PlantUML source goes into LaTeX. Configuring the environment properly is always complex. I have configured PlantUML on Windows 10 to generate PDF
-tpdf
following plantuml.com/pdf and it doesn't require inkscape. Your solution could work with that, too. Commented Jul 28, 2020 at 15:37
uml
anspst-uml
which might help (I don't about plantUML). Both rely onpstricks
. Also ametauml
package, which relies onmetapost
.-tlatex
with the command line, orformat="latex"
with the ANT task.