summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/eolang/eolang.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/eolang/eolang.dtx')
-rw-r--r--macros/latex/contrib/eolang/eolang.dtx132
1 files changed, 102 insertions, 30 deletions
diff --git a/macros/latex/contrib/eolang/eolang.dtx b/macros/latex/contrib/eolang/eolang.dtx
index 49a30283bb..74c346d52f 100644
--- a/macros/latex/contrib/eolang/eolang.dtx
+++ b/macros/latex/contrib/eolang/eolang.dtx
@@ -50,7 +50,7 @@
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{eolang}
%<*package>
-[2022-11-13 0.5.0 Formulas and Graphs for EO Programming Language]
+[2022-11-16 0.6.0 Formulas and Graphs for EO Programming Language]
%</package>
%<*driver>
\documentclass{ltxdoc}
@@ -62,7 +62,7 @@
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage[runs=2,dtx]{docshots}
-\usepackage{eolang}
+\usepackage[nocomments]{eolang}
\usepackage{href-ul}
\PageIndex
\EnableCrossrefs
@@ -101,8 +101,8 @@
% \begin{document}
% \begin{phiquation*}
% a -> [[ % it's abstract!
-% ^ !-> $.b.^{^2}, 0-> TRUE,
-% b -> [[ c -> |fn|(56),
+% ^ !-> $.b.^{^2}, 0/t-> TRUE,
+% b -> [[ *-> |fn|(56),
% @ -> |hello|($),
% \Delta ..> 01-FE-C3 ]]]],\\
% x -> [[ \alpha_0 -> ? ]].
@@ -147,7 +147,14 @@
% (|\vDash|).
% \end{itemize}
-% Before any arrow you can put a number, which will be rendered as |\alpha| with an index.
+% 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/|foo|->x}= will render as ``\phiq{0/|foo|->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.
@@ -173,8 +180,7 @@
% \DescribeEnv{sodg}
% The environment |sodg| allows you to draw a \href{https://github.com/objectionary/sodg}{SODG} graph:
% \begin{docshot}
-% \documentclass{article}
-% \pagestyle{empty}
+% \documentclass{standalone}
% \usepackage{eolang}
% \begin{document}
% \begin{sodg}
@@ -208,7 +214,6 @@
% 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 ``|pi|'' makes it dotted, with $\pi$ label.
@@ -343,7 +348,7 @@
% \begin{phiquation*}
% \dfrac{\begin{split}
% x->[[@->y, z->42,
-% 0->?, 1->42]]
+% 0/g->?, 1/|foo|->42]]
% \end{split}}{\begin{split}
% x->[[@->y, z->?, f ~> |pi|(
% 0->[[ \psi !-> |hello|(12) ]],
@@ -450,13 +455,13 @@
% \begin{sodg}
% v0
% v1 xy:v0,.7,1
-% v0->v1 a:x bend:-10
+% 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
+% v2b->v3b a:\psi{} rho
% \end{sodg}
% \end{document}
% \end{docshot}
@@ -534,6 +539,7 @@
% 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).}
% \begin{macrocode}
\RequirePackage{pgfopts}
\RequirePackage{ifluatex}
@@ -542,6 +548,7 @@
/eolang/.cd,
tmpdir/.store in=\eolang@tmpdir,
tmpdir/.default=_eolang\ifxetex-xe\else\ifluatex-lua\fi\fi,
+ nocomments/.store in=\eolang@nocomments,
tmpdir
}
\ProcessPgfOptions{/eolang}
@@ -580,6 +587,7 @@
% \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 \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->}.}
% Then, we create a Perl script for |phiquation| processing using |VerbatimOut| from
% \href{https://ctan.org/pkg/fancyvrb}{fancyvrb}:
% \begin{macrocode}
@@ -610,7 +618,10 @@ if ($env ne 'phiq') {
$tex =~ s/\n*(\\label\{[^\}]+\})\n*/\1/g;
}
$tex =~ s/&/\\sigma{}/g;
-$tex =~ s/(\s|^)([0-9]+)(->|\.\.>|~>|:=|!->)/\1\\alpha_{\2} \3/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') {
$tex =~ s/\\begin\{split\}\n/\\begin{split}&/g;
$tex =~ s/\n\s*\\end\{split\}/\\end{split}/g;
@@ -630,7 +641,8 @@ $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/([\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;
@@ -668,7 +680,7 @@ if ($env eq 'phiq') {
}
print '\end{', $env, '}';
}
-print '\endinput%';
+print '\endinput';
\end{VerbatimOut}
\message{eolang: File with Perl script
'\eolang@tmpdir/eolang-phi.pl' saved^^J}%
@@ -690,17 +702,18 @@ print '\endinput%';
\iexec[trace,stdout=\eolang@tmpdir/\jobname/\hash-post.tex]{
perl "\eolang@tmpdir/eolang-phi.pl"
'#1'
- "\eolang@tmpdir/\jobname/\hash.tex"}%
+ "\eolang@tmpdir/\jobname/\hash.tex"
+ \ifdefined\eolang@nocomments | perl -pe 's/\%.*(\\n|$)//g'\fi}%
\setcounter{FancyVerbLine}{\value{eolang@lineno}}%
}
\newenvironment{phiquation*}%
-{\VerbatimEnvironment%
+{\catcode`\|=12 \VerbatimEnvironment%
\setcounter{eolang@lineno}{\value{FancyVerbLine}}%
\begin{VerbatimOut}
{\eolang@tmpdir/\jobname/phiquation.tex}}
{\end{VerbatimOut}\eolang@process{equation*}}
\newenvironment{phiquation}%
-{\VerbatimEnvironment%
+{\catcode`\|=12 \VerbatimEnvironment%
\setcounter{eolang@lineno}{\value{FancyVerbLine}}%
\begin{VerbatimOut}
{\eolang@tmpdir/\jobname/phiquation.tex}}
@@ -722,7 +735,8 @@ print '\endinput%';
"\eolang@tmpdir/\jobname/\hash.tex"}%
\iexec[trace,stdout=\eolang@tmpdir/\jobname/\hash-post.tex]{
perl \eolang@tmpdir/eolang-phi.pl 'phiq'
- "\eolang@tmpdir/\jobname/\hash.tex"}%
+ "\eolang@tmpdir/\jobname/\hash.tex"
+ \ifdefined\eolang@nocomments | perl -pe 's/\%.*(\\n|$)//g'\fi}%
}\makeatother
% \end{macrocode}
% \end{macro}
@@ -738,6 +752,7 @@ print '\endinput%';
% \changes{0.5.0}{2022/11/09}{Now edges may have \texttt{break} attribute, to make them shorter.}
% \changes{0.5.0}{2022/11/10}{It is possible to use multiple ``equaltion sign'' symbols for transition arrows \texttt{=>}.}
% \changes{0.5.0}{2022/11/12}{It is possible to use tikz commands inside \texttt{sodg} environment.}
+% \changes{0.6.0}{2022/11/13}{The attribute \texttt{rrho} is retired, now \texttt{rho} works just fine in all situations.}
% Then, we create a Perl script for |sodg| graphs processing using |VerbatimOut| from
% \href{https://ctan.org/pkg/fancyvrb}{fancyvrb}:
% \begin{macrocode}
@@ -812,20 +827,22 @@ for (my $c = 0; $c < 0+@cmds; $c++) {
$opts{'a'} = '\pi';
}
}
+ if (exists $opts{'rho'} and not(exists $opts{'bend'})) {
+ $draw = $draw . '<MB:,phi-rho>';
+ }
$draw = $draw . ']';
my ($from, $to) = split (/->/, $head);
$draw = $draw . " (${from}) ";
if (exists $opts{'bend'}) {
- $draw = $draw . 'edge [<F:draw=none,><MF:bend right=' .
- num($opts{'bend'}) . '>]';
+ $draw = $draw . 'edge [<F:draw=none><MF:,bend right=' .
+ num($opts{'bend'}) . '>';
+ if (exists $opts{'rho'}) {
+ $draw = $draw . '<MB:,phi-rho>';
+ }
+ $draw = $draw . ']';
} else {
$draw = $draw . '--';
}
- if (exists $opts{'rho'} or exists $opts{'rrho'}) {
- $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'};
if (index($a, '$') == -1) {
@@ -992,7 +1009,7 @@ foreach my $c (@cmds) {
print '% ', $c, "\n";
}
print '% --- (' . (0+@cmds) . " lines)\n";
-print '\endinput%';
+print '\endinput';
\end{VerbatimOut}
\message{eolang: File with Perl script
'\eolang@tmpdir/eolang-sodg.pl' saved^^J}%
@@ -1019,8 +1036,11 @@ print '\endinput%';
\usetikzlibrary{snakes}
\usetikzlibrary{decorations}
\usetikzlibrary{decorations.pathmorphing}
+ \usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
+ \usetikzlibrary{math}
+ \usetikzlibrary{arrows.meta}
% \end{macrocode}
% \end{macro}
@@ -1045,8 +1065,59 @@ print '\endinput%';
\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}]
+\tikzset{%
+ phi-rho/.style={
+ postaction={%
+ decoration={
+ show path construction,
+ curveto code={
+ \tikzmath{
+ coordinate \I, \F, \v;
+ \I = (\tikzinputsegmentfirst);
+ \F = (\tikzinputsegmentlast);
+ \v = ($(\I) -(\F)$);
+ real \d, \a, \r, \t;
+ \d = 0.8;
+ \t = atan2(\vy, \vx);
+ if \vx<0 then { \a = 90; } else { \a = -90; };
+ {
+ \draw[arrows={-latex}, decorate,
+ decoration={%
+ snake, amplitude=.4mm,
+ segment length=2mm,
+ post length=1mm
+ }]
+ ($(\F)!.5!(\I) +(\t: -\d em) +(\t +\a: 1ex)$)
+ -- ++(\t: 2*\d em);
+ };
+ }
+ },
+ lineto code={
+ \tikzmath{
+ coordinate \I, \F, \v;
+ \I = (\tikzinputsegmentfirst);
+ \F = (\tikzinputsegmentlast);
+ \v = ($(\I) -(\F)$);
+ real \d, \a, \r, \t;
+ \d = 0.8;
+ \t = atan2(\vy, \vx);
+ if \vx<0 then { \a = 90; } else { \a = -90; };
+ {
+ \draw[arrows={-latex}, decorate,
+ decoration={%
+ snake, amplitude=.4mm,
+ segment length=2mm,
+ post length=1mm}]
+ ($(\F)!.5!(\I) +(\t: -\d em) +(\t +\a: 1ex)$)
+ -- ++(\t: 2*\d em);
+ };
+ }
+ }
+ },
+ decorate
+ }
+ }
+}
\tikzstyle{phi-pi} = [draw,dotted]
\tikzstyle{phi-atom} = [phi-object,double]
\tikzstyle{phi-box} = [xshift=-5pt,yshift=3pt,draw,fill=white,
@@ -1064,7 +1135,7 @@ print '\endinput%';
% \href{https://tex.stackexchange.com/questions/661056}{here}:
% \begin{macrocode}
\makeatletter\newenvironment{sodg}%
-{\VerbatimEnvironment%
+{\catcode`\|=12 \VerbatimEnvironment%
\setcounter{eolang@lineno}{\value{FancyVerbLine}}%
\begin{VerbatimOut}
{\eolang@tmpdir/\jobname/sodg.tex}}
@@ -1075,7 +1146,8 @@ print '\endinput%';
"\eolang@tmpdir/\jobname/\hash.tex"}%
\iexec[trace,stdout=\eolang@tmpdir/\jobname/\hash-post.tex]{
perl "\eolang@tmpdir/eolang-sodg.pl"
- "\eolang@tmpdir/\jobname/\hash.tex"}%
+ "\eolang@tmpdir/\jobname/\hash.tex"
+ \ifdefined\eolang@nocomments | perl -pe 's/\%.*(\\n|$)//g'\fi}%
\setcounter{FancyVerbLine}{\value{eolang@lineno}}%
}\makeatother
% \end{macrocode}