Latex/tikz support

+3 votes
asked Apr 9, 2014 in Wanted features by plantuml (295,760 points)
edited May 5, 2014 by plantuml

Some users have asked for latex/tikz support.

So here is an beta version that has "-tlatex" flags in its command line.

https://dl.dropboxusercontent.com/u/13064071/plantuml.jar

We have choosen a simple diagram:

@startuml
class Subscriber {
  subscriberId
}
class AccumUsage {
  subscriberId
}
class IpSession {
  ipAddress
  specificData
  sapcOriginStateId
  apnId
}
Subscriber "1" --> "1..*" IpSession
Subscriber "1" --> "0..1" AccumUsage
@enduml


The goal of this test is to generate a tikz file like this :

https://www.writelatex.com/read/pgkkspzgzgpb

\documentclass{article}
\usepackage{tikz}
%
\begin{document}
\begin{tikzpicture}[yscale=-1]
\draw (131pt,29pt) rectangle (223pt,90.8359pt);
\node at (160pt,37.4531pt)[below right]{Subscriber};
\draw (132pt,61pt) -- (222pt,61pt);
\node at (137pt,65pt)[below right]{subscriberId};
\draw (132pt,82.8359pt) -- (222pt,82.8359pt);
\draw (31pt,212pt) rectangle (137pt,273.8359pt);
\node at (60pt,220.4531pt)[below right]{AccumUsage};
\draw (32pt,244pt) -- (136pt,244pt);
\node at (37pt,248pt)[below right]{subscriberId};
\draw (32pt,265.8359pt) -- (136pt,265.8359pt);
\draw (221pt,191pt) rectangle (318pt,294.3438pt);
\node at (254.95pt,199.4531pt)[below right]{IpSession};
\draw (222pt,223pt) -- (317pt,223pt);
\node at (227pt,227pt)[below right]{ipAddress};
\node at (227pt,240.8359pt)[below right]{specificData};
\node at (227pt,254.6719pt)[below right]{sapcOriginStateId};
\node at (227pt,268.5078pt)[below right]{apnId};
\draw (222pt,286.3438pt) -- (317pt,286.3438pt);
\draw (191.942pt,90.081pt) ..controls (205.204pt,115.893pt) and (224.952pt,154.325pt) .. (241.265pt,186.076pt);
\node at (191.0584pt,98.9168pt)[below right]{1};
\node at (230.3817pt,166.6703pt)[below right]{1..*};
\draw (162.058pt,90.081pt) ..controls (145.645pt,122.023pt) and (119.302pt,173.295pt) .. (101.824pt,207.31pt);
\node at (143.0082pt,98.7264pt)[below right]{1};
\node at (101.801pt,187.522pt)[below right]{0..1};
\end{tikzpicture}
\end{document}

 

Works is still in progress...
 

See also http://plantuml.sourceforge.net/latex.html

9 Answers

0 votes
answered Jun 25, 2014 by anonymous

If this is the place to post bug reports on the Latex/tikz generation, the following simple file (lets call it test.uml) causes a NullPointerException:

@startuml
class Foo
class Bar <|-- Foo
@enduml
 
I am using the following command line: java -jar plantuml.jar -tlatex test.uml. Generating other formates (e.g., PNG) works as expected.
 
