TeX - LaTeX Asked by Columnist on August 12, 2021
I want to create diagrams. Preferable in LaTeX. Normally, I use the PlantUML language.
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/
# 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
Correct answer by Bennik2000 on August 12, 2021
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
Answered by HolgerJeromin on August 12, 2021
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.
Answered by Ohmen on August 12, 2021
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:
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:
immediatewrite18{java -jar /home/NAME/Downloads/plantuml.jar -tsvg #1.txt}
... instead of ...
immediatewrite18{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:
immediatewrite18{plantuml -tsvg #1.txt}
% Call Inkscape to convert the svg to a pdf (pdflatex cannot use svg):
immediatewrite18{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:
immediatewrite18{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.8textwidth}{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.
Answered by SommerEngineering on August 12, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP