summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/plantuml/plantuml.sty
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/luatex/latex/plantuml/plantuml.sty
Initial commit
Diffstat (limited to 'macros/luatex/latex/plantuml/plantuml.sty')
-rw-r--r--macros/luatex/latex/plantuml/plantuml.sty101
1 files changed, 101 insertions, 0 deletions
diff --git a/macros/luatex/latex/plantuml/plantuml.sty b/macros/luatex/latex/plantuml/plantuml.sty
new file mode 100644
index 0000000000..d6777ed44e
--- /dev/null
+++ b/macros/luatex/latex/plantuml/plantuml.sty
@@ -0,0 +1,101 @@
+%% Copyright (C) 2018 Oliver Kopp, https://github.com/koppor
+%%
+%% SPDX-License-Identifier: LPPL-1.3c+
+\NeedsTeXFormat{LaTeX2e}\relax
+\ProvidesPackage{plantuml}
+ [2018/03/22 v0.2.2
+ Embed PlantUML diagrams in latex documents.]
+
+% Required by PlantUML LaTeX output
+\RequirePackage{tikz}
+
+% 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
+
+\ExplSyntaxOn
+\let\PlantUmlMode\l_plantuml_mode
+\ExplSyntaxOff
+
+\newcounter{PlantUmlFigureNumber}
+
+\ifluatex
+ \RequirePackage{luacode}
+\else
+ \RequirePackage[usefamily=bash]{pythontex}
+\fi
+
+\makeatletter
+\ifcase\pdf@shellescape
+ \message{No shell escape. PlantUML cannot be called. Start pdflatex/lualatex with -shell-escape.}
+ \newenvironment{plantuml}{%
+ No shell escape. PlantUML cannot be called. Start pdflatex/lualatex with -shell-escape.
+ }{}
+\or
+ \ifluatex
+ \directlua{
+ local plantUmlJar = os.getenv("PLANTUML_JAR")
+ if not plantUmlJar then
+ texio.write_nl("Environment variable PLANTUML_JAR not set.")
+ end
+ }
+ \fi
+ \NewDocumentEnvironment{plantuml}{}{%
+ \VerbatimOut{\jobname-plantuml.txt}}
+ {%
+ \endVerbatimOut
+ \ifluatex
+ \directlua{
+ local jobname=\luastring{\jobname}
+ local plantUmlMode=\luastring{\PlantUmlMode}
+ require("plantuml.lua")
+ convertPlantUmlToTikz(jobname, plantUmlMode)
+ }
+ \else
+ \stepcounter{PlantUmlFigureNumber}
+ %TODO: Execute pyhton here
+ \typeout{*** plantuml only works with lualatex ***}
+ \fi
+ \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 pdflatex/lualatex with -shell-escape.}
+ \newenvironment{plantuml}{%
+ Restricted shell escape. PlantUML cannot be called. Start pdflatex/lualatex with -shell-escape.
+ }{}
+\fi
+\makeatother
+