diff options
author | Karl Berry <karl@freefriends.org> | 2022-11-13 21:23:27 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2022-11-13 21:23:27 +0000 |
commit | 38c0458b0227cb97b88876955527ad3bfcde94f1 (patch) | |
tree | 3c6c2881c7778e1049b02b04c627833c84cfcf46 /Master/texmf-dist/tex/latex/eolang/eolang.sty | |
parent | dd89769c5e3ff93f9a9b97e727858cb06ed095dc (diff) |
eolang (13nov22)
git-svn-id: svn://tug.org/texlive/trunk@65006 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/eolang/eolang.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/eolang/eolang.sty | 280 |
1 files changed, 208 insertions, 72 deletions
diff --git a/Master/texmf-dist/tex/latex/eolang/eolang.sty b/Master/texmf-dist/tex/latex/eolang/eolang.sty index 087801f400f..1c58823608b 100644 --- a/Master/texmf-dist/tex/latex/eolang/eolang.sty +++ b/Master/texmf-dist/tex/latex/eolang/eolang.sty @@ -31,7 +31,17 @@ \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{eolang} -[2022-11-05 0.4.0 Formulas and Graphs for EO Programming Language] +[2022-11-13 0.5.0 Formulas and Graphs for EO Programming Language] + + + + + + + + + + @@ -99,31 +109,16 @@ foreach my $t (@lines) { print '% ', $t, "\n"; } print '% ---', "\n"; -if ($env eq 'phiq') { - print '$'; -} else { - print '\begin{', $env, '}\begin{split}'; -} +$tex =~ s/%.*\n/\n/g; $tex =~ s/^\s+|\s+$//g; +my $gathered = (0 == $tex =~ /\n\s+/g); if ($env ne 'phiq') { $tex =~ s/\s+\\\n\s*//g; $tex =~ s/\\\\\n/\n\n/g; + $tex =~ s/\n*(\\label\{[^\}]+\})\n*/\1/g; } -$tex =~ s/([\s,>\(])([0-9A-F][0-9A-F-]*)/\1|\2|/g; -$tex =~ s/\?/\\varnothing{}/g; -$tex =~ s/@/\\varphi{}/g; $tex =~ s/&/\\sigma{}/g; -$tex =~ s/\^/\\rho{}/g; -$tex =~ s/\$/\\xi{}/g; -$tex =~ s/-([a-z]+)>/\\mathrel{\\xrightarrow{\\text{\\sffamily\\scshape \1}}}/g; -$tex =~ s/!->/\\mathrel{\\phiConst}/g; -$tex =~ s/->/\\mathrel{\\mapsto}/g; -$tex =~ s/~>/\\mathrel{\\phiWave}/g; -$tex =~ s/:=/\\mathrel{\\vDash}/g; -$tex =~ s/..>/\\mathrel{\\phiDotted}/g; -$tex =~ s/\|([^\|]+)\|/\\textnormal{\\texttt{\1}}{}/g; -$tex =~ s/\[\[/\\llbracket\\mathrel{}/g; -$tex =~ s/\]\]/\\mathrel{}\\rrbracket{}/g; +$tex =~ s/(\s|^)([0-9]+)(->|\.\.>|~>|:=|!->)/\1\\alpha_{\2} \3/g; if ($env ne 'phiq') { $tex =~ s/\\begin\{split\}\n/\\begin{split}&/g; $tex =~ s/\n\s*\\end\{split\}/\\end{split}/g; @@ -131,20 +126,57 @@ if ($env ne 'phiq') { $tex =~ s/\n/\\\\[-4pt]&/g; $tex =~ s/([^&\s])\s{2}([^\s])/\1 \2/g; $tex =~ s/\s{2}/ \\quad{}/g; - my @leads = $tex =~ /&[^\s]+\s/g; + my @leads = $tex =~ /&[^\s]+\s(->|:=|=)/g; my @eols = $tex =~ /&/g; $tex = '&' . $tex; if (0+@leads == 0+@eols && 0+@eols > 0) { - $tex =~ s/&([^\s]+)\s/\1&/g; + $tex =~ s/&([^\s\}]+)\s/\1&/g; + $gathered = 0; } } +$tex =~ s/\$/\\xi{}/g; +$tex =~ s/(?<!\{)\^/\\rho{}/g; +$tex =~ s/\[\[/\\llbracket\\mathrel{}/g; +$tex =~ s/\]\]/\\mathrel{}\\rrbracket{}/g; +$tex =~ s/([\s,>\(])([0-9A-F]{2}(?:-[0-9A-F]{2})+|[0-9]+(?:\.[0-9]+)?)/\1|\2|/g; +$tex =~ s/TRUE/|TRUE|/g; +$tex =~ s/FALSE/|FALSE|/g; +$tex =~ s/\?/\\varnothing{}/g; +$tex =~ s/@/\\varphi{}/g; +$tex =~ s/-([a-z]+)>/\\mathrel{\\phiSlot{\1}}/g; +$tex =~ s/!->/\\mathrel{\\phiConst}/g; +$tex =~ s/->/\\mathrel{\\mapsto}/g; +$tex =~ s/~>/\\mathrel{\\phiWave}/g; +$tex =~ s/:=/\\mathrel{\\vDash}/g; +$tex =~ s/\.\.>/\\mathrel{\\phiDotted}/g; +$tex =~ s/\|{2,}/|/g; +$tex =~ s/\|([^\|]+)\|/\\textnormal{\\texttt{\1}}{}/g; +if ($env eq 'phiq') { + print '$' if ($tex ne ''); +} else { + print '\begin{', $env, '}'; + if ($gathered) { + print '\begin{gathered}'; + } else { + print '\begin{split}'; + } +} +if ($gathered) { + $tex =~ s/(\\\\(?:\[[^\]]+\])?)&/\1/g; + $tex =~ s/^&//g; +} print $tex; if ($env eq 'phiq') { - print '$'; + print '$' if ($tex ne ''); } else { - print '\end{split}\end{', $env, '}'; + if ($gathered) { + print '\end{gathered}'; + } else { + print '\end{split}'; + } + print '\end{', $env, '}'; } -print '\endinput', "\n"; +print '\endinput%'; \end{VerbatimOut} \message{eolang: File with Perl script '\eolang@tmpdir/eolang-phi.pl' saved^^J}% @@ -201,53 +233,78 @@ sub fmt { $tex =~ s/\|([^\|]+)\|/\\textnormal{\\texttt{\1}}/g; return $tex; } +sub vertex { + my ($v) = @_; + if (index($v, 'v0') == 0) { + return '\Phi'; + } else { + $v =~ s/^v/v_/g; + $v =~ s/[^0-9]$//g; + return $v; + } +} +sub tailor { + my ($t, $m) = @_; + $t =~ s/<([A-Z]?${m}[A-Z]?):([^>]+)>/\2/g; + $t =~ s/<[A-Z]+:[^>]+>//g; + return $t; +} open(my $fh, '<', $ARGV[0]); my $tex; { local $/; $tex = <$fh>; } -print '% This file is auto-generated', "\n"; -print '% There are ', length($tex), - ' chars in the input: ', $ARGV[0], "\n"; -print '% ---', "\n"; if (index($tex, "\t") > 0) { print "TABS are prohibited!"; exit 1; } +print '% This file is auto-generated', "\n%\n"; +print '% --- there are ', length($tex), + ' chars in the input (', $ARGV[0], "):\n"; foreach my $t (split (/\n/g, $tex)) { print '% ', $t, "\n"; } -print '% ---', "\n"; -$tex =~ s/^\s+|\s+$//g; +print "% ---\n"; $tex =~ s/\\\\/\n/g; +$tex =~ s/\\\n//g; $tex =~ s/(\\[a-zA-Z]+) +/\1/g; -$tex =~ s/\n\s+/\n/g; -my @cmds = split (/\n/g, $tex); +$tex =~ s/\n{2,}/\n/g; +my @cmds = split(/\n/g, $tex); +print '% --- before processing:' . "\n"; +foreach my $t (split (/\n/g, $tex)) { + print '% ', $t, "\n"; +} +print '% ---'; +print ' (' . (0+@cmds) . " lines)\n"; print '\begin{phicture}', "\n"; -foreach my $c (@cmds) { - my ($head, $tail) = split (/ /, $c, 2); +for (my $c = 0; $c < 0+@cmds; $c++) { + my $cmd = $cmds[$c]; + $cmd =~ s/^\s+//g; + $cmd =~ s/%.*//g; + my ($head, $tail) = split(/ /, $cmd, 2); my %opts = {}; - foreach my $p (split (/ /, $tail)) { - my ($q, $t) = split (/:/, $p); + foreach my $p (split(/ /, $tail)) { + my ($q, $t) = split(/:/, $p); $opts{$q} = $t; } if (index($head, '->') >= 0) { - print '\draw['; + my $draw = '\draw['; if (exists $opts{'pi'}) { - print ',phi-pi'; + $draw = $draw . '<MB:phi-pi><F:draw=none>'; if (not exists $opts{'a'}) { $opts{'a'} = '\pi'; } } - print ']'; + $draw = $draw . ']'; my ($from, $to) = split (/->/, $head); - print ' (', $from, ') '; + $draw = $draw . " (${from}) "; if (exists $opts{'bend'}) { - print 'edge [bend right=', num($opts{'bend'}), ']'; + $draw = $draw . 'edge [<F:draw=none,><MF:bend right=' . + num($opts{'bend'}) . '>]'; } else { - print '--'; + $draw = $draw . '--'; } if (exists $opts{'rho'} or exists $opts{'rrho'}) { - print ' pic[sloped,phi-rho]{parallel arrow={'; - print '-' if not exists $opts{'rrho'}; - print '0.3,-0.15}}'; + $draw = $draw . ' pic[sloped,phi-rho]{parallel arrow={'; + $draw = $draw . '-' if not exists $opts{'rrho'}; + $draw = $draw . '0.3,-0.15}}'; } if (exists $opts{'a'}) { my $a = $opts{'a'}; @@ -256,27 +313,102 @@ foreach my $c (@cmds) { } else { $a = fmt($a); } - print ' node [phi-attr] {', $a, '}'; + $draw = $draw . '<MB: node [phi-attr] {' . $a . '}>'; + } + if (exists $opts{'break'}) { + $draw = $draw . '<F: coordinate [pos=' . + ($opts{'break'} / 100) . '] (break)>'; + } + $draw = $draw . " (<MF:${to}><B:break-v>)"; + if (exists $opts{'break'}) { + print tailor($draw, 'F') . ";\n"; + print ' \node[outer sep=.1cm,inner sep=0cm] ' . + 'at (break) (break-v) {$' . vertex($to) . + '$};' . "\n"; + print ' ' . tailor($draw, 'B'); + } else { + print tailor($draw, 'M'); } - print ' (', $to, ')'; } elsif (index($head, '=>') >= 0) { - my ($from, $to) = split (/=>/, $head); + my ($from, $to) = split (/=+>/, $head); + my $size = () = $head =~ /=/g; if ($from eq '') { - print '\node [phi-arrow, left=.6cm of ' . - $to . ']'; + print '\node [phi-arrow, left=' . ($size * 0.6) . 'cm of ' . + $to . '.center]'; } elsif ($to eq '') { - print '\node [phi-arrow, right=.6cm of ' . - $from . ']'; + print '\node [phi-arrow, right=' . ($size * 0.6) . 'cm of ' . + $from . '.center]'; } else { print '\node [phi-arrow] at ($(' . $from . ')!0.5!(' . $to . ')$)'; } print '{}'; } elsif (index($head, '!') >= 0) { - my ($v, $marker) = split (/!/, $head); - print '\node [phi-marker, left=.6cm of ' . - $v . ']{' . fmt($marker) . '}'; - } else { + my ($v, $marker) = split (/!+/, $head); + my $size = () = $head =~ /!/g; + print '\node [phi-marker, left=' . + ($size * 0.6) . 'cm of ' . + $v . '.center]{' . fmt($marker) . '}'; + } elsif (index($head, '+') >= 0) { + my ($v, $suffix) = split (/\+/, $head); + my @friends = ($v); + foreach my $c (@cmds) { + $e = $c; + $e =~ s/^\s+//g; + my $h = $e; + $h = substr($e, 0, index($e, ' ')) if index($e, ' ') >= 0; + foreach my $f (@friends) { + my $add = ''; + if (index($h, $f . '->') >= 0) { + $add = substr($h, index($h, '->') + 2); + } + if ($h =~ /->\Q${f}\E$/) { + $add = substr($h, 0, index($h, '->')); + } + if (index($e, ' xy:' . $f . ',') >= 0) { + $add = $h; + } + if (index($add, '+') == -1 + and $add ne '' + and not(grep(/^\Q${add}\E$/, @friends))) { + push(@friends, $add); + } + } + } + my @extra = (); + foreach my $e (@cmds) { + $m = $e; + if ($m =~ /^\s*\Q${v}\E\s/) { + next; + } + if ($m =~ /^\s*[^\s]+\+/ and not($m =~ /^\s*\Q${head}\E\s/)) { + next; + } + foreach my $f (@friends) { + my $h = $f; + $h =~ s/[a-z]$//g; + if ($m =~ s/^(\s*)\Q${f}\E\+\Q${suffix}\E\s?/\1${h}${suffix} /g) { + last; + } + $m =~ s/^(\s*)\Q${f}\E\s/\1${h}${suffix} /g; + $m =~ s/^(\s*)\Q${f}\E->/\1${h}${suffix}->/g; + $m =~ s/\sxy:\Q${f}\E,/ xy:${h}${suffix},/g; + $m =~ s/->\Q${f}\E\s/->${h}${suffix} /g; + } + if ($m ne $e) { + push(@extra, ' ' . $m); + } + } + splice(@extra, 0, 0, @extra[-1]); + splice(@extra, -1, 1); + splice(@extra, 0, 0, '% clone of ' . $v . ' (' . $head . + '), friends: [' . join(', ', @friends) . '] in ' . + (0+@cmds) . ' lines'); + splice(@cmds, $c, 1, @extra); + print '% cloned ' . $v . ' at line no.' . $c . + ' (+' . (0+@extra) . ' lines -> ' . + (0+@cmds) . ' lines total)'; + } elsif ($head =~ /^v[0-9]+[a-z]?$/) { print '\node['; if (exists $opts{'xy'}) { my ($v, $right, $down) = split(/,/, $opts{'xy'}); @@ -293,7 +425,7 @@ foreach my $c (@cmds) { } print ',' . $loc . '='; print abs(num($down)) . 'cm and ' . - abs(num($right)) . 'cm of ' . $v; + abs(num($right)) . 'cm of ' . $v . '.center'; } if (exists $opts{'data'}) { print ',phi-data'; @@ -323,25 +455,24 @@ foreach my $c (@cmds) { } print ']'; print ' (', $head, ')'; - print ' {$'; - if (index($head, 'v0') == 0) { - print '\Phi'; - } else { - $name = $head; - $name =~ s/^v/v_/g; - $name =~ s/[^0-9]$//g; - print $name; - } - print '$}'; + print ' {$' . vertex($head) . '$}'; if (exists $opts{'box'}) { print ' node[phi-box] at ('; print $head, '.south east) {'; print $opts{'box'}, '}'; } + } else { + print $cmd; } print ";\n"; } -print '\end{phicture}', "\n", '\endinput'; +print '\end{phicture}%', "\n"; +print "% --- after processing:\n%"; +foreach my $c (@cmds) { + print '% ', $c, "\n"; +} +print '% --- (' . (0+@cmds) . " lines)\n"; +print '\endinput%'; \end{VerbatimOut} \message{eolang: File with Perl script '\eolang@tmpdir/eolang-sodg.pl' saved^^J}% @@ -354,12 +485,11 @@ print '\end{phicture}', "\n", '\endinput'; \RequirePackage{tikz} \usetikzlibrary{arrows} \usetikzlibrary{shapes} + \usetikzlibrary{snakes} \usetikzlibrary{decorations} \usetikzlibrary{decorations.pathmorphing} - \usetikzlibrary{intersections} \usetikzlibrary{positioning} \usetikzlibrary{calc} - \usetikzlibrary{shapes.arrows} \newenvironment{phicture}% {\noindent\begin{tikzpicture}[ @@ -426,7 +556,7 @@ print '\end{phicture}', "\n", '\endinput'; \newcommand\xmir{% \ifdefined\anon% - \anon[XML']{XMIR}% + \anon[XML$^+$]{XMIR}% \else% XMIR% \fi% @@ -439,6 +569,12 @@ print '\end{phicture}', "\n", '\endinput'; \newcommand\phiWave{% \mapstochar\mathrel{\mspace{0.45mu}}\leadsto} +\newcommand\phiSlot[1]{% + \xrightarrow{\text{\sffamily\scshape #1}}} + +\newcommand\phiMany[3]{% + \overunderset{\scriptscriptstyle #3}{\scriptscriptstyle #2}{#1}} + \RequirePackage{trimclip} \RequirePackage{amsfonts} \makeatletter |