Debian Codegraph @

texmf-dist/source/latex/eolang/eolang.dtx

raw
1 % \iffalse meta-comment
2 % SPDX-FileCopyrightText: Copyright (c) 2021-2025 Yegor Bugayenko
3 % SPDX-License-Identifier: MIT
4 % \fi
5
6 % \CheckSum{0}
7 %
8 % \CharacterTable
9 % {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
10 % 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
11 % Digits \0\1\2\3\4\5\6\7\8\9
12 % Exclamation \! Double quote \" Hash (number) \#
13 % Dollar \$ Percent \% Ampersand \&
14 % Acute accent \' Left paren \( Right paren \)
15 % Asterisk \* Plus \+ Comma \,
16 % Minus \- Point \. Solidus \/
17 % Colon \: Semicolon \; Less than \<
18 % Equals \= Greater than \> Question mark \?
19 % Commercial at \@ Left bracket \[ Backslash \\
20 % Right bracket \] Circumflex \^ Underscore \_
21 % Grave accent \` Left brace \{ Vertical bar \|
22 % Right brace \} Tilde \~}
23
24 % \GetFileInfo{eolang.dtx}
25 % \DoNotIndex{\endgroup,\begingroup,\let,\else,\s,\n,\r,\\,\1,\fi}
26
27 % \iffalse
28 %<*driver>
29 \ProvidesFile{eolang.dtx}
30 %</driver>
31 %<package>\NeedsTeXFormat{LaTeX2e}
32 %<package>\ProvidesPackage{eolang}
33 %<*package>
34 [2025/12/24 0.23.0 Formulas and Graphs for EO Programming Language]
35 %</package>
36 %<*driver>
37 \documentclass{ltxdoc}
38 \usepackage[T1]{fontenc}
39 \usepackage[maxnames=1,minnames=1,maxbibnames=1,natbib=true,citestyle=authoryear,bibstyle=authoryear,doi=false,url=false,isbn=false]{biblatex}
40 \addbibresource{eolang.bib}
41 \usepackage[tt=false, type1=true]{libertine}
42 \usepackage{microtype}
43 \AddToHook{env/verbatim/begin}{\microtypesetup{protrusion=false}}
44 \usepackage{graphicx}
45 \usepackage{xcolor}
46 \usepackage[runs=2,dtx]{docshots}
47 \usepackage[nocomments]{eolang}
48 \usepackage{href-ul}
49 \PageIndex
50 \EnableCrossrefs
51 \CodelineIndex
52 \RecordChanges
53 \begin{document}
54 \DocInput{eolang.dtx}
55 \PrintChanges
56 \PrintIndex
57 \end{document}
58 %</driver>
59 % \fi
60
61 % \title{\includegraphics[height=1in]{cactus.pdf} \\ |eolang|: \LaTeX{} Package \\ for Formulas and Graphs \\ of EO Programming Language \\ and \(\varphi\)-Calculus\thanks{The sources are in GitHub at \href{https://github.com/objectionary/eolang.sty}{objectionary/eolang.sty}}}
62 % \author{Yegor Bugayenko \\ \texttt{[email protected]}}
63 % \date{\filedate, \fileversion}
64 %
65 % \maketitle
66 %
67 % \textbf{\color{red}NB!}
68 % You must run \TeX{} processor with |-shell-escape| option
69 % and you must have \href{https://www.perl.org}{Perl} installed.
70 % If you omit the |-shell-escape| option, the package will try
71 % to use cached files, if they exist. If they don't, compilation will
72 % fail. Thus, when you must prepare your document for a compilation
73 % without the |-shell-escape| option, run it locally with the option provided
74 % and then package all files (including the files in the |_eolang-*| directories)
75 % into a single ZIP archive. It is advised to use |tmpdir| package option
76 % in this case, in order to make the directory name not depend on the
77 % \LaTeX{} engine.
78 %
79 % If |-shell-escape| is set, this package won't work on Windows, because
80 % it uses POSIX command line interface.
81
82 % \section{Introduction}
83 %
84 % This package helps you print formulas of \phic{},
85 % which is a formal foundation of \href{https://www.eolang.org}{EO}
86 % programming language. The calculus was introduced by \citet{bugayenko2021eolang}
87 % and later formalized by \citet{kudasov2021}. Here is how you render
88 % a simple expression:
89 % \begin{docshot}
90 % \documentclass{minimal}
91 % \usepackage{eolang}
92 % \begin{document}
93 % \begin{phiquation*}
94 % app -> [[ % it's abstract!
95 % ^ -> $.b.^{^2}, 0/t~> TRUE,
96 % b -> [[ *-> Q.fn(56),
97 % @ -> Q.string.trim($),
98 % D> 01-FE-C3 ]]]],\\
99 % x -> [[ \lambda ..> ? ]].
100 % \end{phiquation*}
101 % \end{document}
102 % \end{docshot}
103
104 % \DescribeEnv{phiquation}
105 % The environment |phiquation| lets you write a \phic{} expressions
106 % using simple plain-text notation, where:
107 % \begin{itemize}\setlength\itemsep{0em}
108 % \item ``|@|'' maps to ``$@$''
109 % (|\varphi|),
110 % \item ``|^|'' maps to ``$^$''
111 % (|\rho|),
112 % \item ``|$|'' maps to ``\(\phiTerminal{\xi}\)''
113 % (|\xi|),
114 % \item ``|?|'' maps to ``$?$''
115 % (|\varnothing|),
116 % \item ``|T|'' maps to ``$T$''
117 % (|\bot|),
118 % \item ``|Q|'' maps to ``$Q$''
119 % (|\Phi|),
120 % \item ``|->|'' maps to ``$->$''
121 % (|\mapsto|),
122 % \item ``|..>|'' maps to ``$..>$''
123 % (|\phiDotted|),
124 % \item ``|~>|'' maps to ``$~>$''
125 % (|\phiWave|),
126 % \item ``|D|'' maps to ``$D$''
127 % (|\Delta|),
128 % \item ``|L|'' maps to ``$L$''
129 % (|\lambda|),
130 % \item ``|D>|'' maps to ``$D>$''
131 % (|\Delta ..>|),
132 % \item ``|L>|'' maps to ``$L>$''
133 % (|\lambda ..>|),
134 % \item ``|[[|'' maps to ``$[[$''
135 % (|\llbracket|),
136 % \item ``|]]|'' maps to ``$]]$''
137 % (|\rrbracket|),
138 % \item ``|==|'' maps to ``$==$''
139 % (|\equiv|),
140 % \item ``\texttt{\textbar{abc}\textbar}'' maps to ``\texttt{abc}''
141 % (|\texttt{abc}|).
142 % \end{itemize}
143 % Also, a few symbols are supported for $\varphi$PU architecture:
144 % \begin{itemize}\setlength\itemsep{0em}
145 % \item ``|<<|'' maps to ``$\langle$''
146 % (|\langle|),
147 % \item ``|>>|'' maps to ``$\rangle$''
148 % (|\rangle|),
149 % \item ``|-abc>|'' maps to ``$\phiSlot{abc}$''
150 % (|\phiSlot{abc}|),
151 % \item ``|:=|'' maps to ``$\vDash$''
152 % (|\vDash|).
153 % \end{itemize}
154
155 % Before any arrow you can put a number, which will be rendered as |\alpha| with an index, for example
156 % |\phiq{~0 -> x}| will render ``\phiq{~0 -> x}''.
157 % It's also possible to use |~0| to render \(\alpha_0\).
158 % Instead of a number you can use asterisk too.
159
160 % You can append a slash and a title to the number of an attribute, such as |0/g->x|.
161 % This will render as \phiq{0/g->x}. You can use fixed-width words too, for example
162 % \verb=\phiq{0/|f|->x}= will render as ``\phiq{0/|f|->x}''. It's also possible
163 % to use an asterisk instead of a number, such that |\phiq{*/g->x}| renders as ``\phiq{*/g->x}''
164
165 % Numbers are automatically converted to fixed-width font, no need to always decorate them with vertical bars.
166
167 % Object names are automatically converted to fixed-width font too, if they have more than one letter.
168
169 % Texts in double quotes are automatically converted to fixed-width font too.
170
171 % \DescribeMacro{\phiq}
172 % The command |\phiq| lets you inline a \phic{} expressions
173 % using the same simple plain-text notation. You can use dollar sign directly too:
174 % \docshotOptions{firstline=4,lastline=10}
175 % \begin{docshot}
176 % \documentclass{article}
177 % \pagestyle{empty}
178 % \usepackage{eolang}
179 % \begin{document}
180 % A simple object
181 % \phiq{x -> [[@ -> y]]} \\
182 % is a decorator of
183 % the data object \\
184 % $y -> [[\Delta ..> 42]]$.
185 % \end{document}
186 % \end{docshot}
187
188 % \DescribeEnv{sodg}
189 % The environment |sodg| allows you to draw a \href{https://github.com/objectionary/sodg}{SODG} graph:
190 % \begin{docshot}
191 % \documentclass{standalone}
192 % \usepackage{eolang}
193 % \begin{document}
194 % \begin{sodg}
195 % v0 \\ v0===> \\ v0!!A
196 % v1 xy:v0,-.8,2.8 data:42 tag:d_1
197 % v0->v1 a:x rho \\ =>v1
198 % v2 xy:v0,+1,+1 atom:\xi.x+1
199 % v1->v2 a:|hi| bend:-15
200 % v2->v0 pi bend:10 % a comment
201 % \end{sodg}
202 % \end{document}
203 % \end{docshot}
204 % The content of the environment is parsed line by line. Markers in each line are
205 % separated by a single space. The first marker is either a unique name of a
206 % vertex, like ``|v1|'' in the example above, or an edge, like ``|v0->v1|.'' All other markers are either
207 % unary like ``|rho|'' or binary like ``|atom:$\xi.x+1$|.'' Binary markers have two
208 % parts, separated by colon.
209
210 % The following markers are supported for a vertex:
211 % \begin{itemize}\setlength\itemsep{0em}
212 % \item ``|tag:<math>|'' puts a custom label |<math>| into the circle;
213 % \item ``|data:[<box>]|'' makes it a data vertex with an optional attached ``|<box>|''
214 % (the content of the box may only be numeric data);
215 % \item ``|atom:[<box>]|'' makes it an atom with an optional attached ``|<box>|''
216 % (the content of the box is a math formula);
217 % \item ``|box:<txt>|'' attaches a ``|<box>|'' to it;
218 % \item ``|xy:<v>,<r>,<d>|'' places this vertex in a position relative to the vertex ``|<v>|,''
219 % shifting it right by ``|<r>|'' and down by ``|<d>|'' centimetres;
220 % \item ``|+:<v>|'' makes a copy of an existing vertex and all its kids;
221 % \item ``|edgeless|'' removes the border from the vertex;
222 % \item ``|style:{...}|'' adds this TikZ style to the vertex |\node|.
223 % \end{itemize}
224
225 % The following markers are supported for an edge:
226 % \begin{itemize}\setlength\itemsep{0em}
227 % \item ``|rho|'' places a backward snake arrow to the edge,
228 % \item ``|bend:<angle>|'' bend it right by the amount of ``|<angle>|,''
229 % \item ``|a:<txt>|'' attaches label ``|<txt>|'' to it,
230 % \item ``|pi|'' makes it dotted, with $\pi$ label;
231 % \item ``|style:{...}|'' adds this TikZ style to the edge |\path|.
232 % \end{itemize}
233
234 % It is also possible to put transformation arrows to the graph, with the help of ``|v0=>v1|'' syntax. The arrow
235 % will be placed exactly between two vertices. You can also put an arrow from a vertex to the right,
236 % saying for example ``|v3=>|'', or from the left to the vertex, by saying for example ``|=>v5|.'' If you
237 % want the arrow to stay further away from the vertex than usual, use a few ``|=|'' symbols, for example ``|===>v0|.''
238
239 % You can also put a marker at the left side of a vertex, using ``|v5!A|'' syntax, where ``|v5|'' is the vertex
240 % and ``|A|'' is the text in the marker. They are useful when you put a few graphs on a picture
241 % explaining how one graph is transformed to another one and so forth. You can make the distance between the vertex
242 % and the marker a bit larger by using a few exclamation marks,
243 % for example ``|v5!!!A|'' will make a distance three times bigger.
244
245 % You can make a clone of an existing vertex together with all its dependants, by using this syntax: ``|v0+a|.''
246 % Here, we make a copy of ``|v0|'' and call it ``|v0a|.'' See the example below.
247
248 % Be aware, unrecognized markers are simply ignored, without any error reporting.
249
250 % \DescribeMacro{\eolang}
251 % \DescribeMacro{\phic}
252 % \DescribeMacro{\xmir}
253 % There is also a no-argument command |\eolang| to help you print the name of
254 % \eolang{} language. It understands the |anonymous| package option and prints itself
255 % differently, to double-blind your paper. There is also |\phic| command to print
256 % the name of \phic{}, also sensitive to |anonymous| mode. The macro |\xmir| prints "XMIR".
257 % \docshotOptions{firstline=3,lastline=10}
258 % \begin{docshot}
259 % \documentclass{acmart}
260 % \thispagestyle{empty}
261 % \usepackage[anonymous]{eolang}
262 % \begin{document}
263 % In our research we use \eolang{}, \\
264 % an experimental object-oriented \\
265 % dataflow language, \phic{}, as its \\
266 % formal foundation, and \xmir{} --- \\
267 % its XML-based representation.
268 % \end{document}
269 % \end{docshot}
270 % Without the |anonymous| option there will be no orange color:
271 % \docshotOptions{firstline=3,lastline=10}
272 % \begin{docshot}
273 % \documentclass[anonymous]{acmart}
274 % \thispagestyle{empty}
275 % \usepackage{eolang}
276 % \begin{document}
277 % In our research we use \eolang{}, \\
278 % an experimental object-oriented \\
279 % dataflow language, \phic{}, as its \\
280 % formal foundation, and \xmir{} --- \\
281 % its XML-based representation.
282 % \end{document}
283 % \end{docshot}
284
285 % \DescribeMacro{\phiWave}
286 % \DescribeMacro{\phiDotted}
287 % A few simple commands are defined to help you render arrows.
288 % \docshotOptions{firstline=6,lastline=12}
289 % \begin{docshot}
290 % \documentclass{article}
291 % \pagestyle{empty}
292 % \usepackage[paperwidth=3in]{geometry}
293 % \usepackage{eolang}
294 % \begin{document}\noindent
295 % If $x$ is an identifier and $y$ is
296 % an object, then $x \phiWave y$
297 % makes it a decoratee
298 % of an arbitrary number of objects,
299 % while $x \phiDotted y$ makes it
300 % a special attribute.
301 % \end{document}
302 % \end{docshot}
303
304 % \DescribeMacro{\phiOset}
305 % \DescribeMacro{\phiUset}
306 % If you want to put a text over an arrow or under it, use |\phiOset| and |\phiUset| respectively:
307 % \docshotOptions{firstline=6,lastline=11}
308 % \begin{docshot}
309 % \documentclass{article}
310 % \pagestyle{empty}
311 % \usepackage[paperwidth=3in]{geometry}
312 % \usepackage{eolang}
313 % \begin{document}\noindent
314 % When the names of attributes and their
315 % values don't matter, we use an arrow
316 % with a star, for example:
317 % \begin{phiquation*}
318 % [[ \phiOset{*}{->} ]].
319 % \end{phiquation*}
320 % \end{document}
321 % \end{docshot}
322
323 % \DescribeMacro{\phiMany}
324 % Sometimes you may need to simplify the way you describe an object (the typesetting is a bit off, but this is not because of us, but rather because of \href{https://tex.stackexchange.com/questions/664772}{this}):
325 % \docshotOptions{firstline=6,lastline=14}
326 % \begin{docshot}
327 % \documentclass{article}
328 % \pagestyle{empty}
329 % \usepackage[paperwidth=3in]{geometry}
330 % \usepackage{eolang}
331 % \begin{document}\noindent
332 % The expression
333 % \phiq{[[ 1-> x_1,
334 % 2-> x_2, \dots,
335 % \alpha_n -> x_n ]]}
336 % and expression
337 % \phiq{[[ \alpha_i
338 % \phiMany{->}{i=1}{n} x_i ]]}
339 % are syntactically different but
340 % semantically equivalent.
341 % \end{document}
342 % \end{docshot}
343
344 % \DescribeMacro{\phiSaveTo}
345 % \DescribeMacro{\sodgSaveTo}
346 % If you want to use |phiquation| or |sodg| environments inside |tabular| or any other environment or command, you won't be able to do this, because |phiquation| and |sodg| are ``verbatim'' environments. |\phiSaveTo| and |\sodgSaveTo| commands will help you in this situation. You use them right before |\begin{phiquation}| or |\begin{sodg}| respectively --- the content of the equation or the graph won't be rendered, but instead saved to the file. Later, inside |tabular|, you can use it through the |\input| macro (don't forget the |\parbox|):
347 % \docshotOptions{firstline=5,lastline=12}
348 % \begin{docshot}
349 % \documentclass{article}
350 % \usepackage{eolang}
351 % \pagestyle{empty}
352 % \begin{document}
353 % \phiSaveTo{a}
354 % \begin{phiquation*}
355 % [[ x -> [[D>42]] ]]
356 % \end{phiquation*}
357 % \begin{tabular}{p{.5in}l}
358 % Free: & $[[x -> ?]]$ \\
359 % Bound: & \parbox{1in}{\input{a}} \\
360 % \end{tabular}
361 % \end{document}
362 % \end{docshot}
363
364 % \DescribeMacro{\eoAnon}
365 % You may want to hide some of the content with the help of the |anonymous| package option. The command |\eoAnon| may help you with this. It has two parameters: one mandatory and one optional. The mandatory one is the content you want to show and the optional one is the substitution we will render if the |anonymous| package option is set.
366
367 % \section{Package Options}
368
369 % \DescribeMacro{tmpdir}
370 % The default location of temp files is |_eolang|. You can change this with the help of the |tmpdir| package option:
371 %\iffalse
372 %<*verb>
373 %\fi
374 \begin{verbatim}
375 \usepackage[tmpdir=/tmp/foo]{eolang}
376 \end{verbatim}
377 %\iffalse
378 %</verb>
379 %\fi
380
381 % \DescribeMacro{nodollar}
382 % You may disable the special treatment of the dollar sign by using the |nodollar| package option:
383 %\iffalse
384 %<*verb>
385 %\fi
386 \begin{verbatim}
387 \usepackage[nodollar]{eolang}
388 \end{verbatim}
389 %\iffalse
390 %</verb>
391 %\fi
392
393 % \DescribeMacro{anonymous}
394 % You may anonymize |\eolang|, |\xmir|, and |\phic| commands by using |anonymous| package option (they all use the |\eoAnon| command mentioned earlier):
395 %\iffalse
396 %<*verb>
397 %\fi
398 \begin{verbatim}
399 \usepackage[anonymous]{eolang}
400 \end{verbatim}
401 %\iffalse
402 %</verb>
403 %\fi
404
405 % \DescribeMacro{noshell}
406 % You may prohibit any interactions with the shell by using the |noshell| option. This may be helpful when you send your document
407 % for outside processing and want to make sure the compilation won't break due to shell errors:
408 %\iffalse
409 %<*verb>
410 %\fi
411 \begin{verbatim}
412 \usepackage[noshell]{eolang}
413 \end{verbatim}
414 %\iffalse
415 %</verb>
416 %\fi
417
418 % \section{More Examples}
419
420 % The |phiquation| environment treats ends of line as signals to start
421 % new lines in the formula. If you don't want this to happen and want to parse
422 % the next line as a continuation of the current line, you can use a single
423 % backslash as it's done here:
424 % \docshotOptions{firstline=6,lastline=11}
425 % \begin{docshot}
426 % \documentclass{article}
427 % \usepackage{amsmath}
428 % \usepackage{eolang}
429 % \pagestyle{empty}
430 % \begin{document}
431 % \begin{phiquation*}
432 % \dfrac \
433 % {x->[[@->y]] \quad y->[[z->42]]} \
434 % {x.z -> T} \
435 % \text{\sffamily R1}
436 % \end{phiquation*}
437 % \end{document}
438 % \end{docshot}
439
440 % This is how you can use |\dfrac| from \href{https://ctan.org/pkg/amsmath}{amsmath} for large inference rules,
441 % with the help of |\begin{split}| and |\end{split}|:
442 % \docshotOptions{firstline=6,lastline=15}
443 % \begin{docshot}
444 % \documentclass{article}
445 % \usepackage{amsmath}
446 % \usepackage{eolang}
447 % \pagestyle{empty}
448 % \begin{document}
449 % \begin{phiquation*}
450 % \dfrac{\begin{split}
451 % x->[[@->y, z->42,
452 % 0/g->?, 1/foo->42]]
453 % \end{split}}{\begin{split}
454 % x->[[@->y, z->?, f ~> |pi|(
455 % ~0 ->[[ \psi -> |hello|(12) ]],
456 % ~1 -> 42)]]
457 % \end{split}}\text{R2}.
458 % \end{phiquation*}
459 % \end{document}
460 % \end{docshot}
461
462 % You can use the |matrix| environment too, in order to group a few lines:
463 % \docshotOptions{firstline=5,lastline=11}
464 % \begin{docshot}
465 % \documentclass{article}
466 % \usepackage{eolang}
467 % \pagestyle{empty}
468 % \begin{document}
469 % \begin{phiquation*}
470 % foo -> \left\{\begin{matrix} \
471 % ? \\
472 % [[ L> ^ \times $.\alpha_0 ]] \\
473 % [[ D> 42 ]] \
474 % \end{matrix}\right\}
475 % \end{phiquation*}
476 % \end{document}
477 % \end{docshot}
478
479 % The |cases| environment works too:
480 % \docshotOptions{firstline=5,lastline=11}
481 % \begin{docshot}
482 % \documentclass{article}
483 % \usepackage{eolang}
484 % \pagestyle{empty}
485 % \begin{document}
486 % \begin{phiquation*}
487 % \beta := \begin{cases} \
488 % [ v_2, @ -dtzd> 42 ] \\
489 % [ v_{33} ] \
490 % \end{cases}
491 % \end{phiquation*}
492 % \end{document}
493 % \end{docshot}
494
495 % The |phiquation| environment may be used together with the \href{https://ctan.org/pkg/acmart}{acmart} package:
496 % \begin{docshot}
497 % \documentclass{acmart}
498 % \usepackage{eolang}
499 % \thispagestyle{empty}
500 % \begin{document}
501 % \begin{phiquation*}
502 % x -> [[
503 % y -> [[
504 % z -> $, f ..> ? ]]]],\\
505 % \beta_1 := [ \psi -wait> ? ].
506 % \end{phiquation*}
507 % \end{document}
508 % \end{docshot}
509
510 % It's possible to use |\label| inside the |phiquation| environment (pay attention to how you can disable our custom parsing of math formulas by means of curled brackets around the ``|4|'' number):
511 % \docshotOptions{firstline=6,lastline=13}
512 % \begin{docshot}
513 % \documentclass{article}
514 % \usepackage[paperwidth=3in]{geometry}
515 % \usepackage{eolang}
516 % \pagestyle{empty}
517 % \begin{document}\noindent
518 % Discriminant can be calculated using
519 % the following simple formula:
520 % \begin{phiquation}
521 % D = b{^2} - {4}ac.
522 % \label{d}
523 % \end{phiquation}
524 % Eq.~\ref{d} is also widely used in
525 % number theory and polynomial factoring.
526 % \end{document}
527 % \end{docshot}
528
529 % You can add comments to your equations, using the |&&| command (pay attention, the text inside |\text{}| is not processed and treated like a plain text):
530 % \docshotOptions{firstline=6,lastline=10}
531 % \begin{docshot}
532 % \documentclass{article}
533 % \usepackage[paperwidth=4in]{geometry}
534 % \usepackage{eolang}
535 % \pagestyle{empty}
536 % \begin{document}
537 % \begin{phiquation*}
538 % [[ ~0 -> x ]] && \text{This is formation}
539 % [[ ~0 -> ? ]] && \text{Abstraction}
540 % x(D>42) && \text{Application}
541 % \end{phiquation*}
542 % \end{document}
543 % \end{docshot}
544
545 % If you don't use |nodollar| package option, you can still use normal parsing of the dollar sign, by means of |\(...\)| syntax:
546 % \docshotOptions{firstline=6,lastline=8}
547 % \begin{docshot}
548 % \documentclass{article}
549 % \usepackage[paperwidth=3in]{geometry}
550 % \usepackage{eolang}
551 % \pagestyle{empty}
552 % \begin{document}\noindent
553 % The object formation $[[~0->x]]$
554 % may be replaced with a formula
555 % \( Q \times a^2 \).
556 % \end{document}
557 % \end{docshot}
558
559 % The |phiquation| environment will automatically align formulas by the first
560 % arrow, if there are only left-aligned formulas:
561 % \docshotOptions{firstline=5,lastline=11}
562 % \begin{docshot}
563 % \documentclass{acmart}
564 % \usepackage{eolang}
565 % \thispagestyle{empty}
566 % \begin{document}
567 % \begin{phiquation*}
568 % x(\pi) -> [[\lambda ..> f_1]], \\
569 % x(a,b,c) -> [[ ~0 -> ?, L> Foo, \
570 % @ -> Q.hello($), x -> false ]], \\
571 % \Delta = |43-09|,
572 % x(y) == x(~0 -> y).
573 % \end{phiquation*}
574 % \end{document}
575 % \end{docshot}
576
577 % If not a single line is indented in |phiquation|, all formulas will be centered:
578 % \docshotOptions{firstline=5,lastline=9}
579 % \begin{docshot}
580 % \documentclass{acmart}
581 % \usepackage{eolang}
582 % \thispagestyle{empty}
583 % \begin{document}
584 % \begin{phiquation*}
585 % [[ b -> ? ]],
586 % [[ @ -> TRUE, \Delta ..> 42 ]], \\
587 % \psi = << \pi, 42 >>.
588 % \end{phiquation*}
589 % \end{document}
590 % \end{docshot}
591
592 % It is possible to use ``manual splitting'' mode in the |phiquation| environment by starting the body with |\begin{split}|:
593 % \docshotOptions{firstline=5,lastline=10}
594 % \begin{docshot}
595 % \documentclass{article}
596 % \usepackage{eolang}
597 % \thispagestyle{empty}
598 % \begin{document}
599 % \begin{phiquation*}
600 % \begin{split}
601 % x(\pi) & -> 4 \\
602 % x(a,b,c) & -> [[ \alpha_0 -> ? ]] \\
603 % \end{split}
604 % \end{phiquation*}
605 % \end{document}
606 % \end{docshot}
607
608 % When necessary to use a percentage sign, prepend it with a backward slash:
609 % \docshotOptions{firstline=5,lastline=10}
610 % \begin{docshot}
611 % \documentclass{article}
612 % \usepackage{eolang}
613 % \thispagestyle{empty}
614 % \begin{document}
615 % \begin{phiquation*}
616 % x -> sprintf("Hello, \%s!", name)
617 % \end{phiquation*}
618 % \end{document}
619 % \end{docshot}
620
621 % You can make a copy of a vertex together with its kids:
622 % \docshotOptions{firstline=5,lastline=15}
623 % \begin{docshot}
624 % \documentclass{article}
625 % \pagestyle{empty}
626 % \usepackage{eolang}
627 % \begin{document}
628 % \begin{sodg}
629 % v0 \\ v0!!A
630 % v1 xy:v0,.7,1
631 % v0->v1 a:x bend:-10
632 % v2 xy:v1,-1.3,.8
633 % v1->v2 a:|foo| bend:-20
634 % v0+a xy:v0,3,0
635 % v3a xy:v0a,-.7,1
636 % v0a->v3a a:e bend:-15
637 % v0=>v0a \\ v0a!B
638 % \end{sodg}
639 % \end{document}
640 % \end{docshot}
641
642 % You can make a copy from a copy:
643 % \docshotOptions{firstline=5,lastline=15}
644 % \begin{docshot}
645 % \documentclass{article}
646 % \pagestyle{empty}
647 % \usepackage{eolang}
648 % \begin{document}
649 % \begin{sodg}
650 % v0
651 % v1 xy:v0,.7,1
652 % v0->v1 a:x bend:-10 rho
653 % v0+a xy:v0,3,0 \\ v0=>v0a
654 % v2a xy:v1a,-.8,1.3
655 % v1a->v2a a:e
656 % v0a+b xy:v0a,3,0 \\ v0a=>v0b
657 % v3b xy:v2b,-1,-1
658 % v2b->v3b a:\psi{} rho
659 % \end{sodg}
660 % \end{document}
661 % \end{docshot}
662
663 % You can have ``broken'' edges, using ``|break|'' attribute of an edge.
664 % The attribute must have a value, which is the percentage of the path
665 % between vertices that the arrow should take (can't be more than 80 and less than 20).
666 % This may be convenient when you can't fit all edges into the graph,
667 % for example:
668 % \docshotOptions{firstline=5,lastline=14}
669 % \begin{docshot}
670 % \documentclass{article}
671 % \pagestyle{empty}
672 % \usepackage{eolang}
673 % \begin{document}
674 % \begin{sodg}
675 % v0
676 % v1 xy:v0,-1,1
677 % v0->v1 a:x
678 % v2 xy:v0,0,1
679 % v0->v2 a:y
680 % v3 xy:v0,1,1
681 % v0->v3 a:\psi{}
682 % v3->v1 a:f bend:-75 break:30
683 % \end{sodg}
684 % \end{document}
685 % \end{docshot}
686
687 % You can add \href{https://en.wikipedia.org/wiki/PGF/TikZ}{TikZ} commands to |sodg| graph, for example:
688 % \docshotOptions{firstline=6,lastline=13}
689 % \begin{docshot}
690 % \documentclass{article}
691 % \pagestyle{empty}
692 % \usepackage{eolang}
693 % \usetikzlibrary{fit}
694 % \begin{document}
695 % \begin{sodg}
696 % v0 edgeless
697 % v11 xy:v0,-1,1 \\ v0->v11
698 % v12 xy:v0,0,1 \\ v0->v12
699 % v13 xy:v0,1,1 \\ v0->v13
700 % \node[draw=red,rounded corners,\
701 % dotted,fit=(v11) (v12)] {};
702 % \end{sodg}
703 % \end{document}
704 % \end{docshot}
705
706 % You can modify TikZ style yourself (make sure |style:| stays at the end of the line!), for example:
707 % \docshotOptions{firstline=6,lastline=12}
708 % \begin{docshot}
709 % \documentclass{article}
710 % \pagestyle{empty}
711 % \usepackage{eolang}
712 % \usetikzlibrary{fit}
713 % \begin{document}
714 % \begin{sodg}
715 % v0
716 % v1 xy:v0,-2,1 style:font=\color{red}
717 % v2 xy:v0,2,1
718 % v0->v1 style:line width=2pt
719 % v0->v2 style:draw=orange
720 % \end{sodg}
721 % \end{document}
722 % \end{docshot}
723
724 % \StopEventually{}
725
726 % \section{Implementation}
727 % \changes{0.0.1}{2022/10/15}{First draft.}
728
729 % First, we include a few packages.
730 % We need \href{https://ctan.org/pkg/stmaryrd}{stmaryrd} for |\llbracket| and |\rrbracket| commands:
731 % \begin{macrocode}
732 \RequirePackage{stmaryrd}
733 % \end{macrocode}
734 % We need \href{https://ctan.org/pkg/amsmath}{amsmath} for |equation*| environment:
735 % \begin{macrocode}
736 \RequirePackage{amsmath}
737 % \end{macrocode}
738 % We need \href{https://ctan.org/pkg/amssymb}{amssymb} for |\varnothing| command. We disable |\Bbbk|
739 % because it may conflict with some packages from \href{https://ctan.org/pkg/acmart}{acmart}:
740 % \begin{macrocode}
741 \let\Bbbk\relax\RequirePackage{amssymb}
742 % \end{macrocode}
743 % We need \href{https://ctan.org/pkg/fancyvrb}{fancyvrb} for |\VerbatimEnvironment| command:
744 % \begin{macrocode}
745 \RequirePackage{fancyvrb}
746 % \end{macrocode}
747 % We need \href{https://ctan.org/pkg/iexec}{iexec} for executing Perl scripts:
748 % \begin{macrocode}
749 \ifdefined\eolang@noshell\else\RequirePackage{iexec}\fi
750 % \end{macrocode}
751
752 % Then, we process package options:
753 % \changes{0.1.0}{2022/10/26}{Parsing of package options introduced.}
754 % \changes{0.6.0}{2022/11/14}{Package option \texttt{nocomments} added in order to enable comments suppression in temporary \texttt{.tex} files (may be pretty important for \texttt{.dtx} documents).}
755 % \changes{0.8.0}{2022/11/29}{The \texttt{anonymous} package option added.}
756 % \begin{macrocode}
757 \RequirePackage{pgfopts}
758 \RequirePackage{ifluatex}
759 \RequirePackage{ifxetex}
760 \pgfkeys{
761 /eolang/.cd,
762 tmpdir/.store in=\eolang@tmpdir,
763 tmpdir/.default=_eolang\ifxetex-xe\else\ifluatex-lua\fi\fi,
764 nocomments/.store in=\eolang@nocomments,
765 nodollar/.store in=\eolang@nodollar,
766 anonymous/.store in=\eolang@anonymous,
767 noshell/.store in=\eolang@noshell,
768 tmpdir
769 }
770 \ProcessPgfPackageOptions{/eolang}
771 % \end{macrocode}
772
773 % Then, we make a directory where all temporary files will be kept:
774 % \begin{macrocode}
775 \makeatletter
776 \ifdefined\eolang@noshell\else\RequirePackage{shellesc}\fi
777 \IfFileExists
778 {\eolang@tmpdir/\jobname}
779 {\message{eolang: Temporary directory "\eolang@tmpdir/\jobname"
780 already exists^^J}}
781 {
782 \ifdefined\eolang@noshell
783 \message{eolang: Temporary directory "\eolang@tmpdir/\jobname"
784 is not created, because of the "noshell" package option,
785 most probably the compilation will fail later^^J}
786 \else
787 \ifnum\ShellEscapeStatus=1
788 \iexec[null]{mkdir -p "\eolang@tmpdir/\jobname"}
789 \else
790 \message{eolang: Temporary directory "\eolang@tmpdir/\jobname"
791 is not created, because -shell-escape is not set, and
792 it doesn't exist, most probably the compilation
793 will fail later^^J}
794 \fi
795 \fi
796 }
797 \makeatother
798 % \end{macrocode}
799
800 % \begin{macro}{\eolang@lineno}
801 % \changes{0.3.0}{2022/10/30}{New counter for protecting lineno.}
802 % Then, we define an internal counter to protect line number from changing:
803 % \begin{macrocode}
804 \makeatletter\newcounter{eolang@lineno}\makeatother
805 % \end{macrocode}
806 % \end{macro}
807
808 % \begin{macro}{\eolang@mdfive}
809 % \changes{0.1.0}{2022/10/26}{New supplementary command added to calculate MD5 sum of a file.}
810 % Then, we define a command for MD5 hash calculating of a file:
811 % \begin{macrocode}
812 \RequirePackage{pdftexcmds}
813 \makeatletter
814 \newcommand\eolang@mdfive[1]{\pdf@filemdfivesum{#1}}
815 \makeatother
816 % \end{macrocode}
817 % \end{macro}
818
819 % \begin{macro}{-phi.pl}
820 % \changes{0.0.2}{2022/10/21}{The symbols ``\texttt{[}'' and ``\texttt{]}'' replaced with ``\texttt{[[}'' and ``\texttt{]]}'' for abstract object brackets, because they conflicted with normal square brackets}
821 % \changes{0.0.2}{2022/10/21}{New symbol added for basket slots}
822 % \changes{0.0.2}{2022/10/21}{Parsing of the symbols ``\texttt{@},'' ``\texttt{\^{}},'' and ``\texttt{\&}'' enabled (\texttt{\char`\\varphi}, \texttt{\char`\\rho}, and \texttt{\char`\\sigma})}
823 % \changes{0.1.0}{2022/10/26}{A new Perl script "\texttt{eolang-phi.pl}" added for parsing of phi expressions.}
824 % \changes{0.2.0}{2022/10/29}{Numbers automatically render as \texttt{\char`\\texttt}. No need to use vertical bars around them anymore.}
825 % \changes{0.3.0}{2022/10/30}{New arrow added, that looks like \texttt{\char`\\leadsto}.}
826 % \changes{0.5.0}{2022/11/11}{Automated formatting of \texttt{TRUE} and \texttt{FALSE} added.}
827 % \changes{0.5.0}{2022/11/13}{A new syntax introduced for the \texttt{\char`\\alpha} attributes: \texttt{0->}.}
828 % \changes{0.5.0}{2022/11/14}{It's possible to use double names for attributes, such as \texttt{0/g->}.}
829 % \changes{0.7.0}{2022/11/17}{Object names are automatically converted to \texttt{\char`\\texttt}, provided their names include two or more symbols.}
830 % \changes{0.7.0}{2022/11/17}{Text in quotes is automatically converted to \texttt{\char`\\texttt}.}
831 % \changes{0.7.0}{2022/11/17}{New syntax sugar constructs added: \texttt{D>} and \texttt{L>} for \texttt{\char`\\Delta} and \texttt{\char`\\lambda} with a dotted arrow respectively.}
832 % \changes{0.7.0}{2022/11/18}{New syntax sugar for $\Phi$, just using capital ``\texttt{Q}'' is enough.}
833 % \changes{0.8.0}{2022/11/21}{Inside \texttt{phiquation} any text inside the \texttt{\char`\\text} macro is not processed.}
834 % \changes{0.9.0}{2022/12/15}{Proper handling of the \texttt{matrix} environment.}
835 % \changes{0.9.0}{2022/12/15}{Parsing of \texttt{<<} and \texttt{>>} implemented.}
836 % \changes{0.10.0}{2023/01/22}{Parsing of \texttt{==} into \texttt{\char`\\equiv} implemented.}
837 % \changes{0.13.0}{2023/06/28}{Parsing of \texttt{QQ} into \texttt{\char`\\dot\{\char`\\Phi\}} implemented.}
838 % \changes{0.19.0}{2025/09/29}{Parsing of \texttt{T} into \texttt{\char`\\bot} implemented.}
839 % \changes{0.20.0}{2025/11/05}{Parsing of \texttt{~0} into \texttt{\char`\\alpha\_0} implemented.}
840 % \changes{0.20.2}{2025/11/24}{Formatting of numbers fixed, now it works in any place inside an expression.}
841 % \changes{0.21.0}{2025/12/15}{Automated formatting of \texttt{TRUE} and \texttt{FALSE} removed.}
842 % \changes{0.22.0}{2025/12/17}{Automated formatting of \texttt{D} and \texttt{L} added.}
843 % \changes{0.23.0}{2023/12/25}{Parsing of \texttt{QQ} into \texttt{\char`\\dot\{\char`\\Phi\}} removed.}
844 % Then, we create a Perl script for |phiquation| processing using |VerbatimOut| environment from
845 % \href{https://ctan.org/pkg/fancyvrb}{fancyvrb}:
846 % \begin{macrocode}
847 \makeatletter
848 \ifdefined\eolang@noshell
849 \message{eolang: Perl script is not going to be created,
850 at "\eolang@tmpdir/\jobname-phi.pl" because of the "noshell"
851 package option^^J}
852 \else
853 \openin 15=\eolang@tmpdir/\jobname-phi.pl
854 \ifeof 15
855 \message{eolang: Perl script is going to be created,
856 because it is absent at "\eolang@tmpdir/\jobname-phi.pl",
857 but if -shell-escape is not set, the compilation will
858 most likely fail now^^J}
859 \begin{VerbatimOut}{\eolang@tmpdir/\jobname-phi.pl}
860 $macro = $ARGV[0];
861 open(my $fh, '<', $ARGV[1]);
862 my $tex; { local $/; $tex = <$fh>; }
863 print "% This file is auto-generated by eolang.sty 0.23.0\n";
864 print '% There are ', length($tex),
865 ' chars in the input: ', $ARGV[1], "\n";
866 print '% ---', "\n";
867 if (index($tex, "\t") >= 0) {
868 print "TABS are prohibited!";
869 exit 1;
870 }
871 my @lines = split (/\n/g, $tex);
872 foreach my $t (@lines) {
873 print '% ', $t, "\n";
874 }
875 print '% ---', "\n";
876 $tex =~ s/(?<!\\)%.*\n/\n/g;
877 $tex =~ s/^\s+|\s+$//g;
878 my $splitting = $tex =~ /^\\begin\{split\}/;
879 if ($splitting) {
880 print '% The manual splitting mode is ON since \begin{split} started the text' . "\n";
881 }
882 my $indents = $tex =~ /\n +/g;
883 my $gathered = (0 == $indents);
884 if ($gathered) {
885 if ($splitting) {
886 print '% The "gathered" is NOT used because of manual splitting' . "\n";
887 $gathered = 0;
888 } else {
889 print '% The "gathered" is used since all lines are left-aligned' . "\n";
890 }
891 } else {
892 print '% The "gathered" is NOT used because ' .
893 $indents . " lines are indented\n";
894 }
895 my $align = 0;
896 print '% The "align" is NOT used by default' . "\n";
897 if (index($tex, '&&') >= 0) {
898 $macro =~ s/equation/align/g;
899 $align = 1;
900 print '% The "align" is used because of && seen in the text' . "\n";
901 }
902 if ($macro ne 'phiq') {
903 if (not $splitting) {
904 $tex =~ s/\\\\\n/\n\n/g;
905 $tex =~ s/\\\n\s*//g;
906 }
907 $tex =~ s/\n*(\\label\{[^\}]+\})\n*/\1/g;
908 $tex =~ s/\n{3,}/\n\n/g;
909 }
910 my @texts = ();
911 sub trep {
912 my ($s) = @_;
913 my $open = 0;
914 my $p = 0;
915 for (; $p < length($s); $p++) {
916 $c = substr($s, $p, 1);
917 if ($c eq '}') {
918 if ($open == 0) {
919 last;
920 }
921 $open--;
922 }
923 if ($c eq '{') {
924 $open++;
925 }
926 }
927 push(@texts, substr($s, 0, $p));
928 return '{TEXT' . (0+@texts - 1) . '}' . substr($s, $p + 1);
929 }
930 $tex =~ s/\\text\{(.+)/trep("$1")/ge;
931 $tex =~ s/(?<=[\s,>(])([0-9A-F]{2}(?:-[0-9A-F]{2})+)(?!\{)/|\1|/g;
932 $tex =~ s/(?<=[\s,>(])([0-9]+(?:\.[0-9]+)?)(?!\{)/|\1|/g;
933 $tex =~ s/([^\\{a-zA-Z0-9\\\{]|^)Q(?![a-zA-Z0-9])/\1 \\phiTerminal{\\Phi{}}/g;
934 $tex =~ s/([^\\{a-zA-Z0-9\\\{]|^)T(?![a-zA-Z0-9])/\1 \\phiTerminal{\\bot{}}/g;
935 $tex =~ s/([^\\{a-zA-Z0-9\\\{]|^)D>/\1\\phiTerminal{\\Delta{}} ..>/g;
936 $tex =~ s/([^\\{a-zA-Z0-9\\\{]|^)L>/\1\\phiTerminal{\\lambda{}} ..>/g;
937 $tex =~ s/([^\\{a-zA-Z0-9\\\{]|^)D(?![a-zA-Z0-9\\])/\1\\phiTerminal{\\Delta{}}/g;
938 $tex =~ s/([^\\{a-zA-Z0-9\\\{]|^)L(?![a-zA-Z0-9\\])/\1\\phiTerminal{\\lambda{}}/g;
939 $tex =~ s/"([^"]+)"/|"\1"|/g;
940 $tex =~ s/(?:^|(?<=[\s)(\]\[,.>\/]))([a-zA-Z][a-zA-Z0-9]+)(?=[\s)(\]\[,.-]|$)/|\1|/g;
941 $tex =~ s/([^_^]|^)([0-9]+|\*)\/(\\?[a-z]+|\|[a-z]+\|)
942 (->|\.\.>|~>|:=)/\1\\alpha_{\2}\\vert{}\3\\space{}\4/xg;
943 if ($macro ne 'phiq') {
944 if (not $splitting) {
945 $tex =~ s/\\begin\{split\}\n/\\begin{split}&/g;
946 $tex =~ s/\n\s*\\end\{split\}/\\end{split}/g;
947 $tex =~ s/\n\n/\\\\&/g;
948 $tex =~ s/\n/\\phiEOL{}\n&/g;
949 $tex =~ s/\\\\$//g;
950 $tex =~ s/\\\\/\\\\\n/g;
951 $tex =~ s/([^&\s])\s{2}([^\s])/\1 \2/g;
952 $tex =~ s/\s{2}/ \\quad{}/g;
953 $tex = '&' . $tex;
954 }
955 my $lead = '[^\s]+\s(?:->|:=|=|==)\s';
956 my @leads = $tex =~ /&${lead}/g;
957 my @eols = $tex =~ /&/g;
958 if (0+@leads == 0+@eols && 0+@eols > 1) {
959 $tex =~ s/&(${lead})/\1&~/g;
960 $gathered = 0;
961 print '% The "gathered" is NOT used because all ' .
962 (0+@eols) . ' lines are ' . (0+@leads) . " leads\n";
963 }
964 }
965 if ($macro ne 'phiq') {
966 sub strip_tabs {
967 my ($env, $tex) = @_;
968 $tex =~ s/&//g;
969 return "\\begin{$env}" . $tex . "\\end{$env}";
970 }
971 foreach my $e (('matrix', 'cases')) {
972 $tex =~ s/\\begin\{(\Q$e\E\*?)\}(.+)\\end\{\Q$e\E\*?\}/strip_tabs($1, $2)/sge;
973 }
974 }
975 $tex =~ s/\$/\\phiTerminal{\\xi{}}/g;
976 $tex =~ s/(?<!\{)\^(?!\{)/\\phiTerminal{\\rho{}}/g;
977 $tex =~ s/\[\[/\\phiTerminal{\\llbracket}/g;
978 $tex =~ s/\]\]/\\phiTerminal{\\rrbracket{}}/g;
979 $tex =~ s/\?/\\phiTerminal{\\varnothing{}}/g;
980 $tex =~ s/@/\\phiTerminal{\\varphi{}}/g;
981 $tex =~ s/-([a-z]+)>/\\mathrel{\\phiSlot{\1}}/g;
982 $tex =~ s/->/\\mathbin{\\phiTerminal{\\mapsto}}/g;
983 $tex =~ s/~>/\\mathbin{\\phiWave}/g;
984 $tex =~ s/:=/\\mathrel{\\vDash}/g;
985 $tex =~ s/==/\\mathrel{\\equiv}/g;
986 $tex =~ s/\.\.>/\\mathbin{\\phiTerminal{\\phiDotted}}/g;
987 $tex =~ s/~([0-9]+)/\\phiTerminal{\\alpha_{\1}}/g;
988 $tex =~ s/<</\\langle/g;
989 $tex =~ s/>>/\\rangle/g;
990 $tex =~ s/(?<![\\\{])([)(.])/\\phiTerminal{\1}/g;
991 $tex =~ s/(?<![\\\{]),/\\phiTerminal{,}\\;/g;
992 $tex =~ s/\|{2,}/|/g;
993 $tex =~ s/\|([^\|]+)\|/\\textnormal{\\texttt{\1}}{}/g;
994 $tex =~ s/\{TEXT(\d+)\}/'\\text{' . $texts[$1] . '}';/ge;
995 if ($macro eq 'phiq') {
996 print '\(' if ($tex ne '');
997 } else {
998 print '\begin{', $macro, "}\n";
999 if (not($align)) {
1000 if ($gathered) {
1001 print '\begin{gathered}' . "\n";
1002 } elsif (not $splitting) {
1003 print '\begin{split}' . "\n";
1004 }
1005 }
1006 }
1007 if ($gathered and not($align)) {
1008 $tex =~ s/^&//g;
1009 $tex =~ s/\n&/\n/g;
1010 }
1011 print $tex;
1012 if ($macro eq 'phiq') {
1013 print '\)' if ($tex ne '');
1014 } else {
1015 if (not($align)) {
1016 if ($gathered) {
1017 print "\n" . '\end{gathered}';
1018 } elsif (not $splitting) {
1019 print "\n" . '\end{split}';
1020 }
1021 }
1022 print "\n" . '\end{' . $macro . '}';
1023 }
1024 print '\endinput';
1025 \end{VerbatimOut}
1026 \message{eolang: File with Perl script
1027 '\eolang@tmpdir/\jobname-phi.pl' saved^^J}
1028 \else
1029 \message{eolang: Perl script already exists at
1030 "\eolang@tmpdir/\jobname-phi.pl"^^J}
1031 \fi
1032 \closein 15
1033 \fi
1034 \makeatother
1035 % \end{macrocode}
1036 % \end{macro}
1037
1038 % \begin{macro}{\phiSaveTo}
1039 % \changes{0.8.0}{2022/11/20}{The output of the \texttt{phiquation} environment can be redirected to a file.}
1040 % Then, we define the |\phiSaveTo| command to instruct the |phiquation| environment that the output should not be sent to the document but saved to the file instead:
1041 % \begin{macrocode}
1042 \makeatletter
1043 \newcommand\phiSaveTo[1]{\def\eolang@phiSaveTo{#1}}
1044 \makeatother
1045 % \end{macrocode}
1046 % \end{macro}
1047
1048 % \begin{macro}{\eolang@tmp}
1049 % \changes{0.18.3}{2025/03/26}{A new supplementary \texttt{eolang@tmp} command added, to generate temporary file names.}
1050 % Then, we define the |\eolang@tmp| command, which generates temporary file names:
1051 % \begin{macrocode}
1052 \makeatletter
1053 \newcommand\eolang@tmp[1]{#1\ifxetex-xe\else\ifluatex-lua\fi\fi.tex}
1054 \makeatother
1055 % \end{macrocode}
1056 % \end{macro}
1057
1058 % \begin{macro}{\eolang@ifabsent}
1059 % \changes{0.17.0}{2023/12/28}{A new supplementary \texttt{eolang@ifabsent} command added}
1060 % \changes{0.18.0}{2024/01/09}{The \texttt{noshell} package option added in order to enable complete prohibition of shell interactions.}
1061 % Then, we define the |\eolang@ifabsent| command, which if a given file is absent, runs a processing command, otherwise just inputs it:
1062 % \begin{macrocode}
1063 \makeatletter
1064 \newcommand\eolang@ifabsent[2]{%
1065 \IfFileExists
1066 {#1}
1067 {%
1068 \message{eolang: File "#1" already exists ^^J}%
1069 \input{#1}}
1070 {%
1071 \ifdefined\eolang@noshell%
1072 \message{eolang: Shell processing is disabled^^J}%
1073 \else%
1074 \ifnum\ShellEscapeStatus=1\else%
1075 \message{eolang: The -shell-escape command line
1076 option is not provided, most probably compilation
1077 will fail now:^^J}%
1078 \fi%
1079 #2%
1080 \fi%
1081 }%
1082 }
1083 \makeatother
1084 % \end{macrocode}
1085 % \end{macro}
1086
1087 % \begin{macro}{phiquation}
1088 % \changes{0.16.0}{2023/12/27}{The processing of \texttt{phiquation} data is done only if it's the first time processing, otherwise cache is used, thus making processing faster.}
1089 % Then, we define the |phiquation| and the |phiquation*| environments through a supplementary
1090 % |\eolang@process| command:
1091 % \begin{macrocode}
1092 \makeatletter\newcommand\eolang@process[1]{
1093 \def\hash{\eolang@mdfive
1094 {\eolang@tmpdir/\jobname/\eolang@tmp{phiquation}}-\the\inputlineno}%
1095 \eolang@ifabsent
1096 {\eolang@tmpdir/\jobname/\eolang@tmp{\hash-phiquation-post}}
1097 {%
1098 \iexec[null]{cp "\eolang@tmpdir/\jobname/\eolang@tmp{phiquation}"
1099 "\eolang@tmpdir/\jobname/\eolang@tmp{\hash-phiquation}"}%
1100 \message{Start parsing 'phi' at line no. \the\inputlineno^^J}
1101 \iexec[trace,stdout=\eolang@tmpdir/\jobname/\eolang@tmp{\hash-phiquation-post}]{
1102 perl "\eolang@tmpdir/\jobname-phi.pl"
1103 '#1'
1104 "\eolang@tmpdir/\jobname/\eolang@tmp{\hash-phiquation}"
1105 \ifdefined\eolang@nocomments | perl -pe 's/\%.*(\\n|$)//g'\fi
1106 \ifdefined\eolang@phiSaveTo > \eolang@phiSaveTo\fi}%
1107 }%
1108 \setcounter{FancyVerbLine}{\value{eolang@lineno}}%
1109 \def\eolang@phiSaveTo{\relax}%
1110 }
1111 %
1112 \newenvironment{phiquation*}%
1113 {\catcode`\|=12 \VerbatimEnvironment%
1114 \setcounter{eolang@lineno}{\value{FancyVerbLine}}%
1115 \begin{VerbatimOut}
1116 {\eolang@tmpdir/\jobname/\eolang@tmp{phiquation}}}
1117 {\end{VerbatimOut}\eolang@process{equation*}}
1118 %
1119 \newenvironment{phiquation}%
1120 {\catcode`\|=12 \VerbatimEnvironment%
1121 \setcounter{eolang@lineno}{\value{FancyVerbLine}}%
1122 \begin{VerbatimOut}
1123 {\eolang@tmpdir/\jobname/\eolang@tmp{phiquation}}}
1124 {\end{VerbatimOut}\eolang@process{equation}}
1125 \makeatother
1126 % \end{macrocode}
1127 % \end{macro}
1128
1129 % \begin{macro}{\phiq}
1130 % \changes{0.0.2}{2022/10/21}{Parsing of additional symbols enabled.}
1131 % Then, we define |\phiq| command:
1132 % \begin{macrocode}
1133 \RequirePackage{xstring}
1134 \makeatletter\newcommand\phiq[1]{%
1135 \StrSubstitute{\detokenize{#1}}{'}{'"'"'}[\clean]%
1136 \def\hash{\pdf@mdfivesum{\clean}-\the\inputlineno}%
1137 \ifdefined\eolang@nodollar\else\catcode`\$=3 \fi%
1138 \eolang@ifabsent
1139 {\eolang@tmpdir/\jobname/\eolang@tmp{\hash-phiq-post}}
1140 {%
1141 \iexec[log,trace,quiet,stdout=\eolang@tmpdir/\jobname/\eolang@tmp{phiq}]{
1142 printf '\%s' '\clean'}%
1143 \iexec[quiet,null]{cp "\eolang@tmpdir/\jobname/\eolang@tmp{phiq}"
1144 "\eolang@tmpdir/\jobname/\eolang@tmp{\hash-phiq}"}%
1145 \iexec[trace,stdout=\eolang@tmpdir/\jobname/\eolang@tmp{\hash-phiq-post}]{
1146 perl \eolang@tmpdir/\jobname-phi.pl 'phiq'
1147 "\eolang@tmpdir/\jobname/\eolang@tmp{\hash-phiq}"
1148 \ifdefined\eolang@nocomments | perl -pe 's/\%.*(\\n|$)//g' \fi}%
1149 \message{eolang: Parsed `phiq' at line no. \the\inputlineno^^J}%
1150 }%
1151 \ifdefined\eolang@nodollar\else\catcode`\$\active\fi%
1152 }\makeatother
1153 % \end{macrocode}
1154 % \end{macro}
1155
1156 % \begin{macro}{nodollar}
1157 % \changes{0.7.0}{2022/11/18}{Now it is possible to use dollar sign instead of the \texttt{\char`\\phiq} command.}
1158 % Then, we redefine dollar sign:
1159 % \begin{macrocode}
1160 \ifdefined\eolang@nodollar\else
1161 \begingroup
1162 \catcode`\$=\active
1163 \protected\gdef$#1${\phiq{#1}}
1164 \endgroup
1165 \AtBeginDocument{\catcode`\$=\active}
1166 \fi
1167 % \end{macrocode}
1168 % \end{macro}
1169
1170 % \begin{macro}{-sodg.pl}
1171 % \changes{0.0.2}{2022/10/24}{The Perl file now has a fixed name, which doesn't depend on the name of the TeX job. This file may be shared among jobs, no need to make it uniquely named.}
1172 % \changes{0.1.0}{2022/10/26}{There are two Perl scripts now: one for \texttt{phiquation}, another one for \texttt{sodg}.}
1173 % \changes{0.2.0}{2022/10/28}{The content of the \texttt{atom} and the \texttt{data} boxes is parsed automatically as formulas and numbers, respectively.}
1174 % \changes{0.4.0}{2022/10/31}{Labels on the edges are automatically printed as math formulas. Also, boxes are prefixed with the \texttt{\char`\\Delta} and the \texttt{\char`\\lambda} commands.}
1175 % \changes{0.4.0}{2022/10/31}{Relative positioning of vertices fixed.}
1176 % \changes{0.4.0}{2022/10/31}{Transforming arrows added with the \texttt{=>} syntax, also markers with exclamation mark syntax.}
1177 % \changes{0.5.0}{2022/11/09}{New syntax introduced that allows to make clones of vertices and all their dependants.}
1178 % \changes{0.5.0}{2022/11/09}{Now edges may have the \texttt{break} attribute, to make them shorter.}
1179 % \changes{0.5.0}{2022/11/10}{It is possible to use multiple ``equation sign'' symbols for transition arrows \texttt{=>}.}
1180 % \changes{0.5.0}{2022/11/12}{It is possible to use TikZ commands inside the \texttt{sodg} environment.}
1181 % \changes{0.6.0}{2022/11/13}{The \texttt{rrho} attribute is retired, now \texttt{rho} works just fine in all situations.}
1182 % \changes{0.8.0}{2022/11/20}{The \texttt{tag} attribute is introduced for changing labels inside a vertex circle.}
1183 % \changes{0.12.1}{2023/03/01}{The bug is fixed related to the formatting of indexes of vertices.}
1184 % \changes{0.14.0}{2023/07/26}{The \texttt{edgeless} tag of a vertex removes the border of it.}
1185 % \changes{0.15.0}{2023/08/21}{The \texttt{style} tag of vertices and edges.}
1186 % Then, we create a Perl script for |sodg| graphs processing using |VerbatimOut| from
1187 % \href{https://ctan.org/pkg/fancyvrb}{fancyvrb}:
1188 % \begin{macrocode}
1189 \makeatletter
1190 \ifdefined\eolang@noshell
1191 \message{eolang: Perl script is not going to be created
1192 at "\eolang@tmpdir/\jobname-sodg.pl", because of the
1193 "noshell" package option^^J}
1194 \else
1195 \openin 15=\eolang@tmpdir/\jobname-sodg.pl
1196 \ifeof 15
1197 \message{eolang: Perl script is going to be created,
1198 because it is absent at "\eolang@tmpdir/\jobname-sodg.pl",
1199 but if -shell-escape is not set, the compilation will
1200 most likely fail now^^J}
1201 \begin{VerbatimOut}{\eolang@tmpdir/\jobname-sodg.pl}
1202 sub num {
1203 my ($i) = @_;
1204 $i =~ s/(\+|-)\./\10./g;
1205 return $i;
1206 }
1207 sub fmt {
1208 my ($tex) = @_;
1209 $tex =~ s/\|([^\|]+)\|/\\textnormal{\\texttt{\1}}/g;
1210 return $tex;
1211 }
1212 sub toem {
1213 my ($cm) = @_;
1214 return $cm * 2.8;
1215 }
1216 sub vertex {
1217 my ($v) = @_;
1218 if (index($v, 'v0') == 0) {
1219 return '\Phi';
1220 } else {
1221 $v =~ s/^v/v_{/g;
1222 $v =~ s/[^0-9]$//g;
1223 return $v . '}';
1224 }
1225 }
1226 sub tailor {
1227 my ($t, $m) = @_;
1228 $t =~ s/<([A-Z]?${m}[A-Z]?):([^>]+)>/\2/g;
1229 $t =~ s/<[A-Z]+:[^>]+>//g;
1230 return $t;
1231 }
1232 open(my $fh, '<', $ARGV[0]);
1233 my $tex; { local $/; $tex = <$fh>; }
1234 if (index($tex, "\t") >= 0) {
1235 print "TABS are prohibited!";
1236 exit 1;
1237 }
1238 print '% This file is auto-generated', "\n%\n";
1239 print '% --- there are ', length($tex),
1240 ' chars in the input (', $ARGV[0], "):\n";
1241 foreach my $t (split (/\n/g, $tex)) {
1242 print '% ', $t, "\n";
1243 }
1244 print "% ---\n";
1245 $tex =~ s/\\\\/\n/g;
1246 $tex =~ s/\\\n//g;
1247 $tex =~ s/(\\[a-zA-Z]+)\s+/\1/g;
1248 $tex =~ s/\n{2,}/\n/g;
1249 my @cmds = split(/\n/g, $tex);
1250 print '% --- before processing:' . "\n";
1251 foreach my $t (split (/\n/g, $tex)) {
1252 print '% ', $t, "\n";
1253 }
1254 print '% ---';
1255 print ' (' . (0+@cmds) . " lines)\n";
1256 print '\begin{phicture}', "\n";
1257 for (my $c = 0; $c < 0+@cmds; $c++) {
1258 my $cmd = $cmds[$c];
1259 $cmd =~ s/^\s+//g;
1260 $cmd =~ s/(?<!\\)%.*//g;
1261 my ($head, $tail) = split(/ /, $cmd, 2);
1262 my %opts = ();
1263 my ($body, $style) = split(/style:/, $tail, 2);
1264 $opts{'style'} = $style;
1265 $tail = $body;
1266 foreach my $p (split(/ /, $tail)) {
1267 my ($q, $t) = split(/:/, $p);
1268 $opts{$q} = $t;
1269 }
1270 if (index($head, '\\') == 0) {
1271 print $cmd;
1272 } elsif (index($head, '->') >= 0) {
1273 my $draw = '\draw[';
1274 if (exists $opts{'pi'}) {
1275 $draw = $draw . '<MB:phi-pi><F:draw=none>';
1276 if (not exists $opts{'a'}) {
1277 $opts{'a'} = '\pi';
1278 }
1279 }
1280 if (exists $opts{'rho'} and not(exists $opts{'bend'})) {
1281 $draw = $draw . '<MB:,phi-rho>';
1282 }
1283 $draw = $draw . ',' . $opts{'style'} . ']';
1284 my ($from, $to) = split (/->/, $head);
1285 $draw = $draw . " (${from}) ";
1286 if (exists $opts{'bend'}) {
1287 $draw = $draw . 'edge [<F:draw=none><MF:,bend right=' .
1288 num($opts{'bend'}) . '>';
1289 if (exists $opts{'rho'}) {
1290 $draw = $draw . '<MB:,phi-rho>';
1291 }
1292 $draw = $draw . ']';
1293 } else {
1294 $draw = $draw . '--';
1295 }
1296 if (exists $opts{'a'}) {
1297 my $a = $opts{'a'};
1298 if (index($a, '$') == -1) {
1299 $a = '$' . fmt($a) . '$';
1300 } else {
1301 $a = fmt($a);
1302 }
1303 $draw = $draw . '<MB: node [phi-attr] {' . $a . '}>';
1304 }
1305 if (exists $opts{'break'}) {
1306 $draw = $draw . '<F: coordinate [pos=' .
1307 ($opts{'break'} / 100) . '] (break)>';
1308 }
1309 $draw = $draw . " (<MF:${to}><B:break-v>)";
1310 if (exists $opts{'break'}) {
1311 print tailor($draw, 'F') . ";\n";
1312 print ' \node[outer sep=' . toem(0.1) . 'em,inner sep=0em] ' .
1313 'at (break) (break-v) {$' . vertex($to) .
1314 '$};' . "\n";
1315 print ' ' . tailor($draw, 'B');
1316 } else {
1317 print tailor($draw, 'M');
1318 }
1319 } elsif (index($head, '=>') >= 0) {
1320 my ($from, $to) = split (/=+>/, $head);
1321 my $size = () = $head =~ /=/g;
1322 if ($from eq '') {
1323 print '\node [phi-arrow, left=' . toem($size * 0.6) . 'em of ' .
1324 $to . '.center]';
1325 } elsif ($to eq '') {
1326 print '\node [phi-arrow, right=' . toem($size * 0.6) . 'em of ' .
1327 $from . '.center]';
1328 } else {
1329 print '\node [phi-arrow] at ($(' .
1330 $from . ')!0.5!(' . $to . ')$)';
1331 }
1332 print '{}';
1333 } elsif (index($head, '!') >= 0) {
1334 my ($v, $marker) = split (/!+/, $head);
1335 my $size = () = $head =~ /!/g;
1336 print '\node [phi-marker, left=' .
1337 toem($size * 0.6) . 'em of ' .
1338 $v . '.center]{' . fmt($marker) . '}';
1339 } elsif (index($head, '+') >= 0) {
1340 my ($v, $suffix) = split (/\+/, $head);
1341 my @friends = ($v);
1342 foreach my $c (@cmds) {
1343 $e = $c;
1344 $e =~ s/^\s+//g;
1345 my $h = $e;
1346 $h = substr($e, 0, index($e, ' ')) if index($e, ' ') >= 0;
1347 foreach my $f (@friends) {
1348 my $add = '';
1349 if (index($h, $f . '->') >= 0) {
1350 $add = substr($h, index($h, '->') + 2);
1351 }
1352 if ($h =~ /->\Q${f}\E$/) {
1353 $add = substr($h, 0, index($h, '->'));
1354 }
1355 if (index($e, ' xy:' . $f . ',') >= 0) {
1356 $add = $h;
1357 }
1358 if (index($add, '+') == -1
1359 and $add ne ''
1360 and not(grep(/^\Q${add}\E$/, @friends))) {
1361 push(@friends, $add);
1362 }
1363 }
1364 }
1365 my @extra = ();
1366 foreach my $e (@cmds) {
1367 $m = $e;
1368 if ($m =~ /^\s*\Q${v}\E\s/) {
1369 next;
1370 }
1371 if ($m =~ /^\s*[^\s]+\+/ and not($m =~ /^\s*\Q${head}\E\s/)) {
1372 next;
1373 }
1374 foreach my $f (@friends) {
1375 my $h = $f;
1376 $h =~ s/[a-z]$//g;
1377 if ($m =~ s/^(\s*)\Q${f}\E\+\Q${suffix}\E\s?/\1${h}${suffix} /g) {
1378 last;
1379 }
1380 $m =~ s/^(\s*)\Q${f}\E\s/\1${h}${suffix} /g;
1381 $m =~ s/^(\s*)\Q${f}\E->/\1${h}${suffix}->/g;
1382 $m =~ s/\sxy:\Q${f}\E,/ xy:${h}${suffix},/g;
1383 $m =~ s/->\Q${f}\E\s/->${h}${suffix} /g;
1384 }
1385 if ($m ne $e) {
1386 push(@extra, ' ' . $m);
1387 }
1388 }
1389 splice(@extra, 0, 0, $extra[-1]);
1390 splice(@extra, -1, 1);
1391 splice(@extra, 0, 0, '% clone of ' . $v . ' (' . $head .
1392 '), friends: [' . join(', ', @friends) . '] in ' .
1393 (0+@cmds) . ' lines');
1394 splice(@cmds, $c, 1, @extra);
1395 print '% cloned ' . $v . ' at line no.' . $c .
1396 ' (+' . (0+@extra) . ' lines -> ' .
1397 (0+@cmds) . ' lines total)';
1398 } elsif ($head =~ /^v[0-9]+[a-z]?$/) {
1399 print '\node[';
1400 if (exists $opts{'xy'}) {
1401 my ($v, $right, $down) = split(/,/, $opts{'xy'});
1402 my $loc = '';
1403 if ($down > 0) {
1404 $loc = 'below ';
1405 } elsif ($down < 0) {
1406 $loc = 'above ';
1407 }
1408 if ($right > 0) {
1409 $loc = $loc . 'right';
1410 } elsif ($right < 0) {
1411 $loc = $loc . 'left';
1412 }
1413 print ',' . $loc . '=';
1414 print toem(abs(num($down))) . 'em and ' .
1415 toem(abs(num($right))) . 'em of ' . $v . '.center';
1416 }
1417 if (exists $opts{'data'}) {
1418 print ',phi-data';
1419 if ($opts{'data'} ne '') {
1420 my $d = $opts{'data'};
1421 if (index($d, '|') == -1) {
1422 $d = '$\Delta\phiDotted\text{' .
1423 '\textnormal{\texttt{' . fmt($d) . '}}}$';
1424 } else {
1425 $d = fmt($d);
1426 }
1427 $opts{'box'} = $d;
1428 }
1429 } elsif (exists $opts{'atom'}) {
1430 print ',phi-atom';
1431 if ($opts{'atom'} ne '') {
1432 my $a = $opts{'atom'};
1433 if (index($a, '$') == -1) {
1434 $a = '$\lambda\phiDotted{}' . fmt($a) . '$';
1435 } else {
1436 $a = fmt($a);
1437 }
1438 $opts{'box'} = $a;
1439 }
1440 } else {
1441 print ',phi-object';
1442 }
1443 if (exists $opts{'edgeless'}) {
1444 print ',draw=none';
1445 }
1446 print ',' . $opts{'style'} . ']';
1447 print ' (' . $head . ')';
1448 print ' {';
1449 if (exists $opts{'tag'}) {
1450 my $t = $opts{'tag'};
1451 if (index($t, '$') == -1) {
1452 $t = '$' . $t . '$';
1453 } else {
1454 $t = fmt($t);
1455 }
1456 print $t;
1457 } else {
1458 print '$' . vertex($head) . '$';
1459 }
1460 print '}';
1461 if (exists $opts{'box'}) {
1462 print ' node[phi-box] at (';
1463 print $head, '.south east) {';
1464 print $opts{'box'}, '}';
1465 }
1466 }
1467 print ";\n";
1468 }
1469 print '\end{phicture}%', "\n";
1470 print "% --- after processing:\n%";
1471 foreach my $c (@cmds) {
1472 print '% ', $c, "\n";
1473 }
1474 print '% --- (' . (0+@cmds) . " lines)\n";
1475 print '\endinput';
1476 \end{VerbatimOut}
1477 \message{eolang: File with Perl script
1478 '\eolang@tmpdir/\jobname-sodg.pl' saved^^J}
1479 \else
1480 \message{eolang: Perl script already exists at
1481 "\eolang@tmpdir/\jobname-sodg.pl"^^J}
1482 \fi
1483 \closein 15
1484 \fi
1485 \makeatother
1486 % \end{macrocode}
1487 % \end{macro}
1488
1489 % \begin{macro}{FancyVerbLine}
1490 % Then, we reset the counter for \href{https://ctan.org/pkg/fancyvrb}{fancyvrb}, so that
1491 % it starts counting lines from zero when the document starts rendering:
1492 % \begin{macrocode}
1493 \setcounter{FancyVerbLine}{0}
1494 % \end{macrocode}
1495 % \end{macro}
1496
1497 % \begin{macro}{tikz}
1498 % Then, we include \href{https://ctan.org/pkg/tikz}{tikz} package and its libraries:
1499 % \begin{macrocode}
1500 \RequirePackage{tikz}
1501 \usetikzlibrary{arrows}
1502 \usetikzlibrary{shapes}
1503 \usetikzlibrary{decorations}
1504 \usetikzlibrary{decorations.pathmorphing}
1505 \usetikzlibrary{decorations.pathreplacing}
1506 \usetikzlibrary{positioning}
1507 \usetikzlibrary{calc}
1508 \usetikzlibrary{math}
1509 \usetikzlibrary{arrows.meta}
1510 % \end{macrocode}
1511 % \end{macro}
1512
1513 % \begin{macro}{phicture}
1514 % Then, we define internal environment |phicture|:
1515 % \begin{macrocode}
1516 \newenvironment{phicture}%
1517 {\noindent\begin{tikzpicture}[
1518 ->,>=stealth',node distance=0,line width=.08em,
1519 pics/parallel arrow/.style={
1520 code={\draw[-latex,phi-rho] (##1) -- (-##1);}}]}%
1521 {\end{tikzpicture}}
1522 \tikzstyle{phi-arrow} = [fill=white!80!black, single arrow,
1523 minimum height=0.05em, minimum width=0.05em,
1524 single arrow head extend=2mm]
1525 \tikzstyle{phi-marker} = [inner sep=0pt, minimum height=1.4em,
1526 minimum width=1.4em, font={\small\color{white}\ttfamily},
1527 fill=gray]
1528 \tikzstyle{phi-thing} = [inner sep=0pt,minimum height=2.4em,
1529 draw,font={\small}]
1530 \tikzstyle{phi-object} = [phi-thing,circle]
1531 \tikzstyle{phi-data} = [phi-thing,regular polygon,
1532 regular polygon sides=8]
1533 \tikzstyle{phi-empty} = [phi-object]
1534 \tikzset{%
1535 phi-rho/.style={
1536 postaction={%
1537 decoration={
1538 show path construction,
1539 curveto code={
1540 \tikzmath{
1541 coordinate \I, \F, \v;
1542 \I = (\tikzinputsegmentfirst);
1543 \F = (\tikzinputsegmentlast);
1544 \v = ($(\I) -(\F)$);
1545 real \d, \a, \r, \t;
1546 \d = 0.8;
1547 \t = atan2(\vy, \vx);
1548 if \vx<0 then { \a = 90; } else { \a = -90; };
1549 {
1550 \draw[arrows={-latex}, decorate,
1551 decoration={%
1552 snake, amplitude=.4mm,
1553 segment length=2mm,
1554 post length=1mm
1555 }]
1556 ($(\F)!.5!(\I) +(\t: -\d em) +(\t +\a: 1ex)$)
1557 -- ++(\t: 2*\d em);
1558 };
1559 }
1560 },
1561 lineto code={
1562 \tikzmath{
1563 coordinate \I, \F, \v;
1564 \I = (\tikzinputsegmentfirst);
1565 \F = (\tikzinputsegmentlast);
1566 \v = ($(\I) -(\F)$);
1567 real \d, \a, \r, \t;
1568 \d = 0.8;
1569 \t = atan2(\vy, \vx);
1570 if \vx<0 then { \a = 90; } else { \a = -90; };
1571 {
1572 \draw[arrows={-latex}, decorate,
1573 decoration={%
1574 snake, amplitude=.4mm,
1575 segment length=2mm,
1576 post length=1mm}]
1577 ($(\F)!.5!(\I) +(\t: -\d em) +(\t +\a: 1ex)$)
1578 -- ++(\t: 2*\d em);
1579 };
1580 }
1581 }
1582 },
1583 decorate
1584 }
1585 }
1586 }
1587 \tikzstyle{phi-pi} = [draw,dotted]
1588 \tikzstyle{phi-atom} = [phi-object,double]
1589 \tikzstyle{phi-box} = [xshift=-5pt,yshift=3pt,draw,fill=white,
1590 rectangle,line width=.04em,minimum width=1.2em,anchor=north west,
1591 font={\scriptsize}]
1592 \tikzstyle{phi-attr} = [midway,sloped,inner sep=0pt,
1593 above=2pt,sloped/.append style={transform shape},
1594 font={\scriptsize},color=black]
1595 % \end{macrocode}
1596 % \end{macro}
1597
1598 % \begin{macro}{\sodgSaveTo}
1599 % \changes{0.8.0}{2022/11/20}{The output of the \texttt{sodg} environment can be redirected to a file.}
1600 % Then, we define the |\sodgSaveTo| command to instruct the |sodg| environment that the output should not be sent to the document but saved to the file instead:
1601 % \begin{macrocode}
1602 \makeatletter
1603 \newcommand\sodgSaveTo[1]{\def\eolang@sodgSaveTo{#1}}
1604 \makeatother
1605 % \end{macrocode}
1606 % \end{macro}
1607
1608 % \begin{macro}{sodg}
1609 % \changes{0.0.2}{2022/10/20}{The environment \texttt{phigure} renamed to \texttt{sodg} for the sake of better semantic. The graph in the picture is solely a SODG graph, that's why the name \texttt{sodg} is better.}
1610 % \changes{0.16.0}{2023/12/27}{The processing of \texttt{sodg} data is done only if it's the first time processing, otherwise cache is used, thus making processing faster.}
1611 % Then, we create a new environment |sodg|, as suggested
1612 % \href{https://tex.stackexchange.com/questions/661056}{here}:
1613 % \begin{macrocode}
1614 \makeatletter\newenvironment{sodg}%
1615 {\catcode`\|=12 \VerbatimEnvironment%
1616 \setcounter{eolang@lineno}{\value{FancyVerbLine}}%
1617 \begin{VerbatimOut}
1618 {\eolang@tmpdir/\jobname/\eolang@tmp{sodg}}}
1619 {\end{VerbatimOut}%
1620 \def\hash{\eolang@mdfive
1621 {\eolang@tmpdir/\jobname/\eolang@tmp{sodg}}-\the\inputlineno}%
1622 \catcode`\$=3 %
1623 \eolang@ifabsent
1624 {\eolang@tmpdir/\jobname/\eolang@tmp{\hash-sodg-post}}
1625 {%
1626 \iexec[null]{cp "\eolang@tmpdir/\jobname/\eolang@tmp{sodg}"
1627 "\eolang@tmpdir/\jobname/\eolang@tmp{\hash-sodg}"}%
1628 \message{eolang: Start parsing `sodg' at line no. \the\inputlineno^^J}
1629 \iexec[trace,stdout=\eolang@tmpdir/\jobname/\eolang@tmp{\hash-sodg-post}]{
1630 perl "\eolang@tmpdir/\jobname-sodg.pl"
1631 "\eolang@tmpdir/\jobname/\eolang@tmp{\hash-sodg}"
1632 \ifdefined\eolang@nocomments | perl -pe 's/\%.*(\\n|$)//g'\fi
1633 \ifdefined\eolang@sodgSaveTo > \eolang@sodgSaveTo\fi}%
1634 }
1635 \catcode`\$\active%
1636 \setcounter{FancyVerbLine}{\value{eolang@lineno}}%
1637 \def\eolang@sodgSaveTo{\relax}%
1638 }\makeatother
1639 % \end{macrocode}
1640 % \end{macro}
1641
1642 % \begin{macro}{\eoAnon}
1643 % Then, we define a supplementary command to help us anonymize some content.
1644 % \changes{0.9.0}{2022/11/29}{New command \texttt{\char`\\eoAnon} added.}
1645 % \begin{macrocode}
1646 \RequirePackage{hyperref}
1647 \pdfstringdefDisableCommands{
1648 \def\({}%
1649 \def\){}%
1650 \def\alpha{alpha}%
1651 \def\varphi{phi}%
1652 }
1653 \makeatletter
1654 \NewExpandableDocumentCommand{\eoAnon}{O{ANONYMIZED}m}{%
1655 \ifdefined\eolang@anonymous%
1656 \textcolor{orange}{#1}%
1657 \else%
1658 #2%
1659 \fi%
1660 }\makeatother
1661 % \end{macrocode}
1662 % \end{macro}
1663
1664 % \begin{macro}{\eolang}
1665 % Then, we define a simple supplementary command to help you print \eolang{}, the name of our language.
1666 % \changes{0.1.0}{2022/10/25}{New command \texttt{\char`\\eolang} added to print the name of the language in both
1667 % normal and the anonymous mode of \texttt{acmart}.}
1668 % \begin{macrocode}
1669 \newcommand\eolang{%
1670 \eoAnon[XYZ]{{\sffamily EO}}}
1671 % \end{macrocode}
1672 % \end{macro}
1673
1674 % \begin{macro}{\phic}
1675 % Then, we define a simple supplementary command to help you print \phic{}, the name of our formal apparatus.
1676 % \changes{0.1.0}{2022/10/25}{New command \texttt{\char`\\phic} prints the name of \phic{} in both
1677 % normal and the anonymous mode of \texttt{acmart}.}
1678 % \begin{macrocode}
1679 \newcommand\phic{%
1680 \eoAnon[\(\alpha\)-cal\-cu\-lus]{\(\varphi\)-cal\-cu\-lus}}
1681 % \end{macrocode}
1682 % \end{macro}
1683
1684 % \begin{macro}{\xmir}
1685 % Then, we define a simple supplementary command to help you print \xmir{}, the name of our XML-based format of program representation.
1686 % \changes{0.2.0}{2022/10/28}{New command \texttt{\char`\\xmir} prints XMIR in both normal and the anonymous mode of \texttt{acmart}.}
1687 % \begin{macrocode}
1688 \newcommand\xmir{%
1689 \eoAnon[XML\(^+\)]{XMIR}}
1690 % \end{macrocode}
1691 % \end{macro}
1692
1693 % \begin{macro}{\phiWave}
1694 % \changes{0.3.0}{2022/10/30}{New command \texttt{\char`\\phiWave} added to denote a link to a multi-layer attribute.}
1695 % Then, we define a command to render an arrow for a multi-layer attribute,
1696 % as suggested \href{https://tex.stackexchange.com/questions/198755}{here}:
1697 % \begin{macrocode}
1698 \newcommand\phiWave{%
1699 \phiTerminal{\mapstochar\mathrel{\mspace{0.45mu}}\leadsto}}
1700 % \end{macrocode}
1701 % \end{macro}
1702
1703 % \begin{macro}{\phiSlot}
1704 % \changes{0.5.0}{2022/11/10}{New command \texttt{\char`\\phiSlot} added to denote a link to a slot in a basket.}
1705 % Then, we define a command to render an arrow for a slot in a basket:
1706 % \begin{macrocode}
1707 \newcommand\phiSlot[1]{%
1708 \xrightarrow{\text{\sffamily\scshape #1}}}
1709 % \end{macrocode}
1710 % \end{macro}
1711
1712 % \begin{macro}{\phiOset}
1713 % \changes{0.8.0}{2022/11/20}{New commands \texttt{\char`\\phiOset} and \texttt{\char`\\phiUset} help position text over and under an arrow.}
1714 % Then, we define two commands to position a text over and under an arrow, as suggested \href{https://tex.stackexchange.com/a/194805/1449}{here}:
1715 % \begin{macrocode}
1716 \makeatletter
1717 \newcommand{\phiOset}[2]{%
1718 \mathrel{\mathop{#2}\limits^{
1719 \vbox to 0ex{\kern-2\ex@
1720 \hbox{$\scriptscriptstyle#1$}\vss}}}}
1721 \newcommand{\phiUset}[2]{%
1722 \mathrel{\mathop{#2}\limits_{
1723 \vbox to 0ex{\kern-6.3\ex@
1724 \hbox{$\scriptscriptstyle#1$}\vss}}}}
1725 \makeatother
1726 % \end{macrocode}
1727 % \end{macro}
1728
1729 % \begin{macro}{\phiMany}
1730 % \changes{0.5.0}{2022/11/10}{New command \texttt{\char`\\phiMany} enables iterating over an arrow.}
1731 % Then, we define a command for an arrow with iterating indices:
1732 % \begin{macrocode}
1733 \newcommand\phiMany[3]{%
1734 \phiOset{#3}{\phiUset{#2}{#1}}}
1735 % \end{macrocode}
1736 % \end{macro}
1737
1738 % \begin{macro}{\phiEOL}
1739 % \changes{0.9.0}{2022/11/24}{New command \texttt{\char`\\phiEOL} added, instead of \texttt{\char`\\\char`\\[-4pt]}.}
1740 % Then, we define a command for line breaks in formulas:
1741 % \begin{macrocode}
1742 \newcommand\phiEOL{\\[-4pt]}
1743 % \end{macrocode}
1744 % \end{macro}
1745
1746 % \begin{macro}{\phiTerminal}
1747 % \changes{0.21.0}{2025/12/15}{New command \texttt{\char`\\phiTerminal} added, to highlight all terminals in phi expressions.}
1748 % Then, we define a command to wrap all terminals in all expressions:
1749 % \begin{macrocode}
1750 \RequirePackage{xcolor}
1751 \newcommand\phiTerminal[1]{{\color{orange}#1}}
1752 % \end{macrocode}
1753 % \end{macro}
1754
1755 % \begin{macro}{\phiDotted}
1756 % \changes{0.1.0}{2022/10/27}{New command \texttt{\char`\\phiDotted} added to denote a link to a special attribute.}
1757 % Then, we define a command to render an arrow for a special attribute,
1758 % as suggested \href{https://tex.stackexchange.com/questions/663176}{here}:
1759 % \begin{macrocode}
1760 \RequirePackage{trimclip}
1761 \RequirePackage{amsfonts}
1762 \makeatletter
1763 \newcommand{\phiDotted}{%
1764 \phiTerminal{\mapstochar\mathrel{\mathpalette\phiDotted@\relax}}}
1765 \newcommand{\phiDotted@}[2]{%
1766 \begingroup%
1767 \settowidth{\dimen\z@}{$\m@th#1\rightarrow$}%
1768 \settoheight{\dimen\tw@}{$\m@th#1\rightarrow$}%
1769 \sbox\z@{%
1770 \makebox[\dimen\z@][s]{%
1771 \clipbox{0 0 {0.4\width} 0}%
1772 {\resizebox{\dimen\z@}{\height}%
1773 {$\m@th#1\dashrightarrow$}}%
1774 \hss%
1775 \clipbox{{0.69\width} {-0.1\height} 0
1776 {-\height}}{$\m@th#1\rightarrow$}%
1777 }%
1778 }%
1779 \ht\z@=\dimen\tw@ \dp\z@=\z@%
1780 \box\z@%
1781 \endgroup%
1782 }
1783 \makeatother
1784 % \end{macrocode}
1785 % \end{macro}
1786
1787 % \begin{macrocode}
1788 \endinput
1789 % \end{macrocode}
1790
1791 % \Finale
1792
1793 % \clearpage
1794 % \printbibliography
1795 % \clearpage
1796
1797 %\PrintChanges
1798 %\clearpage
1799 %\PrintIndex