1

I want to include an external .puml file and have the diagram generated.

My current approach does not work and I do not understand why.

Following I pasted what I think is relevant from my current approach. If you need to see more of my setup to provide an answer, please ask in a comment.

Works (contain puml content in tex file)

Excerpt of file-containing-puml.tex

...

\begin{plantuml}
@startuml

Class01 "1" *-- "many" Class02 : contains

Class03 o-- Class04 : aggregation

Class05 --> "1" Class06

@enduml
\end{plantuml}

...

Result:

generated diagram

Does not work (input external puml file)

Excerpt of file-referencing-puml.tex

...

\begin{plantuml}
\input{plantuml-file.puml}
\end{plantuml}

...

Full content of plantuml-file.puml

@startuml

Class01 "1" *-- "many" Class02 : contains

Class03 o-- Class04 : aggregation

Class05 --> "1" Class06

@enduml

Result:

enter image description here

0

1 Answer 1

2

There is an open issue concerning external files: https://github.com/koppor/plantuml/issues/3. Until that is implemented, you can use this dirty hack, which provides the command \includeplantuml

\documentclass{scrartcl}
\usepackage{plantuml}

\NewDocumentCommand{\includeplantuml}{m}{%
  \directlua{
    local jobname=\luastring{#1}
      local plantUmlMode=\luastring{\PlantUmlMode}
      local plantUmlSourceFilename = jobname .. "-plantuml.txt"
          infile = io.open(jobname, "r")
          instr = infile:read("*a")
          infile:close()
          outfile = io.open(plantUmlSourceFilename, "w")
          outfile:write(instr)
          outfile:close()
      require("plantuml.lua")
      convertPlantUmlToTikz(jobname, plantUmlMode)
    }
  \ifthenelse{\equal{\PlantUmlMode}{latex}}{
    \begin{adjustbox}{max width=\linewidth}
      \input{#1-plantuml.latex}
    \end{adjustbox}
  }{
    \includegraphics[width=\maxwidth{\textwidth}]{#1-plantuml.\PlantUmlMode}
  }
}


\begin{document}
\includeplantuml{plantuml-file.puml}
\end{document}

Not the answer you're looking for? Browse other questions tagged .