我想要包含一个外部.puml
文件并生成图表。
我当前的方法不起作用,我不明白为什么。
下面我粘贴了我认为与我当前方法相关的内容。如果您需要查看更多我的设置以提供答案,请在评论中提问。
作品(tex文件中含有puml内容)
摘录file-containing-puml.tex
...
\begin{plantuml}
@startuml
Class01 "1" *-- "many" Class02 : contains
Class03 o-- Class04 : aggregation
Class05 --> "1" Class06
@enduml
\end{plantuml}
...
结果:
不起作用(输入外部 puml 文件)
摘录file-referencing-puml.tex
...
\begin{plantuml}
\input{plantuml-file.puml}
\end{plantuml}
...
完整内容plantuml-file.puml
@startuml
Class01 "1" *-- "many" Class02 : contains
Class03 o-- Class04 : aggregation
Class05 --> "1" Class06
@enduml
结果:
答案1
存在一个有关外部文件的未解决的问题:https://github.com/koppor/plantuml/issues/3。在此之前,您可以使用这个肮脏的黑客,它提供了命令\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}