-
Notifications
You must be signed in to change notification settings - Fork 0
/
marmermaidtex.dtx
272 lines (250 loc) · 7.97 KB
/
marmermaidtex.dtx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
% \iffalse meta-comment
%
% Copyright (C) 2022 by Markus Pabst
% -------------------------------------------------------
%
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
% http://www.latex-project.org/lppl.txt
%
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{marmermaidtex.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[2005/12/01]
%<package>\ProvidesPackage{skeleton}
%<*package>
[2022-01-28 v0.3 .dtx marmermaidtex file]
%</package>
%
%<*driver>
\documentclass[a4paper]{ltxdoc}
\usepackage{marmermaidtex}[2022-01-26]
\usepackage{listings,xcolor}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
\DocInput{marmermaidtex.dtx}
\PrintChanges
\PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{0}
%
% \CharacterTable
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
% Digits \0\1\2\3\4\5\6\7\8\9
% Exclamation \! Double quote \" Hash (number) \#
% Dollar \$ Percent \% Ampersand \&
% Acute accent \' Left paren \( Right paren \)
% Asterisk \* Plus \+ Comma \,
% Minus \- Point \. Solidus \/
% Colon \: Semicolon \; Less than \<
% Equals \= Greater than \> Question mark \?
% Commercial at \@ Left bracket \[ Backslash \\
% Right bracket \] Circumflex \^ Underscore \_
% Grave accent \` Left brace \{ Vertical bar \|
% Right brace \} Tilde \~}
%
%
%\changes{v0.1}{2022-01-25}{Initial version}
%\changes{v0.2}{2022-01-26}{Fix for xelatex}
%\changes{v0.3}{2022-01-28}{Add package options: {\itshape noOverwrite} and {\itshape noWarningOverwrite}}
% \def\vbopt#1{\noindent\llap{\scriptsize{#1}\enspace}\ignorespaces}
% \def\vbskip{\vskip.5em\noindent}
%\lstnewenvironment{command}{%
%\lstset{columns=flexible,frame=single,backgroundcolor=\color{blue!20},%
%xleftmargin=\fboxsep,xrightmargin=\fboxsep,escapeinside=`',gobble=1}}{}
%\lstnewenvironment{example}{%
%\lstset{basicstyle=\footnotesize\ttfamily,columns=flexible,frame=single,%
%backgroundcolor=\color{yellow!20},xleftmargin=\fboxsep,%
%xrightmargin=\fboxsep,gobble=1}}{}
%
% \GetFileInfo{marmermaidtex.dtx}
%
% \DoNotIndex{\newcommand,\newenvironment}
%
% \title{The \textsf{marmermaidtex} package}
% \author{Markus Pabst} \date{\fileversion\ (\filedate)}
% \maketitle
%\begin{abstract}\noindent
%\begin{quote}
%"Mermaid is a Javascript based diagramming and charting tool that uses Markdown-inspired text definitions and a renderer to create and modify complex diagrams."
%\end{quote}
%There was no implemation for using mermaid files in latex yet. So I decide to try it with this package.
%\end{abstract}
%\tableofcontents
%\section{Preconditions}
%\begin{enumerate}
%\item Install mermaid.cli (higher than 8.13.10)\\ \url{http://github.com/mermaid-js/mermaid-cli\#Install-globally}\\
%For instance with: \verb|npm install -g @mermaid-js/mermaid-cli|
%\item pdflatex available with command line parameter: \verb|--shell-escape|.
%\end{enumerate}
% \newpage
% \section{Usage}
\begin{example}
\documentclass[]{article}
\usepackage{marmermaidtex}
\begin{document}
\begin{marmermaidtex}[width=.25\textwidth]{foo1.pdf}
graph TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa]
\end{marmermaidtex}
\end{document}
\end{example}
%\subsection{Calling the Package}
%The package may be called as any other package with:
\begin{command}
\usepackage{marmermaidtex}
\end{command}
or you call it with setting the option(s). Take a look in subsection: \ref{sec:package_options}
\begin{command}
\usepackage[<options>]{marmermaidtex}
\end{command}
%\subsection{Commands / envieronments}
%\DescribeEnv{marmermaidtex}
\begin{example}
\begin{marmermaidtex}[width=.25\textwidth]{foo1.pdf}
graph TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa]
\end{marmermaidtex}
\end{example}
\begin{center}
\begin{marmermaidtex}[width=.35\textwidth]{foo1.pdf}
graph TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa]
\end{marmermaidtex}
\end{center}
Marmermaidtex environment in combination with figure environment:
\begin{example}
\begin{figure}
\center
\begin{marmermaidtex}[width=.25\textwidth]{foo2.pdf}
graph TD
A --> B
B --> C
C --> A
\end{marmermaidtex}
\caption{caption}
\label{fig:caption}
\end{figure}
\end{example}
%\subsection{Package options} \label{sec:package_options}
%Here are the options that may be loaded with the package:
%\vbskip
%\vbopt{noOverwrite} As default, the marmermaidtex environment will overwrite the existing files. With \verb|noOverwrite| no overwriting will happen.
%\vbskip
%\vbopt{noWarningOverwrite} As default, the marmermaidtex environment will send a warning message for each file which is overwritten. With \verb|noWarningOverwrite| only one warning message will be sent: \verb|"All warnings for overwrite files a switch off now."|
\StopEventually{}
\section{Implementation}
% \begin{macrocode}
\RequirePackage{
ifthen,
xkeyval,
silence,
iftex,
ifpdf,
graphicx
}
% \end{macrocode}
define a new boolean called noOverwrite and set it to false
% \begin{macrocode}
\newboolean{noOverwrite}
\setboolean{noOverwrite}{false}
% \end{macrocode}
define a new boolean called noWarningOverwrite and set it to false
% \begin{macrocode}
\newboolean{noWarningOverwrite}
\setboolean{noWarningOverwrite}{false}
% \end{macrocode}
declare a new package option called noOverwrite
% \begin{macrocode}
\DeclareOptionX{noOverwrite}{
\setboolean{noOverwrite}{true}
}
% \end{macrocode}
declare a new package option called noWarningOverwrite
% \begin{macrocode}
\DeclareOptionX{noWarningOverwrite}{
\setboolean{noWarningOverwrite}{true}
}
% \end{macrocode}
% \begin{macrocode}
\ProcessOptionsX
% \end{macrocode}
% \begin{macrocode}
\ifthenelse{\NOT\boolean{noOverwrite} \AND \boolean{noWarningOverwrite}}{
\PackageWarning{marmermaidtex}{All Warnings for overwrite files a switch off now.}{}
\WarningFilter{latex}{Writing or overwriting file}
}% \end{macrocode}
define a new boolean called noWarningOverwrite and set it to false
% \begin{macrocode}
\newboolean{correctTool}
\setboolean{correctTool}{false}
% \end{macrocode}
% \begin{macrocode}
\ifXeTeX
\setboolean{correctTool}{true}
\fi
\ifpdf
\setboolean{correctTool}{true}
\fi
% \end{macrocode}
% \begin{macrocode}
\ifthenelse{\boolean{correctTool}}{}{\PackageError{marmermaidtex}{You aren't using pdflatex, Xetex, Luatex}{}}
% \end{macrocode}
\begin{environment}{marmermaidtex}
% Definition for a new enivornment and call it marmermaidtex.
% \begin{macrocode}
\newenvironment{marmermaidtex}[2][]{
% \end{macrocode}
% Before:\\
% define a new varible for keys for
% \begin{macrocode}
\def\@graphicsopts{#1}
% \end{macrocode}
% define a new varible for parameter for file name
% \begin{macrocode}
\def\tempFilenameMermaidPdf{#2}
% \end{macrocode}
% to save code to file
% \begin{macrocode}
\csname filecontents*\endcsname[overwrite]{\tempFilenameMermaidPdf.tmp}
}
{
% \end{macrocode}
% After:
% \begin{macrocode}
\csname endfilecontents*\endcsname
% \end{macrocode}
% include generated image to tex file
% \begin{macrocode}
\expandafter\includegraphics\expandafter[\@graphicsopts]{\tempFilenameMermaidPdf}
}
% \end{macrocode}
\end{environment}
% \Finale