summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex/plantuml
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2018-03-08 22:56:58 +0000
committerKarl Berry <karl@freefriends.org>2018-03-08 22:56:58 +0000
commitda48a65f7e454f173c138f38ac4cc5661f4c1cea (patch)
tree20cd2f03502c0781ce36ebb97ea7698820731184 /Master/texmf-dist/tex/lualatex/plantuml
parente07639350551b80338d2ccb887fe96d1a2a0691f (diff)
plantuml (8mar18)
git-svn-id: svn://tug.org/texlive/trunk@46892 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/lualatex/plantuml')
-rw-r--r--Master/texmf-dist/tex/lualatex/plantuml/plantuml.lua48
-rw-r--r--Master/texmf-dist/tex/lualatex/plantuml/plantuml.sty90
2 files changed, 138 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/lualatex/plantuml/plantuml.lua b/Master/texmf-dist/tex/lualatex/plantuml/plantuml.lua
new file mode 100644
index 00000000000..d94e93b5b44
--- /dev/null
+++ b/Master/texmf-dist/tex/lualatex/plantuml/plantuml.lua
@@ -0,0 +1,48 @@
+-- SPDX-License-Identifier: LPPL-1.3c+
+
+require "lfs"
+
+-- @param mode directly passed to PlantUML. Recommended: png, svg, pdf (requires Apache Batik to convert svg to pdf)
+function convertPlantUmlToTikz(jobname, mode)
+ local plantUmlSourceFilename = jobname .. "-plantuml.txt"
+ local plantUmlTargetFilename = jobname .. "-plantuml." .. mode
+
+ -- delete generated file to ensure they are really recreated
+ os.remove(plantUmlTargetFilename)
+
+ if not (lfs.attributes(plantUmlSourceFilename)) then
+ texio.write_nl("Source " .. plantUmlSourceFilename .. " does not exist.")
+ return
+ end
+
+ local plantUmlJar = os.getenv("PLANTUML_JAR")
+ if not plantUmlJar then
+ texio.write_nl("Environment variable PLANTUML_JAR not set.")
+ return
+ end
+
+ texio.write("Executing PlantUML... ")
+ local cmd = "java -jar " .. plantUmlJar .. " -t"
+ if (mode == "latex") then
+ cmd = cmd .. "latex:nopreamble"
+ else
+ cmd = cmd .. mode
+ end
+ cmd = cmd .. " " .. plantUmlSourceFilename
+ texio.write_nl(cmd)
+ local handle,error = io.popen(cmd)
+ if not handle then
+ texio.write_nl("Error during execution of PlantUML.")
+ texio.write_nl(error)
+ return
+ end
+ io.close(handle)
+
+ if not (lfs.attributes(plantUmlTargetFilename)) then
+ texio.write_nl("PlantUML did not generate anything.")
+ handle = io.open(plantUmlTargetFilename, "w")
+ handle:write("Error during latex code generation")
+ io.close(handle)
+ return
+ end
+end
diff --git a/Master/texmf-dist/tex/lualatex/plantuml/plantuml.sty b/Master/texmf-dist/tex/lualatex/plantuml/plantuml.sty
new file mode 100644
index 00000000000..3f16671ea06
--- /dev/null
+++ b/Master/texmf-dist/tex/lualatex/plantuml/plantuml.sty
@@ -0,0 +1,90 @@
+%% Copyright (C) 2018 Oliver Kopp, https://github.com/koppor
+%%
+%% SPDX-License-Identifier: LPPL-1.3c+
+\NeedsTeXFormat{LaTeX2e}\relax
+\ProvidesPackage{plantuml}
+ [2018/03/08 v0.1.0
+ Embed PlantUML diagrams in latex documents.]
+
+% Required by PlantUML LaTeX output
+\RequirePackage{tikz}
+\RequirePackage{aeguill}
+
+% Enable checking for active -shell-escape
+% Source: https://tex.stackexchange.com/a/88620/9075
+\RequirePackage{pdftexcmds}
+
+% Prepare writing contents of a self-defined environment to a file
+% Source: https://tex.stackexchange.com/a/130298/9075
+\RequirePackage{fancyvrb}
+
+\RequirePackage{l3keys2e}
+\RequirePackage{xparse}
+
+\RequirePackage{ifthen}
+
+\RequirePackage{adjustbox}
+
+\ExplSyntaxOn
+\keys_define:nn { plantuml } {
+ output .choices:nn = {
+ {latex, png, svg}
+ { \tl_gset:NV \l_plantuml_mode \l_keys_choice_tl }
+ },
+ output .initial:n = latex
+}
+\ProcessKeysOptions { plantuml }
+\ExplSyntaxOff
+
+%hint from https://tex.stackexchange.com/a/86355/9075
+\makeatletter
+\def\maxwidth#1{\ifdim\Gin@nat@width>#1 #1\else\Gin@nat@width\fi}
+\makeatother
+
+\ifluatex
+ \ExplSyntaxOn
+ \let\PlantUmlMode\l_plantuml_mode
+ \ExplSyntaxOff
+ \RequirePackage{luacode}
+ \makeatletter
+ \ifcase\pdf@shellescape
+ \message{No shell escape. PlantUML cannot be called. Start lualatex with -shell-escape.}
+ \newenvironment{plantuml}{%
+ No shell escape. PlantUML cannot be called. Start lualatex with -shell-escape.
+ }{}
+ \or
+ \directlua{
+ local plantUmlJar = os.getenv("PLANTUML_JAR")
+ if not plantUmlJar then
+ texio.write_nl("Environment variable PLANTUML_JAR not set.")
+ end
+ }
+ \NewDocumentEnvironment{plantuml}{}{%
+ \VerbatimOut{\jobname-plantuml.txt}}
+ {%
+ \endVerbatimOut
+ \directlua{
+ local jobname=\luastring{\jobname}
+ local plantUmlMode=\luastring{\PlantUmlMode}
+ require("plantuml.lua")
+ convertPlantUmlToTikz(jobname, plantUmlMode)
+ }
+ \ifthenelse{\equal{\PlantUmlMode}{latex}}{
+ \begin{adjustbox}{max width=\linewidth}
+ \input{\jobname-plantuml.latex}
+ \end{adjustbox}
+ }{
+ \includegraphics[width=\maxwidth{\textwidth}]{\jobname-plantuml.\PlantUmlMode}
+ }
+ }
+ \or
+ \message{Restricted shell escape. PlantUML cannot be called. Start lualatex with -shell-escape.}
+ \newenvironment{plantuml}{%
+ Restricted shell escape. PlantUML cannot be called. Start lualatex with -shell-escape.
+ }{}
+ \fi
+ \makeatother
+\else
+ \typeout{*** plantuml only works with lualatex ***}
+\fi
+