diff options
author | Karl Berry <karl@freefriends.org> | 2022-11-05 19:50:33 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2022-11-05 19:50:33 +0000 |
commit | 08648da10bda49b5ae1c07cd02d0da5ddccd32cb (patch) | |
tree | c941ccc288fee885d295df4ab01fdb7b496bc263 /Master/texmf-dist/source | |
parent | 8c6cbee6ada537b144ad3f7cea3752effcd61d2c (diff) |
eolang (5nov22)
git-svn-id: svn://tug.org/texlive/trunk@64943 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source')
-rw-r--r-- | Master/texmf-dist/source/latex/eolang/eolang.dtx | 244 |
1 files changed, 166 insertions, 78 deletions
diff --git a/Master/texmf-dist/source/latex/eolang/eolang.dtx b/Master/texmf-dist/source/latex/eolang/eolang.dtx index c7bad937399..3b2db126a48 100644 --- a/Master/texmf-dist/source/latex/eolang/eolang.dtx +++ b/Master/texmf-dist/source/latex/eolang/eolang.dtx @@ -50,7 +50,7 @@ %<package>\NeedsTeXFormat{LaTeX2e} %<package>\ProvidesPackage{eolang} %<*package> -[2022-10-30 0.3.0 Formulas and Graphs for EO Programming Language] +[2022-11-05 0.4.0 Formulas and Graphs for EO Programming Language] %</package> %<*driver> \documentclass{ltxdoc} @@ -61,7 +61,7 @@ \AddToHook{env/verbatim/begin}{\microtypesetup{protrusion=false}} \usepackage{graphicx} \usepackage{xcolor} -\usepackage[runs=1,dtx]{docshots} +\usepackage[runs=2,dtx]{docshots} \usepackage{eolang} \usepackage{href-ul} \PageIndex @@ -171,9 +171,9 @@ % \usepackage{eolang} % \begin{document} % \begin{sodg} -% v0 -% v1 xy:v0,-2,+1 data:42 -% v0->v1 a:$x$ rho +% v0 \\ v0=> \\ v0!A +% v1 xy:v0,-.8,2.8 data:42 \\ =>v1 +% v0->v1 a:x rho % v2 xy:v0,+1,+1 atom:\xi.x+1 % v1->v2 a:|hi| bend:-15 % v2->v0 pi bend:10 @@ -182,25 +182,40 @@ % \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: +% 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 ``|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 ``|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. % \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 ``|rrho|'' places a reverse |rho|, -% \item ``|bend:<angle>|'' bend it right by the amount of |<angle>|, -% \item ``|a:<txt>|'' attaches label |<txt>| to it, +% \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. % \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|.'' + +% 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. + +% Be aware, unrecognized markers are simply ignored, without any error reporting. + % \DescribeMacro{\eolang} % \DescribeMacro{\phic} % \DescribeMacro{\xmir} @@ -321,6 +336,20 @@ % \end{document} % \end{docshot} +% Inside |phiquation| environment you can use labels too (just put |\label| after the formula): +% \begin{docshot} +% \documentclass{article} +% \usepackage{eolang} +% \usepackage[paperwidth=2in]{geometry} +% \pagestyle{empty} +% \begin{document} +% \begin{phiquation} +% x -> [[\Delta -> 42]]. \label{eq:A} +% \end{phiquation} +% Eq.~\ref{eq:A} is easy to read. +% \end{document} +% \end{docshot} + % \StopEventually{} % \section{Implementation} @@ -389,12 +418,12 @@ % \end{macro} % \begin{macro}{eolang-phi.pl} -% \changes{0.0.2}{2022/10/21}{The symbols ``['' and ``]'' replaced with ``[['' and ``]]'' for abstract object brackets, because they conflicted with normal square brackets} +% \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 symbols ``@,'' ``\^{},'' and ``\&'' enabled (varphi, rho, and sigma)} -% \changes{0.1.0}{2022/10/26}{A new Perl script "eolang-phi.pl" added for parsing of phi expressions.} -% \changes{0.2.0}{2022/10/29}{Numbers automatically render as "texttt". No need to use vertical bars around them anymore.} -% \changes{0.3.0}{2022/10/30}{New arrow added, that looks like "leadsto".} +% \changes{0.0.2}{2022/10/21}{Parsing of 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}.} % Then, we create a Perl script for |phiquation| processing using |VerbatimOut| from % \href{https://ctan.org/pkg/fancyvrb}{fancyvrb}: % \begin{macrocode} @@ -522,13 +551,26 @@ print '\endinput', "\n"; % \begin{macro}{eolang-sodg.pl} % \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.} -% \changes{0.1.0}{2022/10/26}{There are two Perl scripts now: one for phiquation, another one for sodg.} -% \changes{0.2.0}{2022/10/28}{The content of "atom" and "data" boxes is parsed automatically as formulas and numbers, respectively.} +% \changes{0.1.0}{2022/10/26}{There are two Perl scripts now: one for \texttt{phiquation}, another one for \texttt{sodg}.} +% \changes{0.2.0}{2022/10/28}{The content of \texttt{atom} and \texttt{data} boxes is parsed automatically as formulas and numbers, respectively.} +% \changes{0.4.0}{2022/10/31}{Labels on the edges are automatically printed as math formulas. Also, boxes are prefixed with \texttt{\char`\\Delta} and \texttt{\char`\\lambda} commands.} +% \changes{0.4.0}{2022/10/31}{Relative positioning of vertices fixed.} +% \changes{0.4.0}{2022/10/31}{Transforming arrows added with \texttt{=>} syntax, also markers with exclamation mark syntax.} % Then, we create a Perl script for |sodg| graphs processing using |VerbatimOut| from % \href{https://ctan.org/pkg/fancyvrb}{fancyvrb}: % \begin{macrocode} \makeatletter \begin{VerbatimOut}{\eolang@tmpdir/eolang-sodg.pl} +sub num { + my ($i) = @_; + $i =~ s/(\+|-)\./\10./g; + return $i; +} +sub fmt { + my ($tex) = @_; + $tex =~ s/\|([^\|]+)\|/\\textnormal{\\texttt{\1}}/g; + return $tex; +} open(my $fh, '<', $ARGV[0]); my $tex; { local $/; $tex = <$fh>; } print '% This file is auto-generated', "\n"; @@ -539,15 +581,15 @@ if (index($tex, "\t") > 0) { print "TABS are prohibited!"; exit 1; } -$tex =~ s/^\s+|\s+$//g; -$tex =~ s/(\\[a-zA-Z]+)\s+/\1/g; -$tex =~ s/\n\s+/\n/g; -$tex =~ s/\|([^\|]+)\|/\\textnormal{\\texttt{\1}}/g; -my @cmds = split (/\n/g, $tex); -foreach my $t (@cmds) { +foreach my $t (split (/\n/g, $tex)) { print '% ', $t, "\n"; } print '% ---', "\n"; +$tex =~ s/^\s+|\s+$//g; +$tex =~ s/\\\\/\n/g; +$tex =~ s/(\\[a-zA-Z]+) +/\1/g; +$tex =~ s/\n\s+/\n/g; +my @cmds = split (/\n/g, $tex); print '\begin{phicture}', "\n"; foreach my $c (@cmds) { my ($head, $tail) = split (/ /, $c, 2); @@ -556,23 +598,82 @@ foreach my $c (@cmds) { my ($q, $t) = split (/:/, $p); $opts{$q} = $t; } - if (index($head, '->') == -1) { + if (index($head, '->') >= 0) { + 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=', num($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'}) { + my $a = $opts{'a'}; + if (index($a, '$') == -1) { + $a = '$' . fmt($a) . '$'; + } else { + $a = fmt($a); + } + print ' node [phi-attr] {', $a, '}'; + } + print ' (', $to, ')'; + } elsif (index($head, '=>') >= 0) { + my ($from, $to) = split (/=>/, $head); + if ($from eq '') { + print '\node [phi-arrow, left=.6cm of ' . + $to . ']'; + } elsif ($to eq '') { + print '\node [phi-arrow, right=.6cm of ' . + $from . ']'; + } 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 { 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; + my $loc = ''; + if ($down > 0) { + $loc = 'below '; + } elsif ($down < 0) { + $loc = 'above '; + } + if ($right > 0) { + $loc = $loc . 'right'; + } elsif ($right < 0) { + $loc = $loc . 'left'; + } + print ',' . $loc . '='; + print abs(num($down)) . 'cm and ' . + abs(num($right)) . 'cm of ' . $v; } if (exists $opts{'data'}) { print ',phi-data'; if (not $opts{'data'} eq '') { my $d = $opts{'data'}; if (index($d, '|') == -1) { - $d = '\textnormal{\texttt{' . $d . '}}'; + $d = '$\Delta\phiDotted\text{' . + '\textnormal{\texttt{' . fmt($d) . '}}}$'; + } else { + $d = fmt($d); } $opts{'box'} = $d; } @@ -581,7 +682,9 @@ foreach my $c (@cmds) { if (not $opts{'atom'} eq '') { my $a = $opts{'atom'}; if (index($a, '$') == -1) { - $a = '$' . $a . '$'; + $a = '$\lambda\phiDotted{}' . fmt($a) . '$'; + } else { + $a = fmt($a); } $opts{'box'} = $a; } @@ -591,10 +694,13 @@ foreach my $c (@cmds) { print ']'; print ' (', $head, ')'; print ' {$'; - if ($head eq 'v0') { + if (index($head, 'v0') == 0) { print '\Phi'; } else { - print 'v_', substr($head, 1); + $name = $head; + $name =~ s/^v/v_/g; + $name =~ s/[^0-9]$//g; + print $name; } print '$}'; if (exists $opts{'box'}) { @@ -602,31 +708,6 @@ foreach my $c (@cmds) { 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"; } @@ -672,9 +753,12 @@ print '\end{phicture}', "\n", '\endinput'; pics/parallel arrow/.style={ code={\draw[-latex,phi-rho] (##1) -- (-##1);}}]}% {\end{tikzpicture}} -\tikzstyle{transforms} = [fill=white!80!black, single arrow, +\tikzstyle{phi-arrow} = [fill=white!80!black, single arrow, minimum height=0.5cm, minimum width=0.5cm, single arrow head extend=2mm] +\tikzstyle{phi-marker} = [inner sep=0pt, minimum height=1.4em, + minimum width=1.4em, font={\small\color{white}\ttfamily}, + fill=gray] \tikzstyle{phi-thing} = [thick,inner sep=0pt,minimum height=2.4em, draw,font={\small}] \tikzstyle{phi-object} = [phi-thing,circle] @@ -695,7 +779,7 @@ print '\end{phicture}', "\n", '\endinput'; % \end{macro} % \begin{macro}{sodg} -% \changes{0.0.2}{2022/10/20}{The environment ``phigure'' renamed to ``sodg'' for the sake of better semantic. The graph in the picture is solely a SODG graph, that's why the name ``sodg'' is better.} +% \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.} % Then, create a new environment |sodg|, as suggested % \href{https://tex.stackexchange.com/questions/661056}{here}: % \begin{macrocode} @@ -719,8 +803,8 @@ print '\end{phicture}', "\n", '\endinput'; % \begin{macro}{\eolang} % Then, we define a simple supplementary command to help you print \eolang{}, the name of our language. -% \changes{0.1.0}{2022/10/25}{New command "eolang" added to print the name of the language in both -% normal and anonymous mode of "acmart"} +% \changes{0.1.0}{2022/10/25}{New command \texttt{\char`\\eolang} added to print the name of the language in both +% normal and anonymous mode of \texttt{acmart}.} % \begin{macrocode} \newcommand\eolang{% \ifdefined\anon% @@ -734,13 +818,14 @@ print '\end{phicture}', "\n", '\endinput'; % \begin{macro}{\phic} % Then, we define a simple supplementary command to help you print \phic{}, the name of our formal apparatus. -% \changes{0.1.0}{2022/10/25}{New command "phic" prints the name of $\varphi$-calculus in both -% normal and anonymous mode of "acmart"} +% \changes{0.1.0}{2022/10/25}{New command \texttt{\char`\\phic} prints the name of $\varphi$-calculus in both +% normal and anonymous mode of \texttt{acmart}.} % \begin{macrocode} \RequirePackage{hyperref} \newcommand\phic{% \ifdefined\anon% - \anon[\texorpdfstring{$\alpha$}{a}-calculus]{\texorpdfstring{$\varphi$}{phi}-calculus}% + \anon[\texorpdfstring{$\alpha$}{a}-calculus] + {\texorpdfstring{$\varphi$}{phi}-calculus}% \else% \texorpdfstring{$\varphi$}{phi}-calculus% \fi% @@ -750,7 +835,7 @@ print '\end{phicture}', "\n", '\endinput'; % \begin{macro}{\xmir} % Then, we define a simple supplementary command to help you print \xmir{}, the name of our XML-based format of program representation. -% \changes{0.2.0}{2022/10/28}{New command "xmir" prints XMIR in both normal and anonymous mode of "acmart"} +% \changes{0.2.0}{2022/10/28}{New command \texttt{\char`\\xmir} prints XMIR in both normal and anonymous mode of \texttt{acmart}.} % \begin{macrocode} \newcommand\xmir{% \ifdefined\anon% @@ -763,17 +848,18 @@ print '\end{phicture}', "\n", '\endinput'; % \end{macro} % \begin{macro}{\phiConst} -% \changes{0.1.0}{2022/10/26}{New command "phiConst" added to denote a link to a constant attribute.} +% \changes{0.1.0}{2022/10/26}{New command \texttt{\char`\\phiConst} added to denote a link to a constant attribute.} % Then, we define a command to render an arrow for a constant attribute, % as suggested \href{https://tex.stackexchange.com/questions/663121}{here}: % \begin{macrocode} \newcommand\phiConst{% - \mathrel{\hspace{.15em}}\mapstochar\mathrel{\hspace{-.15em}}\mapsto} + \mathrel{\hspace{.15em}}% + \mapstochar\mathrel{\hspace{-.15em}}\mapsto} % \end{macrocode} % \end{macro} % \begin{macro}{\phiWave} -% \changes{0.3.0}{2022/10/30}{New command "phiWave" added to denote a link to a multi-layer attribute.} +% \changes{0.3.0}{2022/10/30}{New command \texttt{\char`\\phiWave} added to denote a link to a multi-layer attribute.} % Then, we define a command to render an arrow for a multi-layer attribute, % as suggested \href{https://tex.stackexchange.com/questions/198755}{here}: % \begin{macrocode} @@ -783,14 +869,15 @@ print '\end{phicture}', "\n", '\endinput'; % \end{macro} % \begin{macro}{\phiDotted} -% \changes{0.1.0}{2022/10/27}{New command "phiDotted" added to denote a link to a special attribute.} +% \changes{0.1.0}{2022/10/27}{New command \texttt{\char`\\phiDotted} added to denote a link to a special attribute.} % Then, we define a command to render an arrow for a special attribute, % as suggested \href{https://tex.stackexchange.com/questions/663176}{here}: % \begin{macrocode} \RequirePackage{trimclip} \RequirePackage{amsfonts} \makeatletter -\newcommand{\phiDotted}{\mapstochar\mathrel{\mathpalette\phiDotted@\relax}} +\newcommand{\phiDotted}{% + \mapstochar\mathrel{\mathpalette\phiDotted@\relax}} \newcommand{\phiDotted@}[2]{% \begingroup \settowidth{\dimen\z@}{$\m@th#1\rightarrow$}% @@ -801,7 +888,8 @@ print '\end{phicture}', "\n", '\endinput'; {\resizebox{\dimen\z@}{\height}% {$\m@th#1\dashrightarrow$}}% \hss% - \clipbox{{0.69\width} {-0.1\height} 0 {-\height}}{$\m@th#1\rightarrow$}% + \clipbox{{0.69\width} {-0.1\height} 0 + {-\height}}{$\m@th#1\rightarrow$}% }% }% \ht\z@=\dimen\tw@ \dp\z@=\z@% |