# LuaLaTex: Plantuml from file

I have a tex-document with some text and a folder with plantuml diagrams.

I need to import diagrams into a document.

I've tried to use plantuml package - https://ctan.org/pkg/plantuml?lang=en. It works pretty well for me. Yet, it works only when I paste uml text inside my document manually.

Is it possible to use that package to import files by path? Or, should I use another package? Or, maybe, should I use Lua for my task?

I'm quite new in TeX %)

My restrictions:

• path contains spaces, e.g. "../folder name/file name with spaces.md"

• plantuml file is a markdown file with injected uml syntax, e.g. (of course, dashes without spaces in original files)

  plantuml
@startuml
...
@enduml



Either include or import doesn't help me :/ Maybe, I do smth wrong with TeX.

You didn't supply a test file, but taking one from the manual...

You can get lua to take a file with the markup, add the latex environment saving to a temporary file and then input (using a temporary file just simplifies the catcode handling)

main document

\documentclass{scrartcl}
\usepackage{plantuml}
\def\pumlfile#1{%
\directlua{%
local f = assert(io.open("#1", "rb"))
f:close()
local f2 = io.open("#1" .. ".ltx","w")
f2:write("\string\\begin{plantuml}\string\n" ..  content .. "\string\\end{plantuml}")
f2:close()
}%
\input{"#1.ltx"}}

\begin{document}

\pumlfile{p1.txt}

\end{document}


p1.txt

@startuml
Alice -> Bob: test
@enduml


Thank you, David! https://tex.stackexchange.com/a/483873/185331

It works nice. I've modified it a bit

\usepackage{plantuml}

\def\pumlfile#1{%
\directlua{%
%texio.write_nl("Filename: \luatexluaescapestring{#1}")
%texio.write_nl("Filename: " .. \luastring{#1})

local srcname = \luastring{#1}
srcname = srcname:sub(2,-2)
% trick with quotes in filename

%texio.write_nl("srcname=[" .. srcname .. "]")

local f = assert(io.open(srcname, "rb"))
f:close()

tmpfile = "temp-plantuml.uml"
os.remove(tmpfile)

local f2 = io.open(tmpfile, "w")
f2:write("\string\\begin{plantuml}\string\n" ..  content .. "\string\\end{plantuml}")
f2:close()
}%
\input{"temp-plantuml.uml"}}


And use it this way


\pumlfile{"../workflow diagrams/02. Keys.Activation Request.md"}


As you see, I have spaces in my paths. And, it's unresloved trick -- if I have cyrillic in my UML then plantuml is unable to process diagrams. Yet, file encoding is UTF8 :/

• Hmm if you have a new question, please ask it. – JouleV Apr 9 at 10:21