% \iffalse meta-comment
% (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.
% \fi

% \CheckSum{0}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}

% \GetFileInfo{eolang.dtx}
% \DoNotIndex{\endgroup,\begingroup,\let,\else,\s,\n,\r,\\,\1,\fi}

% \iffalse
%<*driver>
\ProvidesFile{eolang.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{eolang}
%<*package>
[2022-10-30 0.3.0 Formulas and Graphs for EO Programming Language]
%</package>
%<*driver>
\documentclass{ltxdoc}
\usepackage[maxnames=1,minnames=1,maxbibnames=1,natbib=true,citestyle=authoryear,bibstyle=authoryear,doi=false,url=false,isbn=false,isbn=false]{biblatex}
\addbibresource{eolang.bib}
\usepackage[tt=false, type1=true]{libertine}
\usepackage{microtype}
\AddToHook{env/verbatim/begin}{\microtypesetup{protrusion=false}}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage[runs=1,dtx]{docshots}
\usepackage{eolang}
\usepackage{href-ul}
\PageIndex
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
	\DocInput{eolang.dtx}
	\PrintChanges
	\PrintIndex
\end{document}
%</driver>
% \fi

% \title{\includegraphics[height=1in]{cactus.pdf} \\ |eolang|: \LaTeX{} Package \\ for Formulas and Graphs \\ of EO Programming Language \\ and $\varphi$-calculus\thanks{The sources are in GitHub at \href{https://github.com/objectionary/eolang.sty}{objectionary/eolang.sty}}}
% \author{Yegor Bugayenko \\ \texttt{yegor256@gmail.com}}
% \date{\filedate, \fileversion}
%
% \maketitle
%
% \textbf{\color{red}NB!}
% You must run \TeX{} processor with |--shell-escape| option
% and you must have \href{https://www.perl.org}{Perl} installed.
% This package doesn't work on Windows.

% \section{Introduction}
%
% This package helps you print formulas of $\varphi$-calculus,
% which is a formal foundation of \href{https://www.eolang.org}{EO}
% programming language. The calculus was introduced by \citet{bugayenko2021eolang}
% and later formalized by \citet{kudasov2021}. Here is how you render
% a simple expression:
% \begin{docshot}
% \documentclass{article}
% \pagestyle{empty}
% \usepackage{eolang}
% \begin{document}
% \begin{phiquation*}
% a -> [[
%   ^ !-> $.b,
%   b -> [[ c -> |fn|(56),
%     @ -> |hello|($),
%     \Delta ..> 01-FE-C3 ]]]],\\
% x -> [[ \alpha_0 -> ? ]].
% \end{phiquation*}
% \end{document}
% \end{docshot}

% \DescribeEnv{phiquation}
% The environment |phiquation| lets you write a $\varphi$-calculus expressions
% using simple plain-text notation, where:
% \begin{itemize}\setlength\itemsep{0em}
%   \item ``|@|'' maps to ``$\varphi$''
%     (|\varphi|),
%   \item ``|^|'' maps to ``$\rho$''
%     (|\rho|),
%   \item ``|$|'' maps to ``$\xi$''
%     (|\xi|),
%   \item ``|&|'' maps to ``$\sigma$''
%     (|\sigma|),
%   \item ``|?|'' maps to ``$\varnothing$''
%     (|\varnothing|),
%   \item ``|->|'' maps to ``$\mapsto$''
%     (|\mapsto|),
%   \item ``|~>|'' maps to ``$\phiWave$''
%     (|\phiWave|),
%   \item ``|!->|'' maps to ``$\phiConst$''
%     (|\phiConst|),
%   \item ``|..>|'' maps to ``$\phiDotted$''
%     (|\phiDotted|),
%   \item ``|[[|'' maps to ``$\llbracket$''
%     (|\llbracket|),
%   \item ``|]]|'' maps to ``$\rrbracket$''
%     (|\rrbracket|),
%   \item ``$\vert$|abc|$\vert$'' maps to ``\texttt{abc}''
%     (|\texttt{abc}|).
% \end{itemize}
% Also, a few symbols are supported for $\varphi$PU architecture:
% \begin{itemize}\setlength\itemsep{0em}
%   \item ``|-abc>|'' maps to ``$\xrightarrow{\text{\sffamily\scshape abc}}$''
%     (|\xrightarrow{\text{\sffamily\scshape abc}}|),
%   \item ``|:=|'' maps to ``$\vDash$''
%     (|\vDash|).
% \end{itemize}

% \DescribeMacro{\phiq}
% The command |\phiq| lets you inline a $\varphi$-calculus expressions
% using the same simple plain-text notation:
% \begin{docshot}
% \documentclass{article}
% \pagestyle{empty}
% \usepackage{eolang}
% \begin{document}
% A simple object
% \phiq{x -> [[@ -> y]]} \\
% is a decorator of
% the data object \\
% \phiq{y -> [[\Delta ..> 42]]}.
% \end{document}
% \end{docshot}

% \DescribeEnv{sodg}
% The environment |sodg| allows you to draw a \href{https://github.com/objectionary/sodg}{SODG} graph:
% \begin{docshot}
% \documentclass{article}
% \pagestyle{empty}
% \usepackage{eolang}
% \begin{document}
% \begin{sodg}
% v0
% v1 xy:v0,-2,+1 data:42
% 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
% \end{sodg}
% \end{document}
% \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:
% \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.
% \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 ``|pi|'' makes it dotted, with $\pi$ label.
% \end{itemize}

% \DescribeMacro{\eolang}
% \DescribeMacro{\phic}
% \DescribeMacro{\xmir}
% There is also a no-argument command |\eolang| to help you print the name of
% \eolang{} language. It understands |anonymous| mode of \href{https://ctan.org/pkg/acmart}{acmart} and prints itself
% differently, to double-blind your paper. There is also |\phic| command to print
% the name of \phic{}, also sensitive to |anonymous| mode. The macro |\xmir| prints "XMIR".
% \begin{docshot}
% \documentclass[anonymous]{acmart}
% \thispagestyle{empty}
% \usepackage{eolang}
% \begin{document}
% In our research we use \eolang{}, \\
% an experimental object-oriented \\
% dataflow language, \phic{}, \\
% as its formal foundation, and \xmir{} \\
% --- its XML-based presentation.
% \end{document}
% \end{docshot}

% \DescribeMacro{\phiConst}
% A simple commands is defined to help you render an arrow for a constant attribute.
% It is recommende not to use it directly, but use |!->| instead. However, if you
% want to use |\phiConst|, wrap it in |\mathrel| for better display:
% \begin{docshot}
% \documentclass{article}
% \pagestyle{empty}
% \usepackage{eolang}
% \begin{document}
% \phiq{[[ x \mathrel{\phiConst} y ]]}
% \end{document}
% \end{docshot}

% \section{Package Options}

% \DescribeMacro{tmpdir}
% The default location of temp files is |_eolang|. You can change this using |tmpdir| option:
%\iffalse
%<*verb>
%\fi
\begin{verbatim}
\usepackage[tmpdir=/tmp/foo]{eolang}
\end{verbatim}
%\iffalse
%</verb>
%\fi

% \section{More Examples}

% The |phiquation| environment treats ends of line as signals to start
% new lines in the formula. If you don't want this to happen and want to parse
% the next line as the a continuation of the current line, you can use a single
% backslash as it's done here:
% \begin{docshot}
% \documentclass{article}
% \usepackage{amsmath}
% \usepackage{eolang}
% \pagestyle{empty}
% \begin{document}
% \begin{phiquation*}
% \dfrac \
%  {x->[[@->y]] \quad y->[[z->42]]} \
%  {x.z -> 42} \
%  \text{\sffamily R1}
% \end{phiquation*}
% \end{document}
% \end{docshot}

% This is how you can use |\dfrac| from |amsmath| for large inference rules,
% with the help of |\begin{split}| and |\end{split}|:
% \begin{docshot}
% \documentclass{article}
% \usepackage{amsmath}
% \usepackage{eolang}
% \pagestyle{empty}
% \begin{document}
% \begin{phiquation*}
% \dfrac{\begin{split}
% x->[[@->y, z->42,
%   \alpha_0->?, \alpha_1->42]]
% \end{split}}{\begin{split}
% x->[[@->y, z->?, f ~> |pi|(
%   \alpha_0->[[ \psi !-> |hello|(12) ]],
%     \alpha_1->42)]]
% \end{split}}\text{R2}.
% \end{phiquation*}
% \end{document}
% \end{docshot}

% The |phiquation| environment may be used together with \href{https://ctan.org/pkg/acmart}{acmart}:
% \begin{docshot}
% \documentclass{acmart}
% \usepackage{eolang}
% \thispagestyle{empty}
% \begin{document}
% \begin{phiquation*}
% x -> [[
%   y -> [[
%     z !-> $, f ..> ? ]]]],\\
% \beta_1 := [ \psi -wait> ? ].
% \end{phiquation*}
% \end{document}
% \end{docshot}

% The |phiquation| environment will automatically align formulas by the first
% arrow, if there are only left-aligned formulas:
% \begin{docshot}
% \documentclass{acmart}
% \usepackage{eolang}
% \thispagestyle{empty}
% \begin{document}
% \begin{phiquation*}
% x(\pi) -> [[\lambda ..> f_1]], \\
% x(a,b,c) -> [[ \alpha_0 -> ?, \
%   @ -> |hello|($) ]], \\
% \Delta = |43-09|.
% \end{phiquation*}
% \end{document}
% \end{docshot}

% \StopEventually{}

% \section{Implementation}
% \changes{0.0.1}{2022/10/15}{First draft.}

% First, we include a few packages.
% We need \href{https://ctan.org/pkg/stmaryrd}{stmaryrd} for |\llbracket| and |\rrbracket| commands:
%    \begin{macrocode}
\RequirePackage{stmaryrd}
%    \end{macrocode}
% We need \href{https://ctan.org/pkg/amsmath}{amsmath} for |equation*| environment:
%    \begin{macrocode}
\RequirePackage{amsmath}
%    \end{macrocode}
% We need \href{https://ctan.org/pkg/amssymb}{amssymb} for |\varnothing| command. We disable |\Bbbk|
% because it may conflict with some packages from \href{https://ctan.org/pkg/acmart}{acmart}:
%    \begin{macrocode}
\let\Bbbk\relax\RequirePackage{amssymb}
%    \end{macrocode}
% We need \href{https://ctan.org/pkg/fancyvrb}{fancyvrb} for |\VerbatimEnvironment| command:
%    \begin{macrocode}
\RequirePackage{fancyvrb}
%    \end{macrocode}
% We need \href{https://ctan.org/pkg/iexec}{iexec} for executing Perl scripts:
%    \begin{macrocode}
\RequirePackage{iexec}
%    \end{macrocode}

% Then, we process package options:
% \changes{0.1.0}{2022/10/26}{Parsing of package options introduced.}
%    \begin{macrocode}
\RequirePackage{pgfopts}
\RequirePackage{ifluatex}
\RequirePackage{ifxetex}
\pgfkeys{
  /eolang/.cd,
  tmpdir/.store in=\eolang@tmpdir,
  tmpdir/.default=_eolang\ifxetex-xe\else\ifluatex-lua\fi\fi,
  tmpdir
}
\ProcessPgfOptions{/eolang}
%    \end{macrocode}

% Then, we make a directory where all temporary files will be kept:
%    \begin{macrocode}
\iexec[null]{mkdir -p "\eolang@tmpdir/\jobname"}%
%    \end{macrocode}

% \begin{macro}{\eolang@lineno}
% \changes{0.3.0}{2022/10/30}{New counter for protecting lineno.}
% Then, we define an internal counter to protect line number from changing:
%    \begin{macrocode}
\makeatletter\newcounter{eolang@lineno}\makeatother
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\eolang@mdfive}
% \changes{0.1.0}{2022/10/26}{New supplementary command added to calculate MD5 sum of a file.}
% Then, we define a command for MD5 hash calculating of a file:
%    \begin{macrocode}
\RequirePackage{pdftexcmds}
\makeatletter
\newcommand\eolang@mdfive[1]{\pdf@filemdfivesum{#1}}
\makeatother
%    \end{macrocode}
% \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}{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".}
% Then, we create a Perl script for |phiquation| processing using |VerbatimOut| from
% \href{https://ctan.org/pkg/fancyvrb}{fancyvrb}:
%    \begin{macrocode}
\makeatletter
\begin{VerbatimOut}{\eolang@tmpdir/eolang-phi.pl}
$env = $ARGV[0];
open(my $fh, '<', $ARGV[1]);
my $tex; { local $/; $tex = <$fh>; }
print '% This file is auto-generated', "\n";
print '% There are ', length($tex),
  ' chars in the input: ', $ARGV[1], "\n";
print '% ---', "\n";
if (index($tex, "\t") > 0) {
  print "TABS are prohibited!";
  exit 1;
}
my @lines = split (/\n/g, $tex);
foreach my $t (@lines) {
  print '% ', $t, "\n";
}
print '% ---', "\n";
if ($env eq 'phiq') {
  print '$';
} else {
  print '\begin{', $env, '}\begin{split}';
}
$tex =~ s/^\s+|\s+$//g;
if ($env ne 'phiq') {
  $tex =~ s/\s+\\\n\s*//g;
  $tex =~ s/\\\\\n/\n\n/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;
if ($env 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/([^&\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;
  if (0+@leads == 0+@eols && 0+@eols > 0) {
    $tex =~ s/&([^\s]+)\s/\1&/g;
  }
}
print $tex;
if ($env eq 'phiq') {
  print '$';
} else {
  print '\end{split}\end{', $env, '}';
}
print '\endinput', "\n";
\end{VerbatimOut}
\message{eolang: File with Perl script
  '\eolang@tmpdir/eolang-phi.pl' saved^^J}%
\iexec[trace,null]{perl -pi -e 's/(\\\\[a-zA-Z])\\s+/\\1/g'
  "\eolang@tmpdir/eolang-phi.pl"}
\makeatother
%    \end{macrocode}
% \end{macro}

% \begin{macro}{phiquation}
% Then, we define |phiquation| and |phiquation*| environments through a supplementary
% |\eolang@process| command:
%    \begin{macrocode}
\makeatletter\newcommand\eolang@process[1]{
  \def\hash{\eolang@mdfive
    {\eolang@tmpdir/\jobname/phiquation.tex}}%
  \iexec[null]{cp "\eolang@tmpdir/\jobname/phiquation.tex"
    "\eolang@tmpdir/\jobname/\hash.tex"}%
  \iexec[trace,stdout=\eolang@tmpdir/\jobname/\hash-post.tex]{
    perl "\eolang@tmpdir/eolang-phi.pl"
    '#1'
    "\eolang@tmpdir/\jobname/\hash.tex"}%
  \setcounter{FancyVerbLine}{\value{eolang@lineno}}%
}
\newenvironment{phiquation*}%
{\VerbatimEnvironment%
\setcounter{eolang@lineno}{\value{FancyVerbLine}}%
\begin{VerbatimOut}
  {\eolang@tmpdir/\jobname/phiquation.tex}}
{\end{VerbatimOut}\eolang@process{equation*}}
\newenvironment{phiquation}%
{\VerbatimEnvironment%
\setcounter{eolang@lineno}{\value{FancyVerbLine}}%
\begin{VerbatimOut}
  {\eolang@tmpdir/\jobname/phiquation.tex}}
{\end{VerbatimOut}\eolang@process{equation}}
\makeatother
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\phiq}
% \changes{0.0.2}{2022/10/21}{Parsing of additional symbols enabled.}
% Then, we define |\phiq| command:
%    \begin{macrocode}
\makeatletter\newcommand\phiq[1]{%
  \iexec[trace,quiet,stdout=\eolang@tmpdir/\jobname/phiq.tex]{
    /bin/echo '\detokenize{#1}'}%
  \def\hash{\eolang@mdfive
    {\eolang@tmpdir/\jobname/phiq.tex}}%
  \iexec[null]{cp "\eolang@tmpdir/\jobname/phiq.tex"
    "\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"}%
}\makeatother
%    \end{macrocode}
% \end{macro}

% \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.}
% 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}
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;
}
$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) {
  print '% ', $t, "\n";
}
print '% ---', "\n";
print '\begin{phicture}', "\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 '') {
        my $d = $opts{'data'};
        if (index($d, '|') == -1) {
          $d = '\textnormal{\texttt{' . $d . '}}';
        }
        $opts{'box'} = $d;
      }
    } elsif (exists $opts{'atom'}) {
      print ',phi-atom';
      if (not $opts{'atom'} eq '') {
        my $a = $opts{'atom'};
        if (index($a, '$') == -1) {
          $a = '$' . $a . '$';
        }
        $opts{'box'} = $a;
      }
    } 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{phicture}', "\n", '\endinput';
\end{VerbatimOut}
\message{eolang: File with Perl script
  '\eolang@tmpdir/eolang-sodg.pl' saved^^J}%
\iexec[trace,null]{perl -pi -e 's/(\\\\[a-zA-Z])\\s+/\\1/g'
  "\eolang@tmpdir/eolang-sodg.pl"}
\makeatother
%    \end{macrocode}
% \end{macro}

% \begin{macro}{FancyVerbLine}
% Then, we reset the counter for \href{https://ctan.org/pkg/fancyvrb}{fancyvrb}, so that
% it starts counting lines from zero when the document starts rendering:
%    \begin{macrocode}
\setcounter{FancyVerbLine}{0}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{tikz}
% Then, we include |tikz| package and its libraries:
%    \begin{macrocode}
\RequirePackage{tikz}
  \usetikzlibrary{arrows}
  \usetikzlibrary{shapes}
  \usetikzlibrary{decorations}
  \usetikzlibrary{decorations.pathmorphing}
  \usetikzlibrary{intersections}
  \usetikzlibrary{positioning}
  \usetikzlibrary{calc}
  \usetikzlibrary{shapes.arrows}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{phicture}
% Then, we define internal environment |phicture|:
%    \begin{macrocode}
\newenvironment{phicture}%
  {\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]
%    \end{macrocode}
% \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.}
% Then, create a new environment |sodg|, as suggested
% \href{https://tex.stackexchange.com/questions/661056}{here}:
%    \begin{macrocode}
\makeatletter\newenvironment{sodg}%
{\VerbatimEnvironment%
\setcounter{eolang@lineno}{\value{FancyVerbLine}}%
\begin{VerbatimOut}
  {\eolang@tmpdir/\jobname/sodg.tex}}
{\end{VerbatimOut}%
  \def\hash{\eolang@mdfive
    {\eolang@tmpdir/\jobname/sodg.tex}}%
  \iexec[null]{cp "\eolang@tmpdir/\jobname/sodg.tex"
    "\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"}%
  \setcounter{FancyVerbLine}{\value{eolang@lineno}}%
}\makeatother
%    \end{macrocode}
% \end{macro}

% \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"}
%    \begin{macrocode}
\newcommand\eolang{%
  \ifdefined\anon%
    \anon[XYZ]{{\sffamily EO}}%
  \else%
    {\sffamily EO}%
  \fi%
}
%    \end{macrocode}
% \end{macro}

% \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"}
%    \begin{macrocode}
\RequirePackage{hyperref}
\newcommand\phic{%
  \ifdefined\anon%
    \anon[\texorpdfstring{$\alpha$}{a}-calculus]{\texorpdfstring{$\varphi$}{phi}-calculus}%
  \else%
    \texorpdfstring{$\varphi$}{phi}-calculus%
  \fi%
}
%    \end{macrocode}
% \end{macro}

% \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"}
%    \begin{macrocode}
\newcommand\xmir{%
  \ifdefined\anon%
    \anon[XML']{XMIR}%
  \else%
    XMIR%
  \fi%
}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\phiConst}
% \changes{0.1.0}{2022/10/26}{New command "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}
%    \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.}
% 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}
\newcommand\phiWave{%
  \mapstochar\mathrel{\mspace{0.45mu}}\leadsto}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\phiDotted}
% \changes{0.1.0}{2022/10/27}{New command "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@}[2]{%
  \begingroup
  \settowidth{\dimen\z@}{$\m@th#1\rightarrow$}%
  \settoheight{\dimen\tw@}{$\m@th#1\rightarrow$}%
  \sbox\z@{%
    \makebox[\dimen\z@][s]{%
      \clipbox{0 0 {0.4\width} 0}%
        {\resizebox{\dimen\z@}{\height}%
          {$\m@th#1\dashrightarrow$}}%
      \hss%
      \clipbox{{0.69\width} {-0.1\height} 0 {-\height}}{$\m@th#1\rightarrow$}%
    }%
  }%
  \ht\z@=\dimen\tw@ \dp\z@=\z@%
  \box\z@%
  \endgroup}\makeatother
%    \end{macrocode}
% \end{macro}

% \Finale

% \clearpage
% \printbibliography
% \clearpage

% \PrintChanges
% \clearpage
% \PrintIndex
