diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/eolang')
-rw-r--r-- | Master/texmf-dist/tex/latex/eolang/eolang.sty | 139 |
1 files changed, 111 insertions, 28 deletions
diff --git a/Master/texmf-dist/tex/latex/eolang/eolang.sty b/Master/texmf-dist/tex/latex/eolang/eolang.sty index 824fe933e2f..ff8b74b6f5b 100644 --- a/Master/texmf-dist/tex/latex/eolang/eolang.sty +++ b/Master/texmf-dist/tex/latex/eolang/eolang.sty @@ -31,7 +31,11 @@ \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{eolang} -[2022-11-18 0.7.0 Formulas and Graphs for EO Programming Language] +[2022-11-28 0.7.1 Formulas and Graphs for EO Programming Language] + + + + @@ -98,7 +102,7 @@ \makeatletter \begin{VerbatimOut}{\eolang@tmpdir/eolang-phi.pl} -$env = $ARGV[0]; +$macro = $ARGV[0]; open(my $fh, '<', $ARGV[1]); my $tex; { local $/; $tex = <$fh>; } print '% This file is auto-generated', "\n"; @@ -117,42 +121,78 @@ print '% ---', "\n"; $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; +if ($gathered) { +print '% The "gathered" is used since all lines are left-aligned' . "\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') { $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++; + } } -$tex =~ s/&/\\sigma{}/g; + push(@texts, substr($s, 0, $p)); + return '{TEXT' . (0+@texts - 1) . '}' . substr($s, $p + 1); +} +$tex =~ s/\\text\{(.+)/trep("$1")/ge; +$tex =~ s/(?<![{&])&(?![&}])/\\sigma{}/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/([ )(.>\/]|^)([a-z0-9]{2,})(?=[ )(.-])/\1|\2|/g; +$tex =~ s/(^|(?<=[\s)(\]\[,.>\/]))([a-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 ($env ne 'phiq') { +if ($macro ne 'phiq') { $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/\\\\[-4pt]&/g; + $tex =~ s/\n/\\phiEOL{}\n&/g; + $tex =~ s/\\\\/\\\\\n/g; $tex =~ s/([^&\s])\s{2}([^\s])/\1 \2/g; $tex =~ s/\s{2}/ \\quad{}/g; - my @leads = $tex =~ /&[^\s]+\s(->|:=|=)/g; - my @eols = $tex =~ /&/g; $tex = '&' . $tex; + my $lead = '[^\s]+\s(->|:=|=)'; + my @leads = $tex =~ /&${lead}/g; + my @eols = $tex =~ /&/g; if (0+@leads == 0+@eols && 0+@eols > 0) { - $tex =~ s/&([^\s\}]+)\s/\1&/g; + $tex =~ s/&${lead}/\1&/g; $gathered = 0; + print '% The "gathered" is NOT used because all ' . + (0+@eols) . ' lines are ' . (0+@leads) . " leads\n"; } } $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|/xg; +$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; $tex =~ s/\?/\\varnothing{}/g; @@ -165,30 +205,37 @@ $tex =~ s/:=/\\mathrel{\\vDash}/g; $tex =~ s/\.\.>/\\mathrel{\\phiDotted}/g; $tex =~ s/\|{2,}/|/g; $tex =~ s/\|([^\|]+)\|/\\textnormal{\\texttt{\1}}{}/g; -if ($env eq 'phiq') { +$tex =~ s/\{TEXT(\d+)\}/'\\text{' . @texts[$1] . '}';/ge; +if ($macro eq 'phiq') { print '$' if ($tex ne ''); } else { - print '\begin{', $env, '}'; + print '\begin{', $macro, "}\n"; + if (not($align)) { if ($gathered) { print '\begin{gathered}'; } else { print '\begin{split}'; } + print "\n"; + } } -if ($gathered) { - $tex =~ s/(\\\\(?:\[[^\]]+\])?)&/\1/g; +if ($gathered and not($align)) { $tex =~ s/^&//g; + $tex =~ s/\n&/\n/g; } print $tex; -if ($env eq 'phiq') { +if ($macro eq 'phiq') { print '$' if ($tex ne ''); } else { + if (not($align)) { + print "\n"; if ($gathered) { print '\end{gathered}'; } else { print '\end{split}'; } - print '\end{', $env, '}'; + } + print "\n" . '\end{' . $macro . '}'; } print '\endinput'; \end{VerbatimOut} @@ -196,6 +243,10 @@ print '\endinput'; '\eolang@tmpdir/eolang-phi.pl' saved^^J}% \makeatother +\makeatletter +\newcommand\phiSaveTo[1]{\def\eolang@phiSaveTo{#1}} +\makeatother + \makeatletter\newcommand\eolang@process[1]{ \def\hash{\eolang@mdfive {\eolang@tmpdir/\jobname/phiquation.tex}}% @@ -205,8 +256,10 @@ print '\endinput'; perl "\eolang@tmpdir/eolang-phi.pl" '#1' "\eolang@tmpdir/\jobname/\hash.tex" - \ifdefined\eolang@nocomments | perl -pe 's/\%.*(\\n|$)//g'\fi}% + \ifdefined\eolang@nocomments | perl -pe 's/\%.*(\\n|$)//g'\fi + \ifdefined\eolang@phiSaveTo > \eolang@phiSaveTo\fi}% \setcounter{FancyVerbLine}{\value{eolang@lineno}}% + \def\eolang@phiSaveTo{\relax}% } \newenvironment{phiquation*}% {\catcode`\|=12 \VerbatimEnvironment% @@ -480,8 +533,20 @@ for (my $c = 0; $c < 0+@cmds; $c++) { print ',phi-object'; } print ']'; - print ' (', $head, ')'; - print ' {$' . vertex($head) . '$}'; + print ' (' . $head . ')'; + print ' {'; + if (exists $opts{'tag'}) { + my $t = $opts{'tag'}; + if (index($t, '$') == -1) { + $t = '$' . $t . '$'; + } else { + $t = fmt($t); + } + print $t; + } else { + print '$' . vertex($head) . '$'; + } + print '}'; if (exists $opts{'box'}) { print ' node[phi-box] at ('; print $head, '.south east) {'; @@ -509,7 +574,6 @@ print '\endinput'; \RequirePackage{tikz} \usetikzlibrary{arrows} \usetikzlibrary{shapes} - \usetikzlibrary{snakes} \usetikzlibrary{decorations} \usetikzlibrary{decorations.pathmorphing} \usetikzlibrary{decorations.pathreplacing} @@ -598,6 +662,10 @@ print '\endinput'; above=2pt,sloped/.append style={transform shape}, font={\scriptsize},color=black] +\makeatletter +\newcommand\sodgSaveTo[1]{\def\eolang@sodgSaveTo{#1}} +\makeatother + \makeatletter\newenvironment{sodg}% {\catcode`\|=12 \VerbatimEnvironment% \setcounter{eolang@lineno}{\value{FancyVerbLine}}% @@ -612,9 +680,11 @@ print '\endinput'; \iexec[trace,stdout=\eolang@tmpdir/\jobname/\hash-post.tex]{ perl "\eolang@tmpdir/eolang-sodg.pl" "\eolang@tmpdir/\jobname/\hash.tex" - \ifdefined\eolang@nocomments | perl -pe 's/\%.*(\\n|$)//g'\fi}% + \ifdefined\eolang@nocomments | perl -pe 's/\%.*(\\n|$)//g'\fi + \ifdefined\eolang@sodgSaveTo > \eolang@sodgSaveTo\fi}% \catcode`\$\active% \setcounter{FancyVerbLine}{\value{eolang@lineno}}% + \def\eolang@sodgSaveTo{\relax}% }\makeatother \newcommand\eolang{% @@ -628,10 +698,10 @@ print '\endinput'; \RequirePackage{hyperref} \newcommand\phic{% \ifdefined\anon% - \anon[\texorpdfstring{$\alpha$}{a}-calculus] - {\texorpdfstring{$\varphi$}{phi}-calculus}% + \anon[\texorpdfstring{$\alpha$}{a}-cal\-cu\-lus] + {\texorpdfstring{$\varphi$}{phi}-cal\-cu\-lus}% \else% - \texorpdfstring{$\varphi$}{phi}-calculus% + \texorpdfstring{$\varphi$}{phi}-cal\-cu\-lus% \fi% } @@ -653,8 +723,21 @@ print '\endinput'; \newcommand\phiSlot[1]{% \xrightarrow{\text{\sffamily\scshape #1}}} +\makeatletter +\newcommand{\phiOset}[2]{% + \mathrel{\mathop{#2}\limits^{ + \vbox to 0ex{\kern-2\ex@ + \hbox{$\scriptscriptstyle#1$}\vss}}}} +\newcommand{\phiUset}[2]{% + \mathrel{\mathop{#2}\limits_{ + \vbox to 0ex{\kern-6.3\ex@ + \hbox{$\scriptscriptstyle#1$}\vss}}}} +\makeatother + \newcommand\phiMany[3]{% - \overunderset{\scriptscriptstyle #3}{\scriptscriptstyle #2}{#1}} + \phiOset{#3}{\phiUset{#2}{#1}}} + +\newcommand\phiEOL{\\[-4pt]} \RequirePackage{trimclip} \RequirePackage{amsfonts} |