koppor / plantuml

A LuaLaTeX package for PlantUML in LaTeX
https://koppor.github.io/plantuml/
LaTeX Project Public License v1.3c
56 stars 11 forks source link

Support rendering from file #3

Open koppor opened 6 years ago

koppor commented 6 years ago

See minted and listings for an inspiration

vivi90 commented 2 years ago

Here is an dirty hack from StackExchange:

\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}

But it doen't work for me..

\includeplantuml{abbildungen/uml/ann-general-model-architecture.puml}

produces:

! LaTeX Error: File `abbildungen/uml/ann-general-model-architecture.puml-plantuml.latex' not found.

Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: latex)

Enter file name: 
inhalt/hauptteil.tex:177: Emergency stop.
<read *> 

l.177 .../uml/ann-general-model-architecture.puml}
                                                  ^^M
inhalt/hauptteil.tex:177:  ==> Fatal error occurred, no output PDF file produced!
Transcript written on thesis.log.
...
Latexmk: Missing input file 'abbildungen/uml/ann-general-model-architecture.puml-plantuml.latex' (or dependence on it) from following:
  '! LaTeX Error: File `abbildungen/uml/ann-general-model-architecture.puml-plantuml.latex' not found.'
...

Seems like this hack doen't work with PlantUML files in subdirectories. 🤔

EDIT: Sorry, it was my fault. Used the wrong compiler settings. 🤣 So with this compiler settings it not works now! 🎉

{
      "command": "latexmk",
      "args": [
        "-shell-escape",
        "-synctex=1",
        "-interaction=nonstopmode",
        "-file-line-error",
        "-lualatex",
        "-outdir=%OUTDIR%",
        "%DOC%"
      ]
}