-
Notifications
You must be signed in to change notification settings - Fork 0
/
eolang.dtx
1807 lines (1725 loc) 路 60.7 KB
/
eolang.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% \iffalse meta-comment
% (The MIT License)
%
% Copyright (c) 2021-2024 Yegor Bugayenko
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
% of this software and associated documentation files (the 'Software'), to deal
% in the Software without restriction, including without limitation the rights
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
% copies of the Software, and to permit persons to whom the Software is
% furnished to do so, subject to the following conditions:
%
% The above copyright notice and this permission notice shall be included in all
% copies or substantial portions of the Software.
%
% THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
% SOFTWARE.
% \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 \~}
% \GetFileInfo{eolang.dtx}
% \DoNotIndex{\endgroup,\begingroup,\let,\else,\s,\n,\r,\\,\1,\fi}
% \iffalse
%<*driver>
\ProvidesFile{eolang.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{eolang}
%<*package>
[0000-00-00 0.0.0 Formulas and Graphs for EO Programming Language]
%</package>
%<*driver>
\documentclass{ltxdoc}
\usepackage[T1]{fontenc}
\usepackage[maxnames=1,minnames=1,maxbibnames=1,natbib=true,citestyle=authoryear,bibstyle=authoryear,doi=false,url=false,isbn=false,isbn=false]{biblatex}
\addbibresource{eolang.bib}
\usepackage[tt=false, type1=true]{libertine}
\usepackage{microtype}
\AddToHook{env/verbatim/begin}{\microtypesetup{protrusion=false}}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage[runs=2,dtx]{docshots}
\usepackage[nocomments]{eolang}
\usepackage{href-ul}
\PageIndex
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
\DocInput{eolang.dtx}
\PrintChanges
\PrintIndex
\end{document}
%</driver>
% \fi
% \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}}}
% \author{Yegor Bugayenko \\ \texttt{yegor256@gmail.com}}
% \date{\filedate, \fileversion}
%
% \maketitle
%
% \textbf{\color{red}NB!}
% You must run \TeX{} processor with |-shell-escape| option
% and you must have \href{https://www.perl.org}{Perl} installed.
% If you omit the |-shell-escape| option, the package will try
% to use cached files, if they exist. If they don't, compilation will
% fail. Thus, when you must prepare your document for a compilation
% without the |-shell-escape| option, run it locally with the option provided
% and then package all files (including the files in the |_eolang-*| directories)
% into a single ZIP archive. It is advised to use |tmpdir| package option
% in this case, in order to make the directory name not depend on the
% \LaTeX{} engine.
%
% If |-shell-escape| is set, this package won't work on Windows, because
% it uses POSIX command line interface.
% \section{Introduction}
%
% This package helps you print formulas of $\varphi$-calculus,
% which is a formal foundation of \href{https://www.eolang.org}{EO}
% programming language. The calculus was introduced by \citet{bugayenko2021eolang}
% and later formalized by \citet{kudasov2021}. Here is how you render
% a simple expression:
% \begin{docshot}
% \documentclass{minimal}
% \usepackage{eolang}
% \begin{document}
% \begin{phiquation*}
% app -> [[ % it's abstract!
% ^ !-> $.b.^{^2}, 0/t~> TRUE,
% b -> [[ *-> Q.fn(56),
% @ -> QQ.string.trim($),
% D> 01-FE-C3 ]]]],\\
% x -> [[ \lambda ..> ? ]].
% \end{phiquation*}
% \end{document}
% \end{docshot}
% \DescribeEnv{phiquation}
% The environment |phiquation| lets you write a $\varphi$-calculus expressions
% using simple plain-text notation, where:
% \begin{itemize}\setlength\itemsep{0em}
% \item ``|@|'' maps to ``$\varphi$''
% (|\varphi|),
% \item ``|^|'' maps to ``$\rho$''
% (|\rho|),
% \item ``|$|'' maps to ``$\xi$''
% (|\xi|),
% \item ``|&|'' maps to ``$\sigma$''
% (|\sigma|),
% \item ``|?|'' maps to ``$\varnothing$''
% (|\varnothing|),
% \item ``|Q|'' maps to ``$\Phi$''
% (|\Phi|),
% \item ``|QQ|'' maps to ``$\dot{\Phi}$''
% (|\dot{\Phi}|),
% \item ``|->|'' maps to ``$\mapsto$''
% (|\mapsto|),
% \item ``|~>|'' maps to ``$\phiWave$''
% (|\phiWave|),
% \item ``|!->|'' maps to ``$\phiConst$''
% (|\phiConst|),
% \item ``|..>|'' maps to ``$\phiDotted$''
% (|\phiDotted|),
% \item ``|D>|'' maps to ``$\Delta\phiDotted$''
% (|\Delta ..>|),
% \item ``|L>|'' maps to ``$\lambda\phiDotted$''
% (|\lambda ..>|),
% \item ``|[[|'' maps to ``$\llbracket$''
% (|\llbracket|),
% \item ``|]]|'' maps to ``$\rrbracket$''
% (|\rrbracket|),
% \item ``|==|'' maps to ``$\equiv$''
% (|\equiv|),
% \item ``\texttt{\textbar{abc}\textbar}'' maps to ``\texttt{abc}''
% (|\texttt{abc}|).
% \end{itemize}
% Also, a few symbols are supported for $\varphi$PU architecture:
% \begin{itemize}\setlength\itemsep{0em}
% \item ``|<<|'' maps to ``$\langle$''
% (|\langle|),
% \item ``|>>|'' maps to ``$\rangle$''
% (|\rangle|),
% \item ``|-abc>|'' maps to ``$\phiSlot{abc}$''
% (|\phiSlot{abc}|),
% \item ``|:=|'' maps to ``$\vDash$''
% (|\vDash|).
% \end{itemize}
% Before any arrow you can put a number, which will be rendered as |\alpha| with an index, for example
% |\phiq{0->x}| will render ``\phiq{0->x}''.
% Instead of a number you can use asterix too.
% You can append a slash and a title to the number of an attribute, such as |0/g->x|.
% this will render as \phiq{0/g->x}. You can use fixed-width words too, for example
% \verb=\phiq{0/|f|->x}= will render as ``\phiq{0/|f|->x}''. It's also possible
% to use an asterix instead of a number, such that |\phiq{*/g->x}| renders as ``\phiq{*/g->x}''
% Numbers are automatically converted to fixed-width font, no need to always decorate them with vertical bars.
% |TRUE| and |FALSE| are automatically converted to fixed-width font too.
% Object names are automatically converted to fixed-width font too, if they have more than one letter.
% Texts in double quotes are automatically converted to fixed-width font too.
% \DescribeMacro{\phiq}
% The command |\phiq| lets you inline a $\varphi$-calculus expressions
% using the same simple plain-text notation. You can use dollar sign directly too:
% \docshotOptions{firstline=4,lastline=10}
% \begin{docshot}
% \documentclass{article}
% \pagestyle{empty}
% \usepackage{eolang}
% \begin{document}
% A simple object
% \phiq{x -> [[@ -> y]]} \\
% is a decorator of
% the data object \\
% $y -> [[\Delta ..> 42]]$.
% \end{document}
% \end{docshot}
% \DescribeEnv{sodg}
% The environment |sodg| allows you to draw a \href{https://github.com/objectionary/sodg}{SODG} graph:
% \begin{docshot}
% \documentclass{standalone}
% \usepackage{eolang}
% \begin{document}
% \begin{sodg}
% v0 \\ v0===> \\ v0!!A
% v1 xy:v0,-.8,2.8 data:42 tag:d_1
% v0->v1 a:x rho \\ =>v1
% v2 xy:v0,+1,+1 atom:\xi.x+1
% v1->v2 a:|hi| bend:-15
% v2->v0 pi bend:10 % a comment
% \end{sodg}
% \end{document}
% \end{docshot}
% The content of the environment is parsed line by line. Markers in each line are
% separated by a single space. The first marker is either a unique name of a
% vertex, like ``|v1|'' in the example above, or an edge, like ``|v0->v1|.'' All other markers are either
% unary like ``|rho|'' or binary like ``|atom:$\xi.x+1$|.'' Binary markers have two
% parts, separated by colon.
% The following markers are supported for a vertex:
% \begin{itemize}\setlength\itemsep{0em}
% \item ``|tag:<math>|'' puts a custom label |<math>| into the circle;
% \item ``|data:[<box>]|'' makes it a data vertex with an optional attached ``|<box>|''
% (the content of the box may only be numeric data);
% \item ``|atom:[<box>]|'' makes it an atom with an optional attached ``|<box>|''
% (the content of the box is a math formula);
% \item ``|box:<txt>|'' attaches a ``|<box>|'' to it;
% \item ``|xy:<v>,<r>,<d>|'' places this vertex in a position relative to the vertex ``|<v>|,''
% shifting it right by ``|<r>|'' and down by ``|<d>|'' centimetres;
% \item ``|+:<v>|'' makes a copy of an existing vertex and all its kids;
% \item ``|edgeless|'' removes the border from the vertex;
% \item ``|style:{...}|'' adds this TikZ style to the vertex |\node|.
% \end{itemize}
% The following markers are supported for an edge:
% \begin{itemize}\setlength\itemsep{0em}
% \item ``|rho|'' places a backward snake arrow to the edge,
% \item ``|bend:<angle>|'' bend it right by the amount of ``|<angle>|,''
% \item ``|a:<txt>|'' attaches label ``|<txt>|'' to it,
% \item ``|pi|'' makes it dotted, with $\pi$ label;
% \item ``|style:{...}|'' adds this TikZ style to the edge |\path|.
% \end{itemize}
% It is also possible to put transformation arrows to the graph, with the help of ``|v0=>v1|'' syntax. The arrow
% will be placed exactly between two vertices. You can also put an arrow from a vertex to the right,
% saying for example ``|v3=>|'', of from the left to the vertes, by saying for example ``|=>v5|.'' If you
% want the arrow to stay further away from the vertex than usually, use a few ``|=|'' symbols, for example ``|===>v0|.''
% You can also put a marker at the left side of a vertex, using ``|v5!A|'' syntax, where ``|v5|'' is the vertex
% and ``|A|'' is the text in the marker. They are useful when you put a few graphs on a picture
% explaining how one graph is transformed to another one and so forth. You can make a distance between the vertex
% and the marker a bit larger by using a few exclamation marks,
% for example ``|v5!!!A|'' will make a distance three times bigger.
% You can make a clone of an existing vertex together with all its dependants, by using this syntax: ``|v0+a|.''
% Here, we make a copy of ``|v0|'' and call it ``|v0a|.'' See the example below.
% Be aware, unrecognized markers are simply ignored, without any error reporting.
% \DescribeMacro{\eolang}
% \DescribeMacro{\phic}
% \DescribeMacro{\xmir}
% There is also a no-argument command |\eolang| to help you print the name of
% \eolang{} language. It understands the |anonymous| package option and prints itself
% differently, to double-blind your paper. There is also |\phic| command to print
% the name of \phic{}, also sensitive to |anonymous| mode. The macro |\xmir| prints "XMIR".
% \docshotOptions{firstline=3,lastline=10}
% \begin{docshot}
% \documentclass{acmart}
% \thispagestyle{empty}
% \usepackage[anonymous]{eolang}
% \begin{document}
% In our research we use \eolang{}, \\
% an experimental object-oriented \\
% dataflow language, \phic{}, as its \\
% formal foundation, and \xmir{} --- \\
% its XML-based presentation.
% \end{document}
% \end{docshot}
% Without the |anonymous| option there will be no orange color:
% \docshotOptions{firstline=3,lastline=10}
% \begin{docshot}
% \documentclass[anonymous]{acmart}
% \thispagestyle{empty}
% \usepackage{eolang}
% \begin{document}
% In our research we use \eolang{}, \\
% an experimental object-oriented \\
% dataflow language, \phic{}, as its \\
% formal foundation, and \xmir{} --- \\
% its XML-based presentation.
% \end{document}
% \end{docshot}
% \DescribeMacro{\phiConst}
% \DescribeMacro{\phiWave}
% \DescribeMacro{\phiDotted}
% A few simple commands are defined to help you render arrows.
% It is recommended not to use them directly, but use |!->| instead. However, if you
% want to use |\phiConst|, wrap it in |\mathrel| for better display:
% \docshotOptions{firstline=6,lastline=12}
% \begin{docshot}
% \documentclass{article}
% \pagestyle{empty}
% \usepackage[paperwidth=3in]{geometry}
% \usepackage{eolang}
% \begin{document}\noindent
% If $x$ is an identifier and $y$ is
% an object, then $x \phiConst y$
% makes $y$ a constant,
% $x \phiWave y$ makes it a decoratee
% of an arbitrary number of objects,
% while $x \phiDotted y$ makes it
% a special attribute.
% \end{document}
% \end{docshot}
% \DescribeMacro{\phiOset}
% \DescribeMacro{\phiUset}
% If you want to put a text over an arrow or under it, use |\phiOset| and |\phiUset| respectively:
% \docshotOptions{firstline=6,lastline=11}
% \begin{docshot}
% \documentclass{article}
% \pagestyle{empty}
% \usepackage[paperwidth=3in]{geometry}
% \usepackage{eolang}
% \begin{document}\noindent
% When the names of attributes and their
% values don't matter, we use an arrow
% with a star, for example:
% \begin{phiquation*}
% [[ \phiOset{*}{->} ]].
% \end{phiquation*}
% \end{document}
% \end{docshot}
% \DescribeMacro{\phiMany}
% 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 because of \href{https://tex.stackexchange.com/questions/664772}{this}):
% \docshotOptions{firstline=6,lastline=14}
% \begin{docshot}
% \documentclass{article}
% \pagestyle{empty}
% \usepackage[paperwidth=3in]{geometry}
% \usepackage{eolang}
% \begin{document}\noindent
% The expression
% \phiq{[[ 1-> x_1,
% 2-> x_2, \dots,
% \alpha_n -> x_n ]]}
% and expression
% \phiq{[[ \alpha_i
% \phiMany{->}{i=1}{n} x_i ]]}
% are syntactically different but
% semantically equivalent.
% \end{document}
% \end{docshot}
% \DescribeMacro{\phiSaveTo}
% \DescribeMacro{\sodgSaveTo}
% 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|):
% \docshotOptions{firstline=5,lastline=12}
% \begin{docshot}
% \documentclass{article}
% \usepackage{eolang}
% \pagestyle{empty}
% \begin{document}
% \phiSaveTo{a}
% \begin{phiquation*}
% [[ x -> [[D>42]] ]]
% \end{phiquation*}
% \begin{tabular}{p{.5in}l}
% Free: & $[[x -> ?]]$ \\
% Bound: & \parbox{1in}{\input{a}} \\
% \end{tabular}
% \end{document}
% \end{docshot}
% \DescribeMacro{\eoAnon}
% 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 substituion we will render if the |anonymous| package option is set.
% \section{Package Options}
% \DescribeMacro{tmpdir}
% The default location of temp files is |_eolang|. You can change this with the help of the |tmpdir| package option:
%\iffalse
%<*verb>
%\fi
\begin{verbatim}
\usepackage[tmpdir=/tmp/foo]{eolang}
\end{verbatim}
%\iffalse
%</verb>
%\fi
% \DescribeMacro{nodollar}
% You may disable the special treatment of the dollar sign by using the |nodollar| package option:
%\iffalse
%<*verb>
%\fi
\begin{verbatim}
\usepackage[nodollar]{eolang}
\end{verbatim}
%\iffalse
%</verb>
%\fi
% \DescribeMacro{anonymous}
% You may anonymize |\eolang|, |\XMIR|, and |\phic| commands by using |anonymous| package option (they all use the |\eoAnon| command mentioned earlier):
%\iffalse
%<*verb>
%\fi
\begin{verbatim}
\usepackage[anonymous]{eolang}
\end{verbatim}
%\iffalse
%</verb>
%\fi
% \DescribeMacro{noshell}
% You may prohibit any interactions with the shell by using the |noshell| option. This may be helpful when you send your document
% for outside processing and want to make sure the compilation won't break due to shell errors:
%\iffalse
%<*verb>
%\fi
\begin{verbatim}
\usepackage[noshell]{eolang}
\end{verbatim}
%\iffalse
%</verb>
%\fi
% \section{More Examples}
% The |phiquation| environment treats ends of line as signals to start
% new lines in the formula. If you don't want this to happen and want to parse
% the next line as the a continuation of the current line, you can use a single
% backslash as it's done here:
% \docshotOptions{firstline=6,lastline=11}
% \begin{docshot}
% \documentclass{article}
% \usepackage{amsmath}
% \usepackage{eolang}
% \pagestyle{empty}
% \begin{document}
% \begin{phiquation*}
% \dfrac \
% {x->[[@->y]] \quad y->[[z->42]]} \
% {x.z -> 42} \
% \text{\sffamily R1}
% \end{phiquation*}
% \end{document}
% \end{docshot}
% This is how you can use |\dfrac| from \href{https://ctan.org/pkg/amsmath}{amsmath} for large inference rules,
% with the help of |\begin{split}| and |\end{split}|:
% \docshotOptions{firstline=6,lastline=15}
% \begin{docshot}
% \documentclass{article}
% \usepackage{amsmath}
% \usepackage{eolang}
% \pagestyle{empty}
% \begin{document}
% \begin{phiquation*}
% \dfrac{\begin{split}
% x->[[@->y, z->42,
% 0/g->?, 1/foo->42]]
% \end{split}}{\begin{split}
% x->[[@->y, z->?, f ~> |pi|(
% 0->[[ \psi !-> |hello|(12) ]],
% 1->42)]]
% \end{split}}\text{R2}.
% \end{phiquation*}
% \end{document}
% \end{docshot}
% You can use the |matrix| environment too, in order to group a few lines:
% \docshotOptions{firstline=5,lastline=11}
% \begin{docshot}
% \documentclass{article}
% \usepackage{eolang}
% \pagestyle{empty}
% \begin{document}
% \begin{phiquation*}
% foo -> \left\{\begin{matrix} \
% ? \\
% [[ L> ^ \times $.\alpha_0 ]] \\
% [[ D> 42 ]] \
% \end{matrix}\right\}
% \end{phiquation*}
% \end{document}
% \end{docshot}
% The |cases| environment works too:
% \docshotOptions{firstline=5,lastline=11}
% \begin{docshot}
% \documentclass{article}
% \usepackage{eolang}
% \pagestyle{empty}
% \begin{document}
% \begin{phiquation*}
% \beta := \begin{cases} \
% [ v_2, @ -dtzd> 42 ] \\
% [ v_{33} ] \
% \end{cases}
% \end{phiquation*}
% \end{document}
% \end{docshot}
% The |phiquation| environment may be used together with the \href{https://ctan.org/pkg/acmart}{acmart} package:
% \begin{docshot}
% \documentclass{acmart}
% \usepackage{eolang}
% \thispagestyle{empty}
% \begin{document}
% \begin{phiquation*}
% x -> [[
% y -> [[
% z !-> $, f ..> ? ]]]],\\
% \beta_1 := [ \psi -wait> ? ].
% \end{phiquation*}
% \end{document}
% \end{docshot}
% 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):
% \docshotOptions{firstline=6,lastline=13}
% \begin{docshot}
% \documentclass{article}
% \usepackage[paperwidth=3in]{geometry}
% \usepackage{eolang}
% \pagestyle{empty}
% \begin{document}\noindent
% Discriminant can be calculated using
% the following simple formula:
% \begin{phiquation}
% D = b{^2} - {4}ac.
% \label{d}
% \end{phiquation}
% Eq.~\ref{d} is also widely used in
% number theory and polynomial factoring.
% \end{document}
% \end{docshot}
% 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):
% \docshotOptions{firstline=6,lastline=10}
% \begin{docshot}
% \documentclass{article}
% \usepackage[paperwidth=4in]{geometry}
% \usepackage{eolang}
% \pagestyle{empty}
% \begin{document}
% \begin{phiquation*}
% [[ 0->x ]] && \text{This is formation}
% [[ 0->? ]] && \text{Abstraction}
% x(D>42) && \text{Application}
% \end{phiquation*}
% \end{document}
% \end{docshot}
% If you don't use |nodollar| package option, you can still use normal parsing of the dollar sign, by means of |\(...\)| syntax:
% \docshotOptions{firstline=6,lastline=8}
% \begin{docshot}
% \documentclass{article}
% \usepackage[paperwidth=3in]{geometry}
% \usepackage{eolang}
% \pagestyle{empty}
% \begin{document}\noindent
% The object formation $[[0->x]]$
% may be replaced with a formula
% \( Q \times a^2 \).
% \end{document}
% \end{docshot}
% The |phiquation| environment will automatically align formulas by the first
% arrow, if there are only left-aligned formulas:
% \docshotOptions{firstline=5,lastline=11}
% \begin{docshot}
% \documentclass{acmart}
% \usepackage{eolang}
% \thispagestyle{empty}
% \begin{document}
% \begin{phiquation*}
% x(\pi) -> [[\lambda ..> f_1]], \\
% x(a,b,c) -> [[ \alpha_0 -> ?, \
% @ -> |hello|($), x -> |FALSE| ]], \\
% \Delta = |43-09|,
% x(y) == x(0-> y).
% \end{phiquation*}
% \end{document}
% \end{docshot}
% If not a single line is indented in |phiquation|, all formulas will be centered:
% \docshotOptions{firstline=5,lastline=9}
% \begin{docshot}
% \documentclass{acmart}
% \usepackage{eolang}
% \thispagestyle{empty}
% \begin{document}
% \begin{phiquation*}
% [[ b -> ? ]],
% [[ @ -> TRUE, \Delta ..> 42 ]], \\
% \psi = << \pi, 42 >>.
% \end{phiquation*}
% \end{document}
% \end{docshot}
% It is possible to use ``manual splitting'' mode in the |phiquation| environment by starting the body with |\begin{split}|:
% \docshotOptions{firstline=5,lastline=10}
% \begin{docshot}
% \documentclass{article}
% \usepackage{eolang}
% \thispagestyle{empty}
% \begin{document}
% \begin{phiquation*}
% \begin{split}
% x(\pi) & -> 4 \\
% x(a,b,c) & -> [[ \alpha_0 -> ? ]] \\
% \end{split}
% \end{phiquation*}
% \end{document}
% \end{docshot}
% When necessary to use a percentage sign, prepend it with a backward slash:
% \docshotOptions{firstline=5,lastline=10}
% \begin{docshot}
% \documentclass{article}
% \usepackage{eolang}
% \thispagestyle{empty}
% \begin{document}
% \begin{phiquation*}
% x -> sprintf("Hello, \%s!", name)
% \end{phiquation*}
% \end{document}
% \end{docshot}
% You can make a copy of a vertex together with its kids:
% \docshotOptions{firstline=5,lastline=15}
% \begin{docshot}
% \documentclass{article}
% \pagestyle{empty}
% \usepackage{eolang}
% \begin{document}
% \begin{sodg}
% v0 \\ v0!!A
% v1 xy:v0,.7,1
% v0->v1 a:x bend:-10
% v2 xy:v1,-1.3,.8
% v1->v2 a:|foo| bend:-20
% v0+a xy:v0,3,0
% v3a xy:v0a,-.7,1
% v0a->v3a a:e bend:-15
% v0=>v0a \\ v0a!B
% \end{sodg}
% \end{document}
% \end{docshot}
% You can make a copy from a copy:
% \docshotOptions{firstline=5,lastline=15}
% \begin{docshot}
% \documentclass{article}
% \pagestyle{empty}
% \usepackage{eolang}
% \begin{document}
% \begin{sodg}
% v0
% v1 xy:v0,.7,1
% v0->v1 a:x bend:-10 rho
% v0+a xy:v0,3,0 \\ v0=>v0a
% v2a xy:v1a,-.8,1.3
% v1a->v2a a:e
% v0a+b xy:v0a,3,0 \\ v0a=>v0b
% v3b xy:v2b,-1,-1
% v2b->v3b a:\psi{} rho
% \end{sodg}
% \end{document}
% \end{docshot}
% You can have ``broken'' edges, using ``|break|'' attribute of an edge.
% The attribute must have a value, which is the percentange of the path
% between vertices that the arrow should take (can't be more than 80 and less than 20).
% This may be convenient when you can't fit all edges into the graph,
% for example:
% \docshotOptions{firstline=5,lastline=14}
% \begin{docshot}
% \documentclass{article}
% \pagestyle{empty}
% \usepackage{eolang}
% \begin{document}
% \begin{sodg}
% v0
% v1 xy:v0,-1,1
% v0->v1 a:x
% v2 xy:v0,0,1
% v0->v2 a:y
% v3 xy:v0,1,1
% v0->v3 a:\psi{}
% v3->v1 a:f bend:-75 break:30
% \end{sodg}
% \end{document}
% \end{docshot}
% You can add \href{https://en.wikipedia.org/wiki/PGF/TikZ}{TikZ} commands to |sodg| graph, for example:
% \docshotOptions{firstline=6,lastline=13}
% \begin{docshot}
% \documentclass{article}
% \pagestyle{empty}
% \usepackage{eolang}
% \usetikzlibrary{fit}
% \begin{document}
% \begin{sodg}
% v0 edgeless
% v11 xy:v0,-1,1 \\ v0->v11
% v12 xy:v0,0,1 \\ v0->v12
% v13 xy:v0,1,1 \\ v0->v13
% \node[draw=red,rounded corners,\
% dotted,fit=(v11) (v12)] {};
% \end{sodg}
% \end{document}
% \end{docshot}
% You can modify TikZ style yourself (make sure |style:| stays at the end of the line!), for example:
% \docshotOptions{firstline=6,lastline=12}
% \begin{docshot}
% \documentclass{article}
% \pagestyle{empty}
% \usepackage{eolang}
% \usetikzlibrary{fit}
% \begin{document}
% \begin{sodg}
% v0
% v1 xy:v0,-2,1 style:font=\color{red}
% v2 xy:v0,2,1
% v0->v1 style:line width=2pt
% v0->v2 style:draw=orange
% \end{sodg}
% \end{document}
% \end{docshot}
% \StopEventually{}
% \section{Implementation}
% \changes{0.0.1}{2022/10/15}{First draft.}
% First, we include a few packages.
% We need \href{https://ctan.org/pkg/stmaryrd}{stmaryrd} for |\llbracket| and |\rrbracket| commands:
% \begin{macrocode}
\RequirePackage{stmaryrd}
% \end{macrocode}
% We need \href{https://ctan.org/pkg/amsmath}{amsmath} for |equation*| environment:
% \begin{macrocode}
\RequirePackage{amsmath}
% \end{macrocode}
% We need \href{https://ctan.org/pkg/amssymb}{amssymb} for |\varnothing| command. We disable |\Bbbk|
% because it may conflict with some packages from \href{https://ctan.org/pkg/acmart}{acmart}:
% \begin{macrocode}
\let\Bbbk\relax\RequirePackage{amssymb}
% \end{macrocode}
% We need \href{https://ctan.org/pkg/fancyvrb}{fancyvrb} for |\VerbatimEnvironment| command:
% \begin{macrocode}
\RequirePackage{fancyvrb}
% \end{macrocode}
% We need \href{https://ctan.org/pkg/iexec}{iexec} for executing Perl scripts:
% \begin{macrocode}
\ifdefined\eolang@noshell\else\RequirePackage{iexec}\fi
% \end{macrocode}
% Then, we process package options:
% \changes{0.1.0}{2022/10/26}{Parsing of package options introduced.}
% \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).}
% \changes{0.8.0}{2022/11/29}{The \texttt{anonymous} package option added.}
% \begin{macrocode}
\RequirePackage{pgfopts}
\RequirePackage{ifluatex}
\RequirePackage{ifxetex}
\pgfkeys{
/eolang/.cd,
tmpdir/.store in=\eolang@tmpdir,
tmpdir/.default=_eolang\ifxetex-xe\else\ifluatex-lua\fi\fi,
nocomments/.store in=\eolang@nocomments,
anonymous/.store in=\eolang@anonymous,
noshell/.store in=\eolang@noshell,
tmpdir
}
\ProcessPgfPackageOptions{/eolang}
% \end{macrocode}
% Then, we make a directory where all temporary files will be kept:
% \begin{macrocode}
\makeatletter
\ifdefined\eolang@noshell\else\RequirePackage{shellesc}\fi
\IfFileExists
{\eolang@tmpdir/\jobname}
{\message{eolang: Temporary directory "\eolang@tmpdir/\jobname"
already exists^^J}}
{
\ifdefined\eolang@noshell
\message{eolang: Temporary directory "\eolang@tmpdir/\jobname"
is not created, because of the "noshell" package option,
most probably the compilation will fail later^^J}
\else
\ifnum\ShellEscapeStatus=1
\iexec[null]{mkdir -p "\eolang@tmpdir/\jobname"}
\else
\message{eolang: Temporary directory "\eolang@tmpdir/\jobname"
is not created, because -shell-escape is not set, and
it doesn't exist, most probably the compilation
will fail later^^J}
\fi
\fi
}
\makeatother
% \end{macrocode}
% \begin{macro}{\eolang@lineno}
% \changes{0.3.0}{2022/10/30}{New counter for protecting lineno.}
% Then, we define an internal counter to protect line number from changing:
% \begin{macrocode}
\makeatletter\newcounter{eolang@lineno}\makeatother
% \end{macrocode}
% \end{macro}
% \begin{macro}{\eolang@mdfive}
% \changes{0.1.0}{2022/10/26}{New supplementary command added to calculate MD5 sum of a file.}
% Then, we define a command for MD5 hash calculating of a file:
% \begin{macrocode}
\RequirePackage{pdftexcmds}
\makeatletter
\newcommand\eolang@mdfive[1]{\pdf@filemdfivesum{#1}}
\makeatother
% \end{macrocode}
% \end{macro}
% \begin{macro}{-phi.pl}
% \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}
% \changes{0.0.2}{2022/10/21}{New symbol added for basket slots}
% \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})}
% \changes{0.1.0}{2022/10/26}{A new Perl script "\texttt{eolang-phi.pl}" added for parsing of phi expressions.}
% \changes{0.2.0}{2022/10/29}{Numbers automatically render as \texttt{\char`\\texttt}. No need to use vertical bars around them anymore.}
% \changes{0.3.0}{2022/10/30}{New arrow added, that looks like \texttt{\char`\\leadsto}.}
% \changes{0.5.0}{2022/11/11}{Automated formatting of \texttt{TRUE} and \texttt{FALSE} added.}
% \changes{0.5.0}{2022/11/13}{A new syntax introduced for the \texttt{\char`\\alpha} attributes: \texttt{0->}.}
% \changes{0.5.0}{2022/11/14}{It's possible to use double names for attributes, such as \texttt{0/g->}.}
% \changes{0.7.0}{2022/11/17}{Object names are automatically converted to \texttt{\char`\\texttt}, provided their names include two or more symbols.}
% \changes{0.7.0}{2022/11/17}{Text in quotes is automatically converted to \texttt{\char`\\texttt}.}
% \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.}
% \changes{0.7.0}{2022/11/18}{New syntax sugar for $\Phi$, just using capital ``\texttt{Q}'' is enough.}
% \changes{0.8.0}{2022/11/21}{Inside \texttt{phiquation} any text inside the \texttt{\char`\\text} macro is not processed.}
% \changes{0.9.0}{2022/12/15}{Proper handling of the \texttt{matrix} environment.}
% \changes{0.9.0}{2022/12/15}{Parsing of \texttt{<<} and \texttt{>>} implemented.}
% \changes{0.10.0}{2023/01/22}{Parsing of \texttt{==} into \texttt{\char`\\equiv} implemented.}
% \changes{0.13.0}{2023/06/28}{Parsing of \texttt{QQ} into \texttt{\char`\\dot\{\char`\\Phi\}} implemented.}
% Then, we create a Perl script for |phiquation| processing using |VerbatimOut| environment from
% \href{https://ctan.org/pkg/fancyvrb}{fancyvrb}:
% \begin{macrocode}
\makeatletter
\ifdefined\eolang@noshell
\message{eolang: Perl script is not going to be created,
at "\eolang@tmpdir/\jobname-phi.pl" because of the "noshell"
package option^^J}
\else
\openin 15=\eolang@tmpdir/\jobname-phi.pl
\ifeof 15
\message{eolang: Perl script is going to be created,
because it is absent at "\eolang@tmpdir/\jobname-phi.pl",
but if -shell-escape is not set, the compilation will
most likely fail now^^J}
\begin{VerbatimOut}{\eolang@tmpdir/\jobname-phi.pl}
$macro = $ARGV[0];
open(my $fh, '<', $ARGV[1]);
my $tex; { local $/; $tex = <$fh>; }
print "% This file is auto-generated by 0.0.0\n";
print '% There are ', length($tex),
' chars in the input: ', $ARGV[1], "\n";
print '% ---', "\n";
if (index($tex, "\t") > 0) {
print "TABS are prohibited!";
exit 1;
}
my @lines = split (/\n/g, $tex);
foreach my $t (@lines) {
print '% ', $t, "\n";
}
print '% ---', "\n";
$tex =~ s/(?<!\\)%.*\n/\n/g;
$tex =~ s/^\s+|\s+$//g;
my $splitting = $tex =~ /^\\begin\{split\}/;
if ($splitting) {
print '% The manual splitting mode is ON since \begin{split} started the text' . "\n";
}
my $indents = $tex =~ /\n +/g;
my $gathered = (0 == $indents);
if ($gathered) {
if ($splitting) {
print '% The "gathered" is NOT used because of manual splitting' . "\n";
$gathered = 0;
} else {
print '% The "gathered" is used since all lines are left-aligned' . "\n";
}
} else {
print '% The "gathered" is NOT used because ' .
$indents . " lines are indented\n";
}
my $align = 0;
print '% The "align" is NOT used by default' . "\n";
if (index($tex, '&&') >= 0) {
$macro =~ s/equation/align/g;
$align = 1;
print '% The "align" is used because of && seen in the text' . "\n";
}
if ($macro ne 'phiq') {
if (not $splitting) {
$tex =~ s/\\\\\n/\n\n/g;
$tex =~ s/\\\n\s*//g;
}
$tex =~ s/\n*(\\label\{[^\}]+\})\n*/\1/g;
$tex =~ s/\n{3,}/\n\n/g;
}
my @texts = ();
sub trep {
my ($s) = @_;
my $open = 0;
my $p = 0;
for (; $p < length($s); $p++) {
$c = substr($s, $p, 1);
if ($c eq '}') {
if ($open eq 0) {
last;
}
$open--;
}
if ($c eq '{') {
$open++;
}
}
push(@texts, substr($s, 0, $p));
return '{TEXT' . (0+@texts - 1) . '}' . substr($s, $p + 1);
}
$tex =~ s/\\text\{(.+)/trep("$1")/ge;
if (not $splitting) {
$tex =~ s/(?<![{&])&(?![&}])/\\sigma{}/g;
}
$tex =~ s/([^\\{a-z0-9]|^)QQ(?![a-z0-9])/\1\\dot{\\Phi{}}/g;
$tex =~ s/([^\\{a-z0-9]|^)Q(?![a-z0-9])/\1\\Phi{}/g;
$tex =~ s/([^\\{a-z0-9]|^)D>/\1\\Delta{}..>/g;
$tex =~ s/([^\\{a-z0-9]|^)L>/\1\\lambda{}..>/g;
$tex =~ s/"([^"]+)"/|"\1"|/g;
$tex =~ s/(^|(?<=[\s)(\]\[,.>\/]))([a-zA-Z][a-z0-9]+)(?=[\s)(\]\[,.-]|$)/|\2|/g;
$tex =~ s/([^_^]|^)([0-9]+|\*)\/(\\?[a-z]+|\|[a-z]+\|)
(->|\.\.>|~>|:=|!->)/\1\\alpha_{\2}\\vert{}\3\\space{}\4/xg;
$tex =~ s/([^_^]|^)([0-9]+|\*)
(->|\.\.>|~>|:=|!->)/\1\\alpha_{\2}\\space{}\3/xg;
if ($macro ne 'phiq') {
if (not $splitting) {
$tex =~ s/\\begin\{split\}\n/\\begin{split}&/g;
$tex =~ s/\n\s*\\end\{split\}/\\end{split}/g;
$tex =~ s/\n\n/\\\\&/g;
$tex =~ s/\n/\\phiEOL{}\n&/g;
$tex =~ s/\\\\$//g;
$tex =~ s/\\\\/\\\\\n/g;
$tex =~ s/([^&\s])\s{2}([^\s])/\1 \2/g;
$tex =~ s/\s{2}/ \\quad{}/g;
$tex = '&' . $tex;
}
my $lead = '[^\s]+\s(?:->|:=|=|==)\s';
my @leads = $tex =~ /&${lead}/g;
my @eols = $tex =~ /&/g;
if (0+@leads == 0+@eols && 0+@eols > 1) {
$tex =~ s/&(${lead})/\1&~/g;
$gathered = 0;
print '% The "gathered" is NOT used because all ' .
(0+@eols) . ' lines are ' . (0+@leads) . " leads\n";
}
}
if ($macro ne 'phiq') {
sub strip_tabs {
my ($env, $tex) = @_;
$tex =~ s/&//g;
return "\\begin{$env}" . $tex . "\\end{$env}";
}
foreach my $e (('matrix', 'cases')) {
$tex =~ s/\\begin\{(\Q$e\E\*?)\}(.+)\\end\{\Q$e\E\*?\}/strip_tabs($1, $2)/sge;
}
}
$tex =~ s/\$/\\xi{}/g;
$tex =~ s/(?<!\{)\^(?!\{)/\\rho{}/g;
$tex =~ s/\[\[/\\llbracket\\mathbin{}/g;
$tex =~ s/\]\]/\\mathbin{}\\rrbracket{}/g;
$tex =~ s/([\s,>(])([0-9A-F]{2}(?:-[0-9A-F]{2})+|
[0-9]+(?:\.[0-9]+)?)(?!\{)/\1|\2|/xg;
$tex =~ s/TRUE/|TRUE|/g;
$tex =~ s/FALSE/|FALSE|/g;