diff options
author | Karl Berry <karl@freefriends.org> | 2022-10-20 20:34:25 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2022-10-20 20:34:25 +0000 |
commit | 1bea5105918383ace6baf917095f5127b4b52025 (patch) | |
tree | 03e6ccdb408df98c7878d48af1a5199a7d8b5cdc /Master/texmf-dist/tex | |
parent | 2ef18d0d45d4c9ff3d8c366f375797fbd4bbef15 (diff) |
eolang (20oct22)
git-svn-id: svn://tug.org/texlive/trunk@64763 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/eolang/eolang.sty | 233 |
1 files changed, 233 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/eolang/eolang.sty b/Master/texmf-dist/tex/latex/eolang/eolang.sty new file mode 100644 index 00000000000..a3b5b973cb3 --- /dev/null +++ b/Master/texmf-dist/tex/latex/eolang/eolang.sty @@ -0,0 +1,233 @@ +%% +%% This is file `eolang.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% eolang.dtx (with options: `package') +%% (The MIT License) +%% +%% Copyright (c) 2021-2022 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. + + + +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{eolang} +[2022-10-20 0.0.1 Formulas and Graphs for EO Programming Language] + + + + + + + + + + +\RequirePackage{stmaryrd} +\RequirePackage{amsmath} +\RequirePackage{amsfonts} +\RequirePackage{iexec} +\RequirePackage{fancyvrb} + +\makeatletter\newcommand\eolang@env[2]{ + \iexec[trace]{ + /bin/echo -n '\\begin{#1}\\begin{split} &'; + /bin/echo -n '\detokenize{#2}' + | perl -pe 's/^\\r\\+//g' + | perl -pe 's/\\r\\+$//g' + | perl -pe 's/->/\\\\mapsto/g' + | perl -pe 's/\unexpanded{~}>/\\\\mapstochar\\\\dashrightarrow/g' + | perl -pe 's/\\|([^\\|]+)\\|/\\\\texttt{\\1}/g' + | perl -pe 's/\\[/\\\\llbracket/g' + | perl -pe 's/\\]/\\\\rrbracket/g' + | perl -pe 's/\\r\\r/\\\\\\\\ \&/g' + | perl -pe 's/\\r/\\\\\\\\[-4pt] \&/g' + | perl -pe 's/([^& ]) {2}([^ ])/\\1 \\2/g' + | perl -pe 's/ {2}/\\\\quad{}/g' + ; + /bin/echo -n '\\end{split}\\end{#1}\\endinput' + }% +}\makeatother + +\makeatletter +\NewDocumentEnvironment{phiquation*}{b}{% + \eolang@env{equation*}{#1} +}{} +\NewDocumentEnvironment{phiquation}{b}{% + \eolang@env{equation}{#1} +}{} +\makeatother +\AddToHook{env/phiquation*/begin}{\obeylines\obeyspaces} +\AddToHook{env/phiquation/begin}{\obeylines\obeyspaces} + +\newcommand\phiq[1]{ + \iexec[trace]{ + /bin/echo -n '$'; + /bin/echo -n '\detokenize{#1}' + | perl -pe 's/->/\\\\mapsto/g' + | perl -pe 's/\unexpanded{~}>/\\\\mapstochar\\\\dashrightarrow/g' + | perl -pe 's/\\[/\\\\llbracket/g' + | perl -pe 's/\\]/\\\\rrbracket/g' + ; + /bin/echo -n '$\\endinput' + }% +} + +\begin{VerbatimOut}{\jobname.pl.eolang} +$tex = $ARGV[0]; +$tex =~ s/^\s+|\s+$//g; +$tex =~ s/(\\[a-zA-Z]+)\s+/\1/g; +$tex =~ s/\r\s+/\r/g; +$tex =~ s/\|([^\|]+)\|/\\texttt{\1}/g; +my @cmds = split (/\r/g, $tex); +print '\begin{phig}', "\n"; +foreach my $c (@cmds) { + my ($head, $tail) = split (/ /, $c, 2); + my %opts = {}; + foreach my $p (split (/ /, $tail)) { + my ($q, $t) = split (/:/, $p); + $opts{$q} = $t; + } + if (index($head, '->') == -1) { + print '\node['; + if (exists $opts{'xy'}) { + my ($v, $right, $down) = split(/,/, $opts{'xy'}); + print ',below right='; + print $down; + print 'cm and '; + print $right; + print 'cm of '; + print $v; + } + if (exists $opts{'data'}) { + print ',phi-data'; + if (not $opts{'data'} eq '') { + $opts{'box'} = $opts{'data'}; + } + } elsif (exists $opts{'atom'}) { + print ',phi-atom'; + if (not $opts{'atom'} eq '') { + $opts{'box'} = $opts{'atom'}; + } + } else { + print ',phi-object'; + } + print ']'; + print ' (', $head, ')'; + print ' {$'; + if ($head eq 'v0') { + print '\Phi'; + } else { + print 'v_', substr($head, 1); + } + print '$}'; + if (exists $opts{'box'}) { + print ' node[phi-box] at ('; + print $head, '.south east) {'; + print $opts{'box'}, '}'; + } + } else { + print '\draw['; + if (exists $opts{'pi'}) { + print ',phi-pi'; + if (not exists $opts{'a'}) { + $opts{'a'} = '$\pi$'; + } + } + print ']'; + my ($from, $to) = split (/->/, $head); + print ' (', $from, ') '; + if (exists $opts{'bend'}) { + print 'edge [bend right=', $opts{'bend'}, ']'; + } else { + print '--'; + } + 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}}'; + } + if (exists $opts{'a'}) { + print ' node [phi-attr] {', $opts{'a'}, '}'; + } + print ' (', $to, ')'; + } + print ";\n"; +} +print '\end{phig}', "\n", '\endinput'; +\end{VerbatimOut} +\message{^^Jeolang: file with Perl script (\jobname.pl.eolang) saved^^J}% +\iexec[trace,stdout=/dev/null]{ + perl -pi -e 's/(\\\\[a-zA-Z])\\s+/\\1/g' \jobname.pl.eolang} + +\RequirePackage{tikz} + \usetikzlibrary{arrows} + \usetikzlibrary{shapes} + \usetikzlibrary{decorations} + \usetikzlibrary{decorations.pathmorphing} + \usetikzlibrary{intersections} + \usetikzlibrary{positioning} + \usetikzlibrary{backgrounds} + \usetikzlibrary{calc} + \usetikzlibrary{shapes.arrows} + +\newenvironment{phig}% + {\noindent\begin{tikzpicture}[ + ->,>=stealth',node distance=0,thick, + pics/parallel arrow/.style={ + code={\draw[-latex,phi-rho] (##1) -- (-##1);}}]}% + {\end{tikzpicture}} +\tikzstyle{transforms} = [fill=white!80!black, single arrow, + minimum height=0.5cm, minimum width=0.5cm, + single arrow head extend=2mm] +\tikzstyle{phi-thing} = [thick,inner sep=0pt,minimum height=2.4em, + draw,font={\small}] +\tikzstyle{phi-object} = [phi-thing,circle] +\tikzstyle{phi-data} = [phi-thing,regular polygon, + regular polygon sides=8] +\tikzstyle{phi-empty} = [phi-object] +\tikzstyle{phi-rho} = [draw,decorate,decoration={ + snake,amplitude=.4mm,segment length=2mm,post length=1mm}] +\tikzstyle{phi-pi} = [draw,dotted] +\tikzstyle{phi-atom} = [phi-object,double] +\tikzstyle{phi-box} = [xshift=-5pt,yshift=3pt,draw,fill=white, + rectangle,thin,minimum width=1.2em,anchor=north west, + font={\scriptsize}] +\tikzstyle{phi-attr} = [midway,sloped,inner sep=0pt, + above=2pt,sloped/.append style={transform shape}, + font={\scriptsize},color=black] + +\NewDocumentEnvironment{phigure}{b}{% + \catcode`\ =10 % + \catcode`\^^M=5 % + \iexec[trace,stdout=\jobname.tex.eolang]{ + perl \jobname.pl.eolang '\detokenize{#1}'}% +}{} +\AddToHook{env/phigure/before}{\bgroup\obeylines\obeyspaces} +\AddToHook{env/phigure/after}{\egroup} + + + + +\endinput +%% +%% End of file `eolang.sty'. |