I've uploaded the full traceback here: http://hastebin.com/otesifiyil
commented Jun 25, 2014 by plantuml (295,760 points)
It's the right place, thanks for the report.
We have solved this bug in the following beta:
https://dl.dropboxusercontent.com/u/13064071/plantuml.jar
Feel free to go on if you find any other issues (we've made almost no tests on the latex export).

Regards,
+1 vote
answered Apr 2, 2015 by Pierre.Sassoulas (200 points)
I don't know if it's working as intended but when there is special latex character in the plantuml code, the generated latex won't compile.

For example:

@startuml
title any_string_with_underscore
@enduml

It generate :

% generated by Plantuml 8021

(...)
\node at (0pt,0pt)[below right]{any_string_with_underscore};
(...)

So you get an error with pdflatex :

! Missing $ inserted.
<inserted text>
                $
l.6 \node at (0pt,0pt)[below right]{any_
                                        string_with_underscore};
?

If you add backslashs it works (any\_string\_with\_underscore)
commented Apr 2, 2015 by plantuml (295,760 points)
Thanks for the feedback, this is a bug.
There is a beta version here that fixes it:
https://dl.dropboxusercontent.com/u/13064071/plantuml.jar

By the way, we are in the middle of something. We'd like to use real guillemot instead of << and >> for rendering.

So with this beta, if you test:

@startuml
title any_string_with_underscore
actor foo << Foo >>
@enduml

You'll see that in the Latex code, we are now using \usepackage{aeguill} and the commands \guillemotleft \guillemotright
Any though about this?

Do not hesitate to post here if you find other issues with Latex : very few tests have been done.

Regards,
commented Apr 2, 2015 by Pierre.Sassoulas (200 points)
edited Apr 3, 2015 by Pierre.Sassoulas
The <<>> replacement looks fine to me, but I know what it is supposed to replace so maybe I'm prejudiced.

Another remark maybe : it would be possible to insert everything into a figure environnement and make the title "any_string_with_underscore" as the caption (maybe with an automatic label) ?

Like this :
\begin{figure}

\caption{\label{fig:plantuml-any_string_with_underscore} any\_string\_with\_underscore}
\end{figure}

I think that in most case you want to export to latex because you will use the diagram in your document and it will be inside a figure and the title of the diagram should be the caption.

 I think resizing the figure would be nice too because rigth now a figure can go way above the limit of the page. Edit : This is not simple at all to do in latex the text does not adapt well when you use scale in the tikz figure, and I don't think there is a simple solution to this.
+1 vote
answered May 14, 2017 by anonymous
Hi.

Extending a use case to another use case will generate a solid arrow instead of dashed arrow. My workaround: edit the generated LaTeX code manually by adding "dashed" inside the \draw[...].

Great work by the way. PlantUML really helps me.
+1 vote
answered Jan 9, 2018 by hhhannes (160 points)

Hey,

I cannot run 

plantuml -v -tlatex:nopreamble life-cycle.pum

on this simple diagram. Are you able to reproduce and fix?

The error message is shown below.

Thanks,

hhhannes

Diagram:

@startuml

digraph foo {

node [style=rounded]

node1 [shape=box]

node2 [fillcolor=yellow, style="rounded,filled", shape=diamond]

node3 [shape=record, label="{ a | b | c }"]

node1 -> node2 -> node3

}

@enduml

Error:

(0.000 - 245 Mo) 237 Mo - PlantUML Version 1.2018.00

(0.019 - 245 Mo) 237 Mo - GraphicsEnvironment.isHeadless() false

(1.868 - 245 Mo) 234 Mo - Setting current dir: .

(1.868 - 245 Mo) 234 Mo - Setting current dir: /Users/jo/dev/master/thesis/assets/plantuml

(1.869 - 245 Mo) 234 Mo - Using default charset

(1.874 - 245 Mo) 234 Mo - Setting current dir: /Users/jo/dev/master/thesis/assets/plantuml

(1.886 - 245 Mo) 233 Mo - Setting current dir: /Users/jo/dev/master/thesis/assets/plantuml

(1.887 - 245 Mo) 233 Mo - Reading file: assets/plantuml/life-cycle.puml

(2.203 - 245 Mo) 220 Mo - Creating file: /Users/jo/dev/master/thesis/assets/plantuml/life-cycle.latex

(2.207 - 245 Mo) 218 Mo - Starting Graphviz process [/usr/local/opt/graphviz/bin/dot, -Tlatex_no_preamble]

(2.207 - 245 Mo) 218 Mo - DotString size: 198

(2.238 - 245 Mo) 217 Mo - Ending process ok

(2.238 - 245 Mo) 217 Mo - Ending Graphviz process

Exception in thread "main" java.lang.UnsupportedOperationException

at net.sourceforge.plantuml.ugraphic.UGraphicUtils.writeImage(UGraphicUtils.java:80)

at net.sourceforge.plantuml.directdot.PSystemDot.exportDiagramNow(PSystemDot.java:89)

at net.sourceforge.plantuml.AbstractPSystem.exportDiagram(AbstractPSystem.java:134)

at net.sourceforge.plantuml.PSystemUtils.exportDiagramsDefault(PSystemUtils.java:129)

at net.sourceforge.plantuml.PSystemUtils.exportDiagrams(PSystemUtils.java:72)

at net.sourceforge.plantuml.SourceFileReader.getGeneratedImages(SourceFileReader.java:212)

at net.sourceforge.plantuml.Run.manageFileInternal(Run.java:421)

at net.sourceforge.plantuml.Run.processArgs(Run.java:333)

at net.sourceforge.plantuml.Run.manageAllFiles(Run.java:303)

at net.sourceforge.plantuml.Run.main(Run.java:163)
commented Jan 9, 2018 by plantuml (295,760 points)
Unfortunately, export to LaTeX works only with UML diagrams.
Your diagram is a GraphViz/Dot one.
Sorry about that!
0 votes
answered May 23, 2018 by anonymous
I think I found another bug for the "-tlatex" option. I have created a sequence diagram and some of the text field contain the special LaTeX character "%". This not automatically transformed into "\%".

When I do these changes manually, the *.latex file is build correctly into a PDF by the LaTeX environment.
commented May 23, 2018 by plantuml (295,760 points)
Thanks for the feedback.
This should be fixed in last beta http://beta.plantuml.net/plantuml.jar
Tell us if it's not working for you or if you find other bugs!
commented May 24, 2018 by anonymous
Hi!

Thanks for your quick reply!
I used PlantUML 1.2018.6
You're right. This error does not occur with the current PlantUML beta (1.2018.07beta3).

Thank you very much for your great work! Outstanding tool!
0 votes
answered Oct 17, 2018 by dando (140 points)

Hi and thank you for the great and powerful software!

I think I found a minor bug for the Latex export option. I created a class diagram with the following contents:

@startuml

"HDF5 data file" *-- RSSI

"HDF5 data file" *-- Pilot_Samples

"HDF5 data file" *-- FrameCompleteTime

Pilot_Samples .[#blue].> CSI : samps2csi()

Pilot_Samples .[#blue].> IQ : samps2csi()

class RSSI{

[Frame,User,BS antenna]

15026 x 9 x 96

}

class Pilot_Samples{

[Frame,BS antenna,Samples,I/Q]

15026 x 96 x 2016 x 2

}

class FrameCompleteTime{

256 x 2

}

class CSI{

[Frame,User,LTS1/2,BS ant,Subcarrier]

15026 x 9 x 2 x 96 x 52

}

class IQ{

[Frame,User,LTS1/2,BS ant,Samples]

15026 x 9 x 2 x 96 x 64

}

note "Samples = Samps per user * num of users\n2016 = 224 * 9\nnum of users = actual num + 1 for noise" as N1

Pilot_Samples .. N1

@enduml

The resulting diagram is correct, however the comment box is much wider than the one generated in the PNG image. You can see the difference on this screenshot: https://imgur.com/p6ceLMd

I generate the LaTeX file with

java -jar plantuml.jar -tlatex class.puml

By the way, is there an easy way to import the resulting file in a LaTeX document? So far I have had success by copying only the TikZ picture contents to a figure environment in the target document.

Thank you for your time and efforts!

commented Oct 17, 2018 by plantuml (295,760 points)
About font, it's a issue that is impossible to fix...
You can see http://forum.plantuml.net/6495/wrong-class-widths-after-latex-export
The only workaround is to play with a special setting:
skinparam tikzFont 1.2;4.0
Try to slightly change the value to see if it helps

About your other question, you may have a look at http://forum.plantuml.net/4192/please-provide-command-parameter-output-without-preamble
Is this what you are looking for ?
commented Oct 17, 2018 by dando (140 points)
Thank you very much for the fast and accurate response!

I will take a close look at the references and will see if I can tweak the parameters in order to get a properly-sized comment box. This is anyway a minor issue so the diagram is quite usable as-is currently.

The "-tlatex:nopreamble" option works perfectly. I actually found it a tad later after initially posting the question but decided to not edit it.

Thanks again for your time and efforts!! Keep up the great work! :)
+1 vote
answered Apr 24, 2019 by SieDa

Great work. A 'sourcename.puml' should be processed without the surrounding LaTeX controls to enable an input from sourcname.tex into the document.

\documentclass{article}
\usepackage{tikz}
%
\begin{document}
\begin{tikzpicture}[yscale=-1]

\input{sourcename}

\end{tikzpicture}
\end{document}

commented Apr 24, 2019 by plantuml (295,760 points)
Hello,
I'm not sure to understand the request.
Could you give more information ?
Thanks!
commented Feb 13, 2021 by Andreas
Not my request originally but I have the same opinion. The output generated by plantuml should only contain the part to be included in a document and not create a full latex document.
commented Feb 14, 2021 by plantuml (295,760 points)

You can use -tlatex:nopreamble to do so. Is this what you are looking for ?

commented Feb 15, 2021 by Andreas
Yes! I was stupid enough to miss that in the man page but it is there.

Thanks a lot and keep up the amazing work
0 votes
answered Jul 30, 2019 by anonymous
If you use the symbol "~" in a class diagram as you do it by the name of the destructor, then the symbol is at the top of the line and not in the middle.

For example:

@startuml
class Test{
+ ~Test()
}
@enduml
commented Aug 1, 2019 by plantuml (295,760 points)
I am not sure to understand your request. Is this a defect issue ?

The last example seems to work for us http://www.plantuml.com/plantuml/uml/SoWkIImgAStDuKhEIImkLWX9BIwfvj9Mg0CnD3IvQhaSKlDIWF80
commented Aug 5, 2019 by anonymous

The problem only occurs when you use the -tlatex flag. In the tikz file, the tilde symbol is generated with the command \~. However, in most fonts used by LaTeX, this symbol is not displayed correctly.

Replacing \~ with {\raise.35ex\hbox{$\scriptstyle\mathtt{\sim}$}} in the tikz file sloves the Problem for me, but I do not know if this works in all fonts and font sizes.

commented Aug 5, 2019 by plantuml (295,760 points)
Ok, we've made that change in last beta http://beta.plantuml.net/plantuml.jar

Is it working for you now ?

Let's see what other people would say :-)
commented Aug 5, 2019 by anonymous
Now it works fine.
Thanks a lot.
0 votes
answered Sep 11, 2023 by anonymous
Hey,

The following code produces a figure with very large spacing between the label and the label link

I am using
plantuml  1.2023.10
graphviz 7.1.0
pdfTeX 3.141592653-2.6-1.40.24 (TeX Live 2022/CVE-2023-32700 patched)
Compiled with libpng 1.6.37; using libpng 1.6.37
Compiled with zlib 1.2.13; using zlib 1.2.13
Compiled with xpdf version 4.04

The code:

@startuml
skinparam ActivityDiamondBackgroundColor yellow
start
#yellow :Read Arguments[[latex://subsec:impl:iis:argument_reading 5.1.1]];
if (Select Data Processing Service[[latex://subsec:impl:iis:argument_reading 5.1.1]]) then (Imperative Implementation)
    partition Imperative Data Processing Service[[latex://sec:impl:imp 5.2]] {
        :Read Inputs[[latex://subsec:impl:imp:init 5.2.1]];
        :Setup Processing System[[latex://subsec:impl:imp:init 5.2.1]];
        :Execute Data Processing Service[[latex://subsec:impl:imp:process 5.2.2]];
    }
else (Declarative Implementation)
    partition Declarative Data Processing Service[[latex://sec:impl:dec 5.3]] {
        :Read Inputs[[latex://subsec:impl:dec:init 5.3.1]];
        :Assemble Processing Pipeline[[latex://subsec:impl:dec:init 5.3.1]];
        :Execute Data Processing Service[[latex://subsec:impl:dec:process 5.3.2]];
    }
endif
#yellow :Get Benchmark Readings[[latex://subsec:impl:iis:bench_results_handling 5.1.2]];
#yellow :Return Benchmark Readings[[latex://subsec:impl:iis:bench_results_handling 5.1.2]];
end
@enduml
...