texlive[66952] Master/texmf-dist: mptrees (27apr23)
commits+karl at tug.org
commits+karl at tug.org
Thu Apr 27 22:36:32 CEST 2023
Revision: 66952
http://tug.org/svn/texlive?view=revision&revision=66952
Author: karl
Date: 2023-04-27 22:36:32 +0200 (Thu, 27 Apr 2023)
Log Message:
-----------
mptrees (27apr23)
Modified Paths:
--------------
trunk/Master/texmf-dist/doc/metapost/mptrees/README.md
trunk/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.pdf
trunk/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.tex
trunk/Master/texmf-dist/metapost/mptrees/mptrees.mp
Modified: trunk/Master/texmf-dist/doc/metapost/mptrees/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/metapost/mptrees/README.md 2023-04-26 23:49:55 UTC (rev 66951)
+++ trunk/Master/texmf-dist/doc/metapost/mptrees/README.md 2023-04-27 20:36:32 UTC (rev 66952)
@@ -1,8 +1,16 @@
-Package mptrees - Version 21.10 - November 2, 2021
+Package mptrees - Version 23.04 - April 27, 2023
+---
+
This package provides MetaPost tools for drawing simple probability trees.
One main command, some variants and several parameters to control the output are provided.
+---
-License LPPL 1.3
+Author : Olivier Péault
+E-mail : o.peault at posteo.net
+
+Licence : Released under the LaTeX Project Public License v1.3c or later, see http://www.latex-project.org/lppl.txt
+
+
Modified: trunk/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.tex
===================================================================
--- trunk/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.tex 2023-04-26 23:49:55 UTC (rev 66951)
+++ trunk/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.tex 2023-04-27 20:36:32 UTC (rev 66952)
@@ -1,26 +1,26 @@
\documentclass[11pt,a4paper,english]{article}
+% Code with metapost output thanks to YannD at texnique.fr
+% https://texnique.fr/osqa/questions/11076/comment-obtenir-le-code-metapost-et-la-figure-dans-un-document-avec-luamplib
+
% To compile:
-% (pdf)latex mptrees-doc.tex
-% mpost mptrees-doc.mp
-% mpost mptrees-doc.mp
-% (pdf)latex mptrees-doc.tex
+% lualatex repere-doc.tex
- \usepackage{calc,ifthen}
-
- \usepackage[utf8]{inputenc}
- \usepackage[T1]{fontenc}
- \usepackage{lmodern}
- \usepackage{textcomp}
\usepackage{mathtools}
+\usepackage{unicode-math}
+\setmainfont{STIX Two Text}
+\setmathfont{STIX Two Math}
- \usepackage{geometry}
- \geometry{twoside,hmargin=2cm,vmargin={1.5cm,1.8cm},includefoot}
-
+\usepackage{geometry}
+\geometry{hmargin=2cm,vmargin={1.5cm,1.8cm},includefoot}
+
\usepackage[bottom]{footmisc}
\usepackage{mflogo}
+ \usepackage[output-decimal-marker={,}]{siunitx}
+ \usepackage{esvect}
+ \usepackage{nicefrac}
\usepackage{multicol}
\setlength{\multicolsep}{3pt}
@@ -29,176 +29,220 @@
\usepackage[toc]{multitoc}
\usepackage{enumitem}
- \setlist[description]{font=\ttfamily\bfseries\color{blue}}
+% \setlist[description]{font=\ttfamily\bfseries\color{blue}}
\usepackage[svgnames]{xcolor}
\usepackage{graphicx}
- \usepackage{ifpdf}
- \ifpdf
- \DeclareGraphicsRule{*}{mps}{*}{}
- \fi
\usepackage{url}
\usepackage{verbatim}
\usepackage{fancyvrb}
-% \usepackage{array}
-% \usepackage{tabularx}
-% \renewcommand{\tabularxcolumn}[1]{>{\arraybackslash}m{#1}}
-
- \usepackage{tcolorbox}
- \tcbset{colframe=black,boxsep=0pt,left=3pt,right=3pt,top=0pt,bottom=0pt,boxrule=0.4pt,colback=LightGoldenrod}
-
- \usepackage{listings}
- \lstset{columns=flexible,%
- language=MetaPost,%
- showstringspaces=false,%
- basicstyle=\ttfamily,
- literate={é}{{\'e}}1}
+ \usepackage{array}
+ \usepackage{colortbl}
+ \usepackage{tabularx}
+ \renewcommand{\tabularxcolumn}[1]{>{\arraybackslash}m{#1}}
+ \newcolumntype{M}[1]{>{\arraybackslash}m{#1}}
+ \usepackage{longtable}
+ \usepackage{tabularray}
+\usepackage{luamplib}
+\everymplib{verbatimtex \leavevmode etex;
+ input mptrees;
+ beginfig(1);}
+\everyendmplib{endfig;}
+\mplibnumbersystem{decimal}
+
+\usepackage{tcolorbox}
+\tcbuselibrary{listings,skins}%,documentation}
\usepackage{babel}
- \usepackage[colorlinks=true,urlcolor=blue]{hyperref}
+\usepackage{marginnote}
-%%%%%%%%%%%%%%%%%%% moreverb.sty
-\makeatletter
-\newwrite\verbatim at out
- \immediate\openout \verbatim at out \jobname.mp
-\newwrite\temp at code
-\def\verbatimwrite{%
- \@bsphack
- \immediate\openout \temp at code figtmp.mp
- \let\do\@makeother\dospecials
- \catcode`\^^M\active \catcode`\^^I=12
- \def\verbatim at processline{%
- \immediate\write\verbatim at out
- {\the\verbatim at line}%
- \immediate\write\temp at code
- {\the\verbatim at line}
- }%
- \immediate\write\temp at code{beginfig(\thenumfig)}
- \verbatim at start}
+\usepackage[colorlinks=true,urlcolor=blue]{hyperref}
+%\hypersetup{colorlinks=true,allcolors=red,linkcolor=red}
-\def\endverbatimwrite{%
- \immediate\closeout\temp at code
- \@esphack
- }%
-\makeatother
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\usepackage{listings}
-\newlength{\largeurcode}
-\newlength{\largeurfig}
-\newcounter{numfig}
-\setcounter{numfig}{-1}
+ \lstset{columns=flexible,%
+ basicstyle=\color{darkgray}\ttfamily,
+ literate={é}{{\'e}}1,
+ keywordstyle=\color{black}\bfseries}
-\newcommand{\codedeuxcol}{%
- \begin{tcolorbox}
- \begin{minipage}[c]{\largeurcode}
- \begin{multicols}{2}
- \lstinputlisting{figtmp.mp}
- \end{multicols}
- \end{minipage}
- \end{tcolorbox}
- \par\noindent
- }
-
-
-\newcommand{\codehoriz}{%
- \begin{minipage}[c]{\largeurcode}
- \lstinputlisting[frame=single,frameround=tttt,backgroundcolor=\color{LightGoldenrod}]{figtmp.mp}
- \end{minipage}
- \hfill
- }
+\lstdefinestyle{mpost}{language={MetaPost},
+ morekeywords={tree}
+ }
-\newcommand{\codevert}{%
- {\centering
- \begin{minipage}[c]{\largeurcode}
- \lstinputlisting[frame=single,frameround=tttt,backgroundcolor=\color{LightGoldenrod}]{figtmp.mp}
- \end{minipage}
- \par\noindent}
- }
-
\makeatletter
-\newenvironment{codefigure}[3]%
- {%
- \refstepcounter{numfig}
- \setlength{\largeurcode}{#2\linewidth}
- \ifnum#1=0
- \setlength{\largeurfig}{\linewidth-\largeurcode-2\fboxsep-2\fboxrule}
- \def\inscode{\codehoriz}
- \else
- \setlength{\largeurfig}{\linewidth}
- \def\inscode{\codevert}
- \ifnum#3=1
- \relax
- \else
- \def\inscode{\codedeuxcol}
- \fi
- \fi
- \immediate\write\verbatim at out{beginfig(\thenumfig)}
- \verbatimwrite
- }%
- {%
- \immediate\write\temp at code{endfig;}
- \immediate\write\verbatim at out{endfig;}
-
- \endverbatimwrite
- \par
- \noindent
- \inscode
- \IfFileExists{\jobname.\thenumfig}%
- {\begin{minipage}[c]{\largeurfig}
- \centering \includegraphics{\jobname.\thenumfig}\par
- \end{minipage}}{}
- \par}
+\tcbset{%
+ listing metapost/.code={%
+ \def\tcbuselistingtext at input{%
+ \begin{mplibcode}
+ input \jobname.listing;
+ \end{mplibcode}}%
+ }
+}
\makeatother
-\newenvironment{codecache}%
- {\verbatimwrite}{\endverbatimwrite}
-
-\newcounter{reptmp}
+\definecolor{CoulParam}{rgb}{0.4,0,0.5}
+\definecolor{TestC}{rgb}{0.963,0.971,0.994}
+\colorlet{FondCommandes}{black!60!yellow!10!white}
-\newcounter{repexemple}
-\setcounter{repexemple}{0}
+\tcbset{boites/.style={left=1em,right=1em,
+ colback=white,
+ boxrule=0pt,
+ colframe=white,
+ fonttitle=\bfseries\ttfamily,
+ colbacktitle=FondCommandes,
+ before title={\hspace{-1em}},
+ arc=0pt,
+ after=\medskip,
+ }}
-\newcommand{\debutexemple}{\par\vspace{2ex}
- \refstepcounter{repexemple}
- \noindent {\bfseries \color{blue!20!black}
- Example \arabic{repexemple}}
- \par\nopagebreak\vspace{1ex}
- }
+\DeclareTColorBox{rpobjet}{ v m }{
+ boites,
+ title={#1},
+ coltitle=blue,
+ colbacktitle=blue!5!white,
+ after title={\hfill #2},
+ }
+\DeclareTColorBox{mptparam}{ v m v}{
+ boites,
+ title={#1},
+ coltitle=CoulParam,
+ colbacktitle=CoulParam!5!white,
+ after title={\hfill #2, {\normalfont default :} #3},
+ }
-\newenvironment{exemple}[1][0.5]%
- {\debutexemple
- \codefigure{0}{#1}{1}
- }%
- {\endcodefigure
- \par\vspace{2ex}}
+\DeclareTColorBox{rpdeclaration}{ v }{
+ boites,
+ title={#1},
+ coltitle=black,
+ colbacktitle=black!5!white,
+ }
-\newenvironment{exemplev}[2][1]%
- {\debutexemple
- \codefigure{1}{#1}{#2}
- }%
- {\endcodefigure
- \par\vspace{2ex}}
-
-
-\newenvironment{figreperedoc}%
- {\refstepcounter{numfig}
- \verbatimwrite}%
- {%
- \endverbatimwrite%
- \IfFileExists{\jobname.\thenumfig}%
- {\includegraphics{\jobname.\thenumfig}}{}
- }
+\DeclareTColorBox{rplabel}{ v }{
+ boites,
+ title={#1},
+ coltitle=red,
+ colbacktitle=red!50!black!5!white,
+ }
+\DefTblrTemplate{contfoot-text}{default}{}
+\DefTblrTemplate{conthead-text}{default}{}
+\DefTblrTemplate{caption-tag}{default}{}
+\DefTblrTemplate{caption-sep}{default}{}
+\DefTblrTemplate{caption-text}{default}{}
+\NewDocumentEnvironment{rpparam}{ +b}
+ {\par\medskip\begin{center}
+ \begin{longtblr}[label=none,caption={}]{
+ rowhead=2,
+ verb,
+ hlines={2pt,white},
+ columns={c},
+ row{1}=white,
+ row{2-Z}={bg=CoulParam!5!white,m},
+ column{4}={wd=8cm,fg=black,j},
+ cell{3-Z}{1-3}={cmd=\testparam},
+ cell{3-Z}{1}={cmd=\bfseries\testparam}
+ }
+ \SetCell[c=4]{c} Paramètres \\
+ Nom & Type & Défaut & \\
+ #1
+ \end{longtblr}
+ \end{center}\bigskip}
+ {}
+
+\tcbset{mot/.style={colback=FondCommandes,
+ verbatim,
+ arc=0pt,
+ outer arc=0pt,
+ top=0pt,bottom=0pt,left=0mm,right=0mm,
+ boxrule=0pt}}
+
+\DeclareTotalTCBox{\rpdec}{v}{mot,coltext=black}{#1}
+\DeclareTotalTCBox{\rpfig}{v}{mot,coltext=blue}{#1}
+\DeclareTotalTCBox{\rplab}{v}{mot,coltext=red}{#1}
+\DeclareTotalTCBox{\rppar}{v}{mot,coltext=CoulParam}{#1}
+
+\NewDocumentCommand{\testparam}{v}{\textcolor{CoulParam}{\texttt{#1}}}
+\NewDocumentCommand{\desstab}{v}{\textbf{\texttt{#1}}}
+
+\NewDocumentCommand{\decfig}{m}{\raisebox{-.45\height}{#1}}
+
+
+
+\DeclareTCBListing[auto counter]{exemple}{ !O{} }{
+ enhanced,
+ title=Exemple \thetcbcounter,
+ coltitle=black,
+ fonttitle=\bfseries,
+ attach boxed title to top left,
+ boxed title style={left=0pt,
+ boxrule=0pt,
+ colframe=white,
+ colback=white,
+ coltext=black},
+ colback=red!25!yellow!10!white,
+ left=1mm,top=0mm,bottom=0mm,
+ halign lower=center,
+ listing metapost,
+ listing outside text,
+% listing only,
+ sidebyside gap=1mm,
+ after skip=2em,
+ before upper={\texttt{beginfig(\thetcbcounter);}\par\vspace{-0.5\baselineskip}},
+ after upper={\par\vspace{-0.5\baselineskip}\texttt{endfig;}},
+ listing options={style=mpost
+ },
+ #1}
+
+
+\DeclareTCBListing{codelatex}{ !O{} }{
+ enhanced,
+ notitle,
+ colback=LightSteelBlue,
+ left=2mm,top=0mm,bottom=0mm,
+ listing only,
+ listing options={language={[LaTeX]TeX}
+ },
+ #1}
+
+\DeclareTCBListing{codempost}{ !O{} }{
+ enhanced,
+ notitle,
+ colback=red!25!yellow!10!white,
+ left=2mm,top=0mm,bottom=0mm,
+ after skip=1em,
+ listing only,
+ listing options={style=mpost
+ },
+ #1}
+
+
+\newcommand{\btet}{%
+\begin{tcolorbox}[fontupper=\ttfamily,
+nobeforeafter,
+%tcbox raise base,
+arc=0pt,
+outer arc=0pt,
+width=1.5cm,
+top=0pt,bottom=0pt,left=0mm,right=0mm,
+leftrule=0pt,rightrule=0pt,toprule=0.3mm,bottomrule=0.3mm,
+boxsep=0.5mm,
+colback=red!10!white,colframe=red!50!black]
+\scriptsize begintree;\par endtree;
+\end{tcolorbox}%
+}
+
+
\begin{document}
\title{Documentation of \texttt{mptrees.mp}}
\date{\today}
@@ -215,34 +259,29 @@
\newcommand{\ijc}{[i][j]}
-\begin{codecache}
-input mptrees;
-%input latexmp;
-setupLaTeXMP(inputencoding="utf8",
- packages="fourier,amsmath,nicefrac,babel[english]");
-dirtree:=0;
-\end{codecache}
+\reversemarginpar
+
\section{Overview}
This package is intended to simplify the drawing of probability trees with \MP. It provides one main command and several parameters to control the output.
-It can be used in standalone files with two compilations (\verb|latexmp| package is loaded) but it can also be used with Lua\LaTeX{} and \verb|luamplib| package.
+It can be used in standalone files with two compilations (\verb|latexmp| package is loaded) but also with Lua\LaTeX{} and \verb|luamplib| package.
+%Some of the following constructions need to be enclosed between \verb|begintree| and \verb|endtree|.
-\begin{description}
-\item[tree\ijc (dim1,dim2,...)(ev1,prob1,ev2,prob2,...)] probability tree located in column \verb|i| and row \verb|j| (see figure below). \verb|dim1|, \verb|dim2|,... can be numerics or pairs and control the dimension of the tree. \verb|ev1|, \verb|prob1|... can be strings or pictures and will be printed (using \verb|latexmp| if strings) at the end of the edge (the event) and above the edge (the probability).
+\begin{rpobjet}{tree[<i>][<j>](<dim1>,<dim2>,...)(<ev1>,<prob1>,<ev2>,<prob2>,...)}{picture}
+Probability tree located in column \verb|i| and row \verb|j| (see figure below). \verb|dim1|, \verb|dim2|,... can be numerics or pairs and control the dimension of the tree. \verb|ev1|, \verb|prob1|... can be strings or pictures and will be printed (using \verb|latexmp| if strings) at the end of the edge (the event) and above the edge (the probability).
-%\item[shiftev, scaleprob, posprob, typeprob, proboffset, dirtree] numerics controlling the scale and position of the probability label, the direction of the tree...
-\end{description}
+\end{rpobjet}
+
\begin{center}
-\begin{figreperedoc}
-beginfig(0)
+\begin{mplibcode}
draw tree[1][1](3cm,2cm)("$A$","$p$","$\overline{A}$","$q$");
draw tree[2][1](3cm,1cm)("$B$","$\nicefrac{1}{4}$","$\overline{B}$","$\nicefrac{3}{4}$");
draw tree[2][2](3cm,1cm)("$B$","$0.5$","$\overline{B}$","$0.5$");
@@ -250,110 +289,119 @@
draw tree[4][2](3cm,1cm)("$D$","$a$","$\overline{D}$","$b$");
drawoptions(dashed evenly);
draw (Orig_arbre[2][1]+(0,0.5cm))--(Orig_arbre[2][2]-(0,0.5cm))--(Orig_arbre[2][2]-(3.5cm,0.5cm))--(Orig_arbre[2][1]+(-3.5cm,0.5cm))--cycle withcolor red;
-label.bot(textext("\verb|tree[1][1]|"),0.5[Orig_arbre[2][2]-(0,0.5cm),Orig_arbre[2][2]-(3.5cm,0.5cm)]) withcolor red;
+label.bot(textext("\texttt{tree[1][1]}"),0.5[Orig_arbre[2][2]-(0,0.5cm),Orig_arbre[2][2]-(3.5cm,0.5cm)]) withcolor red;
draw (Orig_arbre[3][1]+(0,0.5cm))--(Orig_arbre[3][2]-(0,0.5cm))--(Orig_arbre[2][1]-(0,1cm))--(Orig_arbre[2][1]+(0,1cm))--cycle withcolor 0.5green;
-label.top(textext("\verb|tree[2][1]|"),0.5[Orig_arbre[3][1]+(0,0.5cm),Orig_arbre[2][1]+(0,1cm)]) withcolor 0.5green;
+label.top(textext("\texttt{tree[2][1]}"),0.5[Orig_arbre[3][1]+(0,0.5cm),Orig_arbre[2][1]+(0,1cm)]) withcolor 0.5green;
draw (Orig_arbre[3][3]+(0,0.5cm))--(Orig_arbre[3][4]-(0,0.5cm))--(Orig_arbre[2][2]-(0,1cm))--(Orig_arbre[2][2]+(0,1cm))--cycle withcolor 0.5green;
-label.bot(textext("\verb|tree[2][2]|"),0.5[Orig_arbre[3][4]-(0,0.5cm),Orig_arbre[2][2]-(0,1cm)]) withcolor 0.5green;
+label.bot(textext("\texttt{tree[2][2]}"),0.5[Orig_arbre[3][4]-(0,0.5cm),Orig_arbre[2][2]-(0,1cm)]) withcolor 0.5green;
draw (Orig_arbre[4][1]+(0,0.5cm))--(Orig_arbre[4][2]-(0,0.5cm))--(Orig_arbre[3][2]-(0,1cm))--(Orig_arbre[3][2]+(0,1cm))--cycle withcolor blue;
-label.bot(textext("\verb|tree[3][2]|"),0.5[Orig_arbre[4][2]-(0,0.5cm),Orig_arbre[3][2]-(0,1cm)]) withcolor blue;
+label.bot(textext("\texttt{tree[3][2]}"),0.5[Orig_arbre[4][2]-(0,0.5cm),Orig_arbre[3][2]-(0,1cm)]) withcolor blue;
draw (Orig_arbre[5][1]+(0,0.5cm))--(Orig_arbre[5][2]-(0,0.5cm))--(Orig_arbre[4][2]-(0,1cm))--(Orig_arbre[4][2]+(0,1cm))--cycle withcolor red;
-label.bot(textext("\verb|tree[4][2]|"),0.5[Orig_arbre[5][2]-(0,0.5cm),Orig_arbre[4][2]-(0,1cm)]) withcolor red;
-endfig;
+label.bot(textext("\texttt{tree[4][2]}"),0.5[Orig_arbre[5][2]-(0,0.5cm),Orig_arbre[4][2]-(0,1cm)]) withcolor red;
+\end{mplibcode}
-\end{figreperedoc}
-
\end{center}
+\marginnote[\btet]{}Note that you can use these commands inside any \verb|beginfig();...endfig;| but sometimes, for some constructions, they need to be enclosed between \verb|begintree| and \verb|endtree| commands. Such commands are indicated with a margin note.
+
\section{Trees}
\subsection{Different kinds of trees}
-\begin{description}
-\item[tree\ijc (width,vspace)(ev1,prob1,ev2,prob2,...)] regular tree where \verb|width| is the horizontal width of the tree and \verb|vspace| the vertical space between two consecutive nodes.
+\begin{rpobjet}{tree[<i>][<j>](<width>,<vspace>)(<ev1>,<prob1>,<ev2>,<prob2>,...)}{picture}
+Regular tree where \verb|width| is the horizontal width of the tree and \verb|vspace| the vertical space between two consecutive nodes.
+\end{rpobjet}
-\begin{codecache}
-string dim[];
-dim[4]:="4 cm";dim[3]:="3 cm";dim[2]:="2 cm";dim[1]:="1 cm";
-dim[15]:="1.5 cm";dim[25]:="2.5 cm";dim[11]:="-1 cm";
-dim[22]:="-2 cm";dim[7]:="7cm";
-\end{codecache}
-\begin{codecache}
-extra_endfig:="drawoptions(withcolor red);";
-extra_endfig:=extra_endfig & "drawdblarrow ((0,0)--(4cm,0)) shifted (0,2.25cm);label.top(textext(dim[4]),(2cm,2.25cm));";
-extra_endfig:=extra_endfig & "drawdblarrow ((0,0)--(0,2.5cm)) shifted (Orig_arbre[2][2]-(5cm,0));label.lft(textext(dim[25]),(-1cm,0));";
-extra_endfig:=extra_endfig & "drawoptions(withcolor 0.5green);";
-extra_endfig:=extra_endfig & "drawdblarrow ((0,0)--(3cm,0)) shifted (Orig_arbre[2][1]+(0,1cm));label.top(textext(dim[3]),(6cm,2.25cm));";
-extra_endfig:=extra_endfig & "drawdblarrow ((0,0)--(0,1.5cm)) shifted (Orig_arbre[3][2]+(0.25cm,0));label.rt(textext(dim[15]),Orig_arbre[3][2]+(0.25cm,0.75cm));";
-extra_endfig:=extra_endfig & "drawdblarrow ((0,0)--(0,1cm)) shifted (Orig_arbre[3][4]+(0.25cm,0));label.rt(textext(dim[1]),Orig_arbre[3][4]+(0.25cm,0.5cm));";
-extra_endfig:=extra_endfig & "drawdblarrow ((0,0)--(0,1cm)) shifted (Orig_arbre[3][5]+(0.25cm,0));label.rt(textext(dim[1]),Orig_arbre[3][5]+(0.25cm,0.5cm));";
-\end{codecache}
-
-{\small \begin{exemplev}{1}
+
+\mplibcodeinherit{enable}
+
+\begin{mplibcode}
+string dim[];dim[4]:="4 cm";dim[3]:="3 cm";dim[2]:="2 cm";dim[1]:="1 cm";dim[15]:="1.5 cm";dim[25]:="2.5 cm";dim[11]:="-1 cm";dim[22]:="-2 cm";dim[7]:="7cm";
+\end{mplibcode}
+
+\everyendmplib{drawoptions(withcolor red);drawdblarrow ((0,0)--(4cm,0)) shifted (0,2.25cm);label.top(textext(dim[4]),(2cm,2.25cm));drawdblarrow ((0,0)--(0,2.5cm)) shifted (Orig_arbre[2][2]-(5cm,0));label.lft(textext(dim[25]),(-1cm,0));drawoptions(withcolor 0.5green);drawdblarrow ((0,0)--(3cm,0)) shifted (Orig_arbre[2][1]+(0,1cm));label.top(textext(dim[3]),(6cm,2.25cm));drawdblarrow ((0,0)--(0,1.5cm)) shifted (Orig_arbre[3][2]+(0.25cm,0));label.rt(textext(dim[15]),Orig_arbre[3][2]+(0.25cm,0.75cm));drawdblarrow ((0,0)--(0,1cm)) shifted (Orig_arbre[3][4]+(0.25cm,0));label.rt(textext(dim[1]),Orig_arbre[3][4]+(0.25cm,0.5cm));drawdblarrow ((0,0)--(0,1cm)) shifted (Orig_arbre[3][5]+(0.25cm,0));label.rt(textext(dim[1]),Orig_arbre[3][5]+(0.25cm,0.5cm));endfig;}
+
+\begin{exemple}[listing above text]
draw tree[1][1](4cm,2.5cm)("$A_1$","$\nicefrac{1}{3}$","$A_2$","$\nicefrac{2}{3}$");
draw tree[2][1](3cm,1.5cm)("$B$","$\nicefrac{1}{4}$","$C$","$\nicefrac{3}{4}$");
draw tree[2][2](3cm,1cm)("$D$","$p$","$E$","$q$","$F$","$r$");
-\end{exemplev}
-}
+\end{exemple}
-\item[tree\ijc (width,vspace1,vspace2...)(ev1,prob1,ev2,prob2,...)] tree where \verb|width| is the horizontal width of the tree while each \verb|vspace| indicates the vertical space between the node and the origin of the tree.
+\begin{rpobjet}{tree[<i>][<j>](<width>,<vsp1>,<vsp2>,...)(<ev1>,<p1>,<ev2>,<p2>,...)}{picture}
+Tree where \verb|width| is the horizontal width of the tree while each \verb|vsp| indicates the vertical space between the node and the origin of the tree.
-\begin{codecache}
-extra_endfig:="drawoptions(withcolor 0.5green);";
-extra_endfig:=extra_endfig & "draw Orig_arbre[2][1] -- (Orig_arbre[2][1]+(4.5cm,0)) dashed evenly;";
-extra_endfig:=extra_endfig & "drawdblarrow ((0,0)--(3cm,0)) shifted (Orig_arbre[2][1]+(0,2.25cm));label.top(textext(dim[3]),(5cm,3.25cm));";
-extra_endfig:=extra_endfig & "drawarrow ((0,-2cm)--(0,0)) shifted (Orig_arbre[3][1]+(0.25cm,0));label.rt(textext(dim[2]),Orig_arbre[3][1]+(0.25cm,-0.7cm));";
-extra_endfig:=extra_endfig & "drawarrow ((0,-1cm)--(0,0)) shifted (Orig_arbre[3][2]+(0.5cm,0));label.rt(textext(dim[1]),Orig_arbre[3][2]+(0.5cm,-0.5cm));";
-extra_endfig:=extra_endfig & "drawarrow ((0,1cm)--(0,0)) shifted (Orig_arbre[3][3]+(0.75cm,0));label.rt(textext(dim[11]),Orig_arbre[3][3]+(0.75cm,0.5cm));";
-extra_endfig:=extra_endfig & "drawarrow ((0,0)--(0,-2cm)) shifted (Orig_arbre[3][4]+(0.25cm,0));label.rt(textext(dim[22]),Orig_arbre[3][4]+(0.25cm,-1cm));";
-\end{codecache}
-\begin{exemplev}{1}
+\end{rpobjet}
+
+\everyendmplib{
+drawoptions(withcolor 0.5green);
+draw Orig_arbre[2][1] -- (Orig_arbre[2][1]+(4.5cm,0)) dashed evenly;
+drawdblarrow ((0,0)--(3cm,0)) shifted (Orig_arbre[2][1]+(0,2.25cm));label.top(textext(dim[3]),(5cm,3.25cm));
+drawarrow ((0,-2cm)--(0,0)) shifted (Orig_arbre[3][1]+(0.25cm,0));label.rt(textext(dim[2]),Orig_arbre[3][1]+(0.25cm,-0.7cm));
+drawarrow ((0,-1cm)--(0,0)) shifted (Orig_arbre[3][2]+(0.5cm,0));label.rt(textext(dim[1]),Orig_arbre[3][2]+(0.5cm,-0.5cm));
+drawarrow ((0,1cm)--(0,0)) shifted (Orig_arbre[3][3]+(0.75cm,0));label.rt(textext(dim[11]),Orig_arbre[3][3]+(0.75cm,0.5cm));
+drawarrow ((0,0)--(0,-2cm)) shifted (Orig_arbre[3][4]+(0.25cm,0));label.rt(textext(dim[22]),Orig_arbre[3][4]+(0.25cm,-1cm));
+endfig;}
+
+\begin{exemple}[listing above text]
draw tree[1][1](3cm,2cm)("$A$","$p$","$\overline{A}$","$q$");
draw tree[2][1](3cm,2cm,1cm,-1cm)("$B$","$p$","$C$","$q$","$D$","$r$");
draw tree[2][2](3cm,0cm,-2cm)("$E$","$0.5$","$F$","$0.5$");
-\end{exemplev}
+\end{exemple}
-\begin{codecache}
-extra_endfig:="";
-\end{codecache}
-\item[tree\ijc (pair1,pair2,...)(ev1,prob1,ev2,prob2,...)] tree where \verb|pair1|, \verb|pair2|... indicate the coordinates of each node from the origin of the tree.
+\begin{rpobjet}{tree[<i>][<j>](<pair1>,<pair2>,...)(<ev1>,<prob1>,<ev2>,<prob2>,...)}{picture}
+Tree where \verb|pair1|, \verb|pair2|... indicate the coordinates of each node from the origin of the tree.
+\end{rpobjet}
+\everyendmplib{
+drawoptions(withcolor 0.5green);
+draw Orig_arbre[2][1] -- (Orig_arbre[2][1]+(5cm,0)) dashed evenly;
+drawarrow ((0,0)--(3cm,0)) shifted (Orig_arbre[2][1]+(0,2.25cm));label.top(textext(dim[3]),(5cm,3.25cm));
+drawarrow ((0,-2cm)--(0,0)) shifted (Orig_arbre[3][1]+(0.25cm,0));label.rt(textext(dim[2]),Orig_arbre[3][1]+(0.25cm,-0.7cm));
+drawarrow ((0,0)--(4cm,0)) shifted (Orig_arbre[2][1]+(0,-1.25cm));label.bot(textext(dim[4]),(5.5cm,-0.25cm));
+drawarrow ((0,0)--(0,-1cm)) shifted (Orig_arbre[3][2]+(0,1cm));label.rt(textext(dim[11]),Orig_arbre[3][2]+(0,0.5cm));
+endfig;}
-\begin{codecache}
-extra_endfig:="drawoptions(withcolor 0.5green);";
-extra_endfig:=extra_endfig & "draw Orig_arbre[2][1] -- (Orig_arbre[2][1]+(5cm,0)) dashed evenly;";
-extra_endfig:=extra_endfig & "drawarrow ((0,0)--(3cm,0)) shifted (Orig_arbre[2][1]+(0,2.25cm));label.top(textext(dim[3]),(5cm,3.25cm));";
-extra_endfig:=extra_endfig & "drawarrow ((0,-2cm)--(0,0)) shifted (Orig_arbre[3][1]+(0.25cm,0));label.rt(textext(dim[2]),Orig_arbre[3][1]+(0.25cm,-0.7cm));";
-extra_endfig:=extra_endfig & "drawarrow ((0,0)--(4cm,0)) shifted (Orig_arbre[2][1]+(0,-1.25cm));label.bot(textext(dim[4]),(5.5cm,-0.25cm));";
-extra_endfig:=extra_endfig & "drawarrow ((0,0)--(0,-1cm)) shifted (Orig_arbre[3][2]+(0,1cm));label.rt(textext(dim[11]),Orig_arbre[3][2]+(0,0.5cm));";
-\end{codecache}
-
-\begin{exemplev}{1}
+\begin{exemple}[listing above text]
draw tree[1][1](3cm,2cm)("$A$","$p$","$\overline{A}$","$1-p$");
draw tree[2][1]((3cm,2cm),(4cm,-1cm))("$B$","$q$","$C$","$r$");
-\end{exemplev}
+\end{exemple}
-\begin{codecache}
-extra_endfig:="";
-\end{codecache}
-\end{description}
+\everyendmplib{endfig;}
+
+\subsection{Simple trees}
+\begin{rpobjet}{stree[<i>][<j>](...)(<ev1>,<ev2>)}{picture}
+Same as previous except that there are no probabilities.
+\end{rpobjet}
+
+
+\begin{exemple}[listing above text]
+draw stree[1][1](100,50)("$A$","$B$","$C$");
+draw stree[2][1](80,25)("$A$","$B$");
+draw stree[2][2](80,25)("$A$","$B$");
+draw stree[2][3](80,25)("$A$","$B$");
+\end{exemple}
+
\subsection{Start and end labels}
-\begin{description}
-\item[startlabel(s)] Print \verb|s| (can be a string or a picture) at the origin of the tree.
+\begin{rpobjet}{startlabel(<s>)}{picture}
+Prints \verb|s| (can be a string or a picture) at the origin of the tree.
+\end{rpobjet}
-\begin{exemple}[0.65]
+
+\begin{exemple}[lefthand ratio = 0.65]
draw startlabel("$S$");
draw tree[1][1](3cm,2cm)("$A$","$p$","$B$","$q$");
\end{exemple}
-\item[endlabel\ijc(s)] Print \verb|s| at the end of a branch. The space between the previous label ans \verb|s| is controlled by the numeric \verb|endlabelspace| which defaults to \verb|1cm|.
+\begin{rpobjet}{endlabel[<i>][<j>](<s>)}{picture}
+Prints \verb|s| at the end of a branch. The space between the previous label ans \verb|s| is controlled by the numeric \verb|endlabelspace| which defaults to \verb|1cm|.
+\end{rpobjet}
-\begin{exemplev}{1}
+\begin{exemple}[listing above text]
draw startlabel("$S$");
draw tree[1][1](3cm,2cm)("$A$","$p$","$B$","$q$");
draw tree[2][2](2cm,1cm)("$A$","$p$","$B$","$q$");
@@ -360,58 +408,63 @@
draw endlabel[2][1]("$SA$");
draw endlabel[3][1]("$SBA$");
draw endlabel[3][2]("$SBB$");
-\end{exemplev}
+\end{exemple}
-\end{description}
-
\section{Direction}
-\begin{description}
-\item[dirtree] All trees are construct horizontally by default. \verb|ditree| indicates the angle in degrees between the horizontal and the main direction of the tree. Default is $0$.
+\begin{mptparam}{dirtree}{numeric}{0}
+All trees are construct horizontally by default. \verb|ditree| indicates the angle in degrees between the horizontal and the main direction of the tree.
+\end{mptparam}
-
-\begin{exemplev}{1}
+\begin{exemple}[listing above text]
dirtree:=135;
draw tree[1][1](3cm,2cm)("$A_1$","$a_1$","$A_2$","$a_2$");
draw tree[2][1](3cm,1cm)("$B$","$b$","$C$","$c$");
draw tree[2][2](3cm,1cm)("$D$","$p$","$E$","$q$");
-\end{exemplev}
+\end{exemple}
-\begin{exemplev}{1}
+\begin{exemple}[listing above text]
dirtree:=-60;
draw tree[1][1](3cm,2cm)("$A_1$","$a_1$","$A_2$","$a_2$");
draw tree[2][1](3cm,1cm)("$B$","$b$","$C$","$c$");
draw tree[2][2](3cm,1cm)("$D$","$p$","$E$","$q$");
-\end{exemplev}
+\end{exemple}
-\begin{codecache}
-dirtree:=0;dirlabel:=0;
-\end{codecache}
-\item[dirlabel] With dirtree, the whole tree is rotated. With \verb|dirlabel|, only the position of the labels is changed so the given coordinates are the real ones. May be useful for vertical trees.
+\begin{mptparam}{dirlabel}{numeric}{0}
+All the trees are viewed as ``horizontal" trees, so the space between two subtrees is horizontal too. With \verb|dirtree|, the whole (horizontal) tree is rotated. But if the tree is designed vertically, spacing is wrong. In this case, one can use \verb|dirlabel| to indicate the orientation of the tree.
+\end{mptparam}
-\begin{exemplev}{1}
-dirlabel:=90;
-draw tree[1][1]((-1cm,2cm),(1cm,2cm))("$A$","$p$","$B$","$q$");
-draw tree[2][1]((-0.5cm,2cm),(0.5cm,2cm))("$C$","$c$","$D$","$d$");
-draw tree[2][2]((-0.5cm,2cm),(0.5cm,2cm))("$E$","$e$","$F$","$f$");
-\end{exemplev}
-\begin{codecache}
-dirlabel:=0;
-\end{codecache}
+\begin{exemple}[lefthand ratio=0.65]
+draw tree[1][1]((-1cm,2cm),(1cm,2cm))
+ ("$A$","$p$","$B$","$q$");
+draw tree[2][1]((-0.5cm,2cm),(0.5cm,2cm))
+ ("$C$","$c$","$D$","$d$");
+draw tree[2][2]((-0.5cm,2cm),(0.5cm,2cm))
+ ("$E$","$e$","$F$","$f$");
+\end{exemple}
-\end{description}
+\begin{exemple}[lefthand ratio=0.65]
+dirlabel:=90;
+draw tree[1][1]((-1cm,2cm),(1cm,2cm))
+ ("$A$","$p$","$B$","$q$");
+draw tree[2][1]((-0.5cm,2cm),(0.5cm,2cm))
+ ("$C$","$c$","$D$","$d$");
+draw tree[2][2]((-0.5cm,2cm),(0.5cm,2cm))
+ ("$E$","$e$","$F$","$f$");
+\end{exemple}
\section{Dealing with alignment}
-\begin{description}
-\item[shiftev] The origin of each tree is located where the bounding box of the previous event's name ends. Thus subtrees may begin at different places. The numeric \verb|shiftev| indicates the horizontal space between the end of the edges and the beginning of following trees.
+\begin{mptparam}{shiftev}{numeric}{-1}
+The origin of each tree is located at the right side of the bounding box of the previous event name. Thus different subtrees may begin at different places. The numeric \verb|shiftev|, if positive, indicates the fixed horizontal space between the end of the edges and the beginning of following subtrees.
+
It can be used inside the first set of parameters of the tree (see example below) or as a global variable.
+\end{mptparam}
-
-\begin{exemplev}{1}
+\begin{exemple}[listing above text]
draw tree[1][1](80,120)("$A$","$0.5$","$\overline{A}$","$0.5$");
draw tree[2][1](70,40)("Yes","$p$","No","$q$","Maybe","$r$");
draw tree[2][2](70,40,"shiftev:=1.5cm")("Yes","$p$","No","$q$","Maybe","$r$");
@@ -421,325 +474,500 @@
draw tree[3][4](50,20)("$B$","$b$","$C$","$c$");
draw tree[3][5](50,20)("$B$","$b$","$C$","$c$");
draw tree[3][6](50,20)("$B$","$b$","$C$","$c$");
-\end{exemplev}
+\end{exemple}
+\begin{mptparam}{abscoord}{boolean}{false}
+With the boolean \verb|abscoord| set to \verb|true|, all the coordinates are given from the origin of the \emph{first} tree instead of the origin of the subtree, which makes easier the alignment of all the subtrees.
+\end{mptparam}
-\item[abscoord] With the boolean \verb|abscoord| set to \verb|true|, all the coordinates are given from the origin of the \emph{first} tree instead of the origin of the subtree, which makes easier the alignment of all the subtrees.
-\end{description}
+\everyendmplib{drawoptions(withcolor red);
+drawdblarrow ((0,0)--(7cm,0)) shifted (0,2cm);label.top(textext(dim[7]),(3.5cm,2cm));
+drawdblarrow ((0,0)--(0,1.5cm)) shifted (-0.5cm,0);label.lft(textext("1.5 cm"),(-0.5cm,0.75cm));
+endfig;}
-\begin{codecache}
-extra_endfig:="drawoptions(withcolor red);";
-extra_endfig:=extra_endfig & "drawdblarrow ((0,0)--(7cm,0)) shifted (0,2.25cm);label.top(textext(dim[7]),(3.5cm,2.25cm));";
-extra_endfig:=extra_endfig & "drawdblarrow ((0,0)--(0,2cm)) shifted (-0.5cm,0);label.lft(textext(dim[2]),(-0.5cm,1cm));";
-\end{codecache}
-
-\begin{exemplev}{1}
+\begin{exemple}[listing above text]
abscoord:=true;
draw tree[1][1](3cm,2cm)("$A$","$p$","Blabla","$q$");
-draw tree[2][1]((7cm,2cm),(7cm,0.5cm))("$A$","$p$","$B$","$q$");
-draw tree[2][2]((7cm,-0.5cm),(7cm,-2cm))("$A$","$p$","$B$","$q$");
-\end{exemplev}
+draw tree[2][1]((7cm,1.5cm),(7cm,0.5cm))("$A$","$p$","$B$","$q$");
+draw tree[2][2]((7cm,-0.5cm),(7cm,-1.5cm))("$A$","$p$","$B$","$q$");
+\end{exemple}
-\begin{codecache}
-extra_endfig:="";
-abscoord:=false;
-\end{codecache}
+\everyendmplib{endfig;}
-
\section{Parameters}
+All following parameters can be changed globally before drawing the tree or changed locally inside the first set of parameters:
+
+\begin{codempost}[width=0.7\linewidth,left skip=1cm]
+scaleev:=2;
+draw tree[1][1](3cm,2cm)(...);
+draw tree[2][1](3cm,2cm)(...);
+\end{codempost}
+
+or
+
+\begin{codempost}[width=0.7\linewidth,left skip=1cm]
+draw tree[1][1](3cm,2cm,"scaleev:=2")(...);
+draw tree[2][1](3cm,2cm)(...);
+\end{codempost}
+
+In the fisrt case, \verb|scaleev| is changed globally while in the second case, the change only applies to the first tree.
+
+
\subsection{Event}
-\begin{description}
-\item[scaleev] numeric controlling the scale of the label at the end of the edge (the event). Default is $1$.
-\begin{exemple}[0.65]
+\begin{mptparam}{scaleev}{numeric}{1}
+Numeric controlling the scale of the label at the end of the edge (the event).
+\end{mptparam}
+
+
+\begin{exemple}[lefthand ratio=0.65]
scaleev:=2;
- draw tree[1][1](3cm,2cm)("$A$","$p$","$B$","$q$");
+ draw stree[1][1](3cm,2cm)("$A$","$B$");
\end{exemple}
-\begin{codecache}
-scaleev:=1;
-\end{codecache}
+\begin{mptparam}{nodeformat}{string}{""}
+String that indicates how the events are printed (the shape of path around the event). Possible values are (for now) \verb|"bbox"|, \verb|"circle"|, \verb|"superellipse"|.
+\end{mptparam}
+\begin{exemple}[lefthand ratio=0.65]
+ nodeformat:="bbox";
+ draw stree[1][1](3cm,2cm)("$A$","$B$");
+\end{exemple}
-\end{description}
+\begin{mptparam}{nodelinecolor}{color}{black}
+Color of the path around the node
+\end{mptparam}
+\begin{mptparam}{nodebgcolor}{color}{white}
+Color of the background of the region delimited by the previous path.
+\end{mptparam}
+
+\begin{mptparam}{nodefgcolor}{color}{black}
+Color of the text.
+\end{mptparam}
+
+
+
+\begin{exemple}[lefthand ratio=0.65]
+nodeformat:="superellipse";
+nodelinecolor:=(0.8,0,0);
+nodebgcolor:=(1,0.5,0.5);
+nodefgcolor:=white;
+draw stree[1][1](3cm,2cm)("$A$","$B$");
+\end{exemple}
+
+
+\begin{exemple}[lefthand ratio=0.65]
+nodefgcolor:=(0.7,0.4,0.7);
+draw stree[1][1](3cm,2cm)("$A$","$B$");
+\end{exemple}
+
+
+
+\subsection{Leaves}
+\marginnote[\btet]{}
+You may want to format the leaves in a different way from the nodes. A tree using the following parameters must be enclosed in a \verb|begintree;|...\verb|endtree;| ``environment".
+
+\begin{mptparam}{leaveformat}{string}{""}
+String that indicates how the events are printed (the shape of path around the event). Possible values are (for now) \verb|"bbox"|, \verb|"circle"|, \verb|"superellipse"| and \verb|"none"|.
+\end{mptparam}
+
+\begin{exemple}[listing above text]
+begintree;
+leaveformat:="bbox";
+draw stree[1][1](100,45)("$A$","$B$");
+draw stree[2][1](80,30)("$C$","$D$");
+draw stree[3][2](65,20)("$E$","$F$");
+endtree;
+\end{exemple}
+
+\begin{mptparam}{leavelinecolor}{color}{black}
+Color of the path around the leave
+\end{mptparam}
+
+\begin{mptparam}{leavebgcolor}{color}{white}
+Color of the background of the region delimited by the previous path.
+\end{mptparam}
+
+\begin{mptparam}{leavefgcolor}{color}{black}
+Color of the text.
+\end{mptparam}
+
+\begin{exemple}[listing above text]
+begintree;
+nodeformat:="circle";
+nodelinecolor:=(0.8,0,0); nodebgcolor:=(1,0.5,0.5); nodefgcolor:=white;
+leaveformat:="bbox";
+leavebgcolor:=(0.3,1,1); leavefgcolor:=red;
+draw stree[1][1](100,45)("$A$","$B$");
+draw stree[2][1](80,30)("$C$","$D$");
+draw stree[3][2](65,20)("$E$","$F$");
+endtree;
+\end{exemple}
+
+Note that \verb|nodeformat| applies to both nodes and leaves. To avoid formatting the leaves, use the value \verb|"none"| for \verb|leaveformat|.
+
+\begin{exemple}[listing above text]
+begintree;
+nodeformat:="circle";
+nodelinecolor:=(0.8,0,0); nodebgcolor:=(1,0.5,0.5); nodefgcolor:=white;
+leaveformat:="none";
+draw stree[1][1](100,45)("$A$","$B$");
+draw stree[2][1](80,30)("$C$","$D$");
+draw stree[3][2](65,20)("$E$","$F$");
+endtree;
+\end{exemple}
+
\subsection{Probability}
-\begin{description}
+\begin{mptparam}{probformat}{string}{""}
+String that indicates how the probabilities are printed (the shape of path around the probability). Possible values are (for now) \verb|"bbox"|, \verb|"circle"|, \verb|"superellipse"|.
+\end{mptparam}
-\item[scaleprob] numeric controlling the scale of the label above the edge (the probability). Default is $0.85$.
-
-\begin{exemple}[0.65]
- scaleprob:=1.5;
+\begin{exemple}[lefthand ratio=0.65]
+ probformat:="bbox";
draw tree[1][1](3cm,2cm)("$A$","$p$","$B$","$q$");
\end{exemple}
-\begin{codecache}
-scaleprob:=0.85;
-\end{codecache}
+\begin{mptparam}{problinecolor}{color}{black}
+Color of the path around the probability
+\end{mptparam}
+\begin{mptparam}{probbgcolor}{color}{white}
+Color of the background of the region delimited by the previous path.
+\end{mptparam}
+\begin{mptparam}{probfgcolor}{color}{black}
+Color of the text.
+\end{mptparam}
-\item[posprob] numeric controlling the position of the label above the edge. Default is $0.6$.
+\begin{exemple}[lefthand ratio=0.65]
+probformat:="circle";
+problinecolor:=(0.8,0,0);
+probbgcolor:=(1,0.5,0.5);
+probfgcolor:=white;
+draw tree[1][1](3cm,2cm)("$A$","$p$","$B$","$q$");
+\end{exemple}
-\begin{exemple}[0.65]
+\begin{exemple}[lefthand ratio=0.65]
+probfgcolor:=blue;
+draw tree[1][1](3cm,2cm)("$A$","$p$","$B$","$q$");
+\end{exemple}
+
+
+\begin{mptparam}{scaleprob}{numeric}{0.85}
+Numeric controlling the scale of the label above the edge (the probability).
+\end{mptparam}
+
+\begin{exemple}[lefthand ratio=0.65]
+ scaleprob:=1.5;
+ draw tree[1][1](3cm,2cm)("$A$","$p$","$B$","$q$");
+\end{exemple}
+
+
+\begin{mptparam}{posprob}{numeric}{0.6}
+Numeric controlling the position of the label above the edge.
+\end{mptparam}
+
+\begin{exemple}[lefthand ratio=0.65]
posprob:=0.8;
draw tree[1][1](3cm,2cm)("$A$","$p$","$B$","$q$");
\end{exemple}
-\item[typeprob] numeric controlling how the label is printed. Values can be 1 (the default, label is printed above the edge), 2 (the label is printed on the edge), 3 (the label is printed above the edge and rotated) or 4 (the label is printed on the edge and rotated).
-\begin{codecache}
-posprob:=0.6;
-\end{codecache}
+\begin{mptparam}{typeprob}{numeric}{1}
+Numeric controlling how the label is printed. Values can be 1 (the label is printed above the edge), 2 (the label is printed on the edge), 3 (the label is printed above the edge and rotated) or 4 (the label is printed on the edge and rotated).
+\end{mptparam}
-\begin{exemple}[0.7]
+\begin{exemple}[lefthand ratio=0.7]
typeprob:=2;
draw tree[1][1](3cm,2cm)("$A$","$p$","$B$","$1-p$");
\end{exemple}
-\begin{exemple}[0.7]
+\begin{exemple}[lefthand ratio=0.7]
typeprob:=3;
draw tree[1][1](3cm,2cm)("$A$","$p$","$B$","$1-p$");
\end{exemple}
-\begin{exemple}[0.7]
+\begin{exemple}[lefthand ratio=0.7]
typeprob:=4;
draw tree[1][1](3cm,2cm)("$A$","$p$","$B$","$1-p$");
\end{exemple}
-\item[proboffset] numeric controlling the amount by which the label above the edge is offset. Default is \verb|labeloffset| (\verb|3bp|).
-\begin{codecache}
-typeprob:=1;
-\end{codecache}
+\begin{mptparam}{proboffset}{numeric}{3bp}
+Numeric controlling the amount by which the label above the edge is offset.
+\end{mptparam}
-\begin{exemple}[0.75]
+\begin{exemple}[lefthand ratio=0.75]
draw tree[1][1](3cm,3cm)("$A$","$p+q+r$","$B$","$s$");
\end{exemple}
-\begin{exemple}[0.75]
+\begin{exemple}[lefthand ratio=0.75]
proboffset:=6bp;
draw tree[1][1](3cm,3cm)("$A$","$p+q+r$","$B$","$s$");
\end{exemple}
-\begin{codecache}
-proboffset:=3bp;
-\end{codecache}
-\end{description}
-
\subsection{Edge}
-\begin{description}
-\item[endedgeshift] vertical space added at the end of the edge. Default is $0$. Useful when various edges end at the same point
+\begin{mptparam}{linewidth}{numeric}{0.5bp}
+Width of the lines.
+\end{mptparam}
-\begin{exemple}[0.65]
+\begin{mptparam}{linecolor}{color}{black}
+Color of the lines.
+\end{mptparam}
+
+\begin{exemple}[lefthand ratio=0.65]
+ linewidth:=1.5;
+ linecolor:=blue;
+ draw tree[1][1](3cm,2cm)("$A$","$p$","$B$","$q$");
+\end{exemple}
+
+\begin{mptparam}{endedgeshift}{numeric}{0}
+Vertical space added at the end of the edge. Useful when various edges end at the same point.
+\end{mptparam}
+
+\begin{exemple}[lefthand ratio=0.65]
draw startlabel("$S$");
draw tree[1][1]((3cm,-1cm))("$A$","$p$");
\end{exemple}
-\begin{exemple}[0.65]
+\begin{exemple}[lefthand ratio=0.65]
endedgeshift:=10;
draw startlabel("$S$");
draw tree[1][1]((3cm,-1cm))("$A$","$p$");
\end{exemple}
-\begin{codecache}
-endedgeshift:=0;
-\end{codecache}
+\begin{mptparam}{edgearrow}{boolean}{false}
+When the boolean \verb|edgearrow| is set to true, edges end with an arrow.
+\end{mptparam}
+\begin{exemple}[lefthand ratio=0.65]
+ edgearrow:=true;
+ draw tree[1][1](3cm,2cm)("$A$","$p$","$B$","$q$");
+\end{exemple}
+\begin{mptparam}{branchtype}{string}{"segment"}
+String which indicates the shape of the edge. Possible values are \verb|segment|, \verb|curve|, \verb|broken|.
-\item[edgearrow] When the boolean \verb|edgearrow| is set to true, edges end with an arrow. Default is \verb|false|.
+Note that double quotes have to be replaced by single quotes when this parameter is changed locally inside the \verb|tree| macro.
+\end{mptparam}
-\begin{exemple}[0.65]
- edgearrow:=true;
- draw tree[1][1](3cm,2cm)("$A$","$p$","$B$","$q$");
+
+\begin{mptparam}{tenscurve}{numeric}{0}
+ If string \verb|branchtype| is set to \verb|curve|, \verb|tenscurve| indicates the ``tension". When sets to \verb|1|, the curve is a segment.
+ \end{mptparam}
+
+\begin{exemple}[lefthand ratio=0.6]
+ branchtype:="curve";
+ draw stree[1][1](3cm,3cm)("$A$","$B$");
\end{exemple}
-\begin{codecache}
-edgearrow:=false;
-\end{codecache}
-\item[branchtype] string which controls the shape of the edge. Possible values are \verb|segment| (default), \verb|curve|, \verb|broken|. With the last one, the length of the first segment of the broken line depends on a numeric parameter, \verb|brokenlineratio| which indicates the ratio between the length of this segment and the length of the horizontal space. Default value is \verb|0.2|.
-\end{description}
+\begin{exemple}[lefthand ratio=0.6]
+ draw stree[1][1](3cm,3cm,"branchtype:='curve'")
+ ("$A$","$B$");
+\end{exemple}
-\begin{exemple}[0.65]
+
+
+\begin{exemple}[lefthand ratio=0.6]
branchtype:="curve";
- draw tree[1][1](3cm,3cm)("$A$","$p$","$B$","$q$");
+ tenscurve:=0.5;
+ draw stree[1][1](3cm,3cm)("$A$","$B$");
\end{exemple}
-\begin{exemple}[0.65]
+
+\begin{mptparam}{brokenlineratio}{numeric}{0.2}
+ If string \verb|branchtype| is set to \verb|broken|, \verb|brokenlineratio| indicates the ratio between the length of the first segment of the broken line and the total length of the horizontal space.
+ \end{mptparam}
+
+\begin{exemple}[lefthand ratio=0.6]
branchtype:="broken";
- draw tree[1][1](3cm,3cm)("$A$","$p$","$B$","$q$");
+ draw stree[1][1](3cm,3cm)("$A$","$B$");
\end{exemple}
-\begin{exemple}[0.65]
+\begin{exemple}[lefthand ratio=0.6]
branchtype:="broken";
posprob:=0.8;
brokenlineratio:=0.5;
- draw tree[1][1](3cm,3cm)("$A$","$p$","$B$","$q$");
+ draw stree[1][1](3cm,3cm)("$A$","$B$");
\end{exemple}
-\begin{exemple}[0.65]
+\begin{exemple}[lefthand ratio=0.6]
branchtype:="broken";
posprob:=0.8;
brokenlineratio:=0.75;
- draw tree[1][1](3cm,3cm)("$A$","$p$","$B$","$q$");
+ draw stree[1][1](3cm,3cm)("$A$","$B$");
\end{exemple}
-\begin{codecache}
- posprob:=0.6;
- branchtype:="segment";
- brokenlineratio:=0.2;
-\end{codecache}
-\section{Binomial trees}
-\begin{description}
-\item[bernoulliprocess(n)(l,h)] tree describing the Bernoulli process with $n$ trials. \verb|l| is the length of the first edges and \verb|h| is the space between two final nodes.
-\item[bernoulliprocessL(n)(L,H)] same as above where \verb|L| is the whole width of the tree and \verb|H| its height.
-\end{description}
+\section{Regular trees}
+\subsection{Ordinary regular trees}
+\begin{rpobjet}{regulartree(<n>)(<l>,<h>)(<ev1>,<prob1>,<ev2>,<prob2>,...)}{picture}
+Tree describing the repetition of $n$ identical and independent random experiments. \verb|l| is the horizontal length of the first edges and \verb|h| is the vertical space between two leaves.
+\end{rpobjet}
+
+\begin{mptparam}{scalebranch}{numeric}{0.8}
+Ratio between edges width of consecutive level.
+\end{mptparam}
+
+\begin{exemple}[lefthand ratio=0.6]
+draw regulartree(2)(3cm,0.7cm)
+ ("$A$","$p$","$B$","$q$","$C$","$r$");
+\end{exemple}
+
+Note that you can change variable values inside the first set of parameters.
+
+\begin{exemple}[lefthand ratio=0.6]
+draw regulartree(2)(3cm,0.7cm,"typeprob:=2")
+ ("$A$","$p$","$B$","$q$","$C$","$r$");
+\end{exemple}
+
+
+\subsection{Binomial trees}
+
+\begin{rpobjet}{bernoulliprocess(<n>)(<l>,<h>)(<ev1>,<prob1>,<ev2>,<prob2>)}{picture}
+Tree describing the Bernoulli process with $n$ trials. \verb|l| is the horizontal length of the first edges and \verb|h| is the vertical space between two final nodes. If the last set of parameters is omitted, the values are set according to the following parameters.
+\end{rpobjet}
+
+
+\begin{rpobjet}{bernoulliprocessL(<n>)(<L>,<H>)(<ev1>,<prob1>,<ev2>,<prob2>)}{picture}
+Same as above where \verb|L| is the whole width of the tree and \verb|H| its height.
+\end{rpobjet}
+
+
+
Several parameters control the output:
-\begin{description}
-\item[bernoullisuccessevent] string printed at every node representing a success. Default is \verb|"$S$"|.
-\item[bernoullifailureevent] string printed at every node representing a failure. Default is \verb|"$\overline{S}$"|.
-\item[bernoullisuccessprob] string printed above every edge representing a success. Default is \verb|"$p$"|.
-\item[bernoullifailureprob] string printed above every edge representing a success. Default is \verb|"$q$"|.
-\item[bernoulliscalebranch] ratio between width of consecutive edges. Default is \verb|0.8|.
-\end{description}
+\begin{mptparam}{bernoullisuccessevent}{string}{"$S$"}
+String printed at every node representing a success.
+\end{mptparam}
-\begin{exemple}[0.45]
-draw bernoulliprocess(3)(3cm,0.7cm);
+\begin{mptparam}{bernoullifailureevent}{string}{"$\overline{S}$"}
+String printed at every node representing a failure.
+\end{mptparam}
+
+\begin{mptparam}{bernoullisuccessprob}{string}{"$p$"}
+String printed above every edge representing a success.
+\end{mptparam}
+
+\begin{mptparam}{bernoullifailureprob}{string}{"$q$"}
+String printed above every edge representing a failure.
+\end{mptparam}
+
+\begin{mptparam}{bernoulliscalebranch}{numeric}{0.8}
+Ratio between width of consecutive edges.
+\end{mptparam}
+
+
+
+
+
+\begin{exemple}[lefthand ratio=0.45]
+draw bernoulliprocess(3)(3cm,0.7cm)();
\end{exemple}
-\begin{exemple}[0.45]
+
+\begin{exemple}[lefthand ratio=0.45]
+draw bernoulliprocess(3)
+ (3cm,0.7cm,"typeprob:=2;")
+ ("$A$","$0.7$","$B$","$0.3$");
+\end{exemple}
+
+\begin{exemple}[lefthand ratio=0.45]
typeprob:=4;
bernoullisuccessevent:="$A$";
bernoullifailureevent:="$B$";
bernoullisuccessprob:="$0.7$";
bernoullifailureprob:="$0.3$";
-draw bernoulliprocess(3)(3cm,0.7cm);
+draw bernoulliprocess(3)(3cm,0.7cm)();
\end{exemple}
-\begin{codecache}
-typeprob:=1;
-bernoullisuccessevent := "$S$";
-bernoullifailureevent := "$\overline{S}$";
-bernoullisuccessprob := "$p$";
-bernoullifailureprob := "$q$";
-\end{codecache}
-\begin{description}
-\item[binomialtree(n)(l,h)] tree describing the binomial distribution with $n$ trials. \verb|l| is the length of the first edges and \verb|h| is the space between two final nodes. It uses \verb|bernoullisuccesprob| and \verb|bernoullifailureprob| but \verb|bernoulliscalebranch| is set to \verb|1|.
-\item[binomialtreeL(n)(L,H)] same as above where \verb|L| is the whole width of the tree and \verb|H| its height.
-\end{description}
+\begin{rpobjet}{binomialtree(<n>)(<l>,<h>)}{picture}
+Tree describing the binomial distribution with $n$ trials. \verb|l| is the length of the first edges and \verb|h| is the space between two final nodes. It uses \verb|bernoullisuccesprob| and \verb|bernoullifailureprob| but \verb|bernoulliscalebranch| is set to \verb|1|.
+\end{rpobjet}
-\begin{exemplev}{1}
-draw binomialtree(4)(3cm,1.5cm);
-\end{exemplev}
+\begin{rpobjet}{binomialtreeL(<n>)(<L>,<H>)}{picture}
+Same as above where \verb|L| is the whole width of the tree and \verb|H| its height.
+\end{rpobjet}
-\section{Embedded code in \LaTeX{} files}
-You can embed your code in \LaTeX{} files.
-\subsection{With \texttt{pdftex}}
-\medskip
+\begin{exemple}[listing above text]
+draw binomialtree(4)(3cm,1.5cm);
+\end{exemple}
-\begin{minipage}[t]{0.45\linewidth}
-{\centering \textbf{Using \texttt{emp} package}\par}
+\section{``Calculated'' trees}
+\marginnote[\btet]{}The following commands are experimental and need to be enclosed in a \verb|begintree;|...\verb|endtree;| ``environment".
-\verb|pdflatex myfile.tex|
+\begin{rpobjet}{tree[<i>][<j>]()(<ev1>,<prob1>,<ev2>,<prob2>,...)}{picture}
+When the first set of parameters is left empty, the dimensions of the tree are calculated. The calculations use the parameters described below.
+\end{rpobjet}
-\verb|mpost myfile.mp|
-\verb|mpost myfile.mp|
+\begin{rpobjet}{stree[<i>][<j>]()(<ev1>,<ev2>,...)}{picture}
+Same as above for ``simple'' trees.
+\end{rpobjet}
-\verb|pdflatex myfile.tex|
+\begin{exemple}[listing above text]
+begintree;
+draw startlabel("$S$");
+draw stree[1][1]()("$A$","$B$","$C$");
+draw stree[2][1]()("$D$","$E$","$F$");
+draw stree[2][3]()("$D$","$E$");
+draw stree[3][2]()("$G$","$H$");
+draw stree[3][4]()("$G$","$H$");
+endtree;
+\end{exemple}
-\begin{lstlisting}[frame=single,frameround=tttt,backgroundcolor=\color{LightSteelBlue},language={[LaTeX]TeX}]
-\documentclass{article}
-\usepackage{emp}
-\usepackage{ifpdf}
- \ifpdf % allows pdflatex compilation
- \DeclareGraphicsRule{*}{mps}{*}{}
- \fi
-\begin{document}
-\begin{empfile}
-\begin{empcmds}
- input mptrees;
-\end{empcmds}
-\begin{emp}(0,0)
- draw tree[1][1](3cm,3cm)(...);
-\end{emp}
-\end{empfile}
-\end{document}
-\end{lstlisting}
-\end{minipage}
-\hfill
-\begin{minipage}[t]{0.45\linewidth}
-{\centering \textbf{Using \texttt{mpgraphics} package}\par}
+\begin{mptparam}{widthbranch}{numeric}{3.5cm}
+Horizontal width of the first level tree.
+\end{mptparam}
+\begin{mptparam}{gapnode}{numeric}{0.7cm}
+Minimal vertical space between two nodes of the last level trees.
+\end{mptparam}
-\verb|pdflatex -shell-escape myfile.tex|
+\begin{mptparam}{scalebranch}{numeric}{0.8}
+Ratio between edges width of consecutive level.
+\end{mptparam}
-\begin{lstlisting}[frame=single,frameround=tttt,backgroundcolor=\color{LightSteelBlue},language={[LaTeX]TeX}]
-\documentclass{article}
-\usepackage[runs=2]{mpgraphics}
-\begin{document}
-\begin{mpdefs}
- input mptrees;
-\end{mpdefs}
-\begin{mpdisplay}
- draw tree[1][1](3cm,3cm)(...);
-\end{mpdisplay}
-\end{document}
-\end{lstlisting}
-\end{minipage}
-\subsection{With \texttt{luatex}}
+\begin{exemple}[listing above text]
+begintree;
+widthbranch:=4cm;
+scalebranch:=1;
+gapnode:=1cm;
+draw startlabel("$S$");
+draw stree[1][1]()("$A$","$B$","$C$");
+draw stree[2][1]()("$D$","$E$","$F$");
+draw stree[2][3]()("$D$","$E$");
+draw stree[3][2]()("$G$","$H$");
+draw stree[3][4]()("$G$","$H$");
+endtree;
+\end{exemple}
-\begin{center}
-\begin{minipage}[t]{0.6\linewidth}
-{\centering \textbf{Using Lua\LaTeX}\par}
-
-
-\verb|lualatex myfile.tex|
-
-\begin{lstlisting}[frame=single,frameround=tttt,backgroundcolor=\color{LightSteelBlue},language={[LaTeX]TeX}]
-\documentclass{article}
-\usepackage{fontspec}
-\usepackage{luamplib}
-\begin{document}
-\everymplib{input mptrees;}
-\begin{mplibcode}
-beginfig(1);
- draw tree[1][1](3cm,3cm)("$A$","$p$","$B$","$q$");
-endfig;
-\end{mplibcode}
-\end{document}
-\end{lstlisting}
-\end{minipage}
-\end{center}
-
\section{Examples}
-\begin{exemplev}[0.9]{1}
+\begin{exemple}[listing above text]
u:=0.4cm;
branchtype:="curve";
dirlabel:=90;
@@ -746,22 +974,20 @@
abscoord:=true;
endlabelspace:=0.5cm;
draw startlabel("S");
-draw tree[1][1]((-5.5u,4u),(5.5u,8u))("NP","","VP","");
-draw tree[2][1]((-8.5u,12u),(-2.5u,8u))("A","","NP","");
-draw tree[2][2]((3.5u,12u),(7.5u,12u))("V","","Adv","");
-draw tree[3][2]((-4.5u,12u),(-0.5u,12u))("A","","N","");
+draw stree[1][1]((-5.5u,4u),(5.5u,8u))("NP","VP");
+draw stree[2][1]((-8.5u,12u),(-2.5u,8u))("A","NP");
+draw stree[2][2]((3.5u,12u),(7.5u,12u))("V","Adv");
+draw stree[3][2]((-4.5u,12u),(-0.5u,12u))("A","N");
draw endlabel[3][1]("Colorless");
draw endlabel[4][1]("green");
draw endlabel[4][2]("ideas");
draw endlabel[3][3]("sleep");
draw endlabel[3][4]("furiously");
-\end{exemplev}
+\end{exemple}
-\begin{codecache}
-endlabelspace:=1cm;
-\end{codecache}
-\begin{exemplev}[0.9]{1}
+
+\begin{exemple}[listing above text]
u:=1cm;
branchtype:="broken";
dirlabel:=-90;
@@ -769,20 +995,14 @@
scaleev:=2;
label.top(textext("\Large Tree diagram of $(2x+1)(x-3)$"),(0,1cm));
draw startlabel("$\times$");
-draw tree[1][1]((-2u,-1.5u),(2u,-1.5u))("$+$","","$-$","");
-draw tree[2][1]((-3u,-3.5u),(-1u,-3.5u))("$\times$","","$1$","");
-draw tree[2][2]((1u,-3.5u),(3u,-3.5u))("$x$","","$3$","");
-draw tree[3][1]((-4u,-5.5u),(-2u,-5.5u))("$2$","","$x$","");
-\end{exemplev}
+draw stree[1][1]((-2u,-1.5u),(2u,-1.5u))("$+$","$-$");
+draw stree[2][1]((-3u,-3.5u),(-1u,-3.5u))("$\times$","$1$");
+draw stree[2][2]((1u,-3.5u),(3u,-3.5u))("$x$","$3$");
+draw stree[3][1]((-4u,-5.5u),(-2u,-5.5u))("$2$","$x$");
+\end{exemple}
-\begin{codecache}
-branchtype:="segment";
-dirlabel:=0;
-abscoord:=false;
-scaleev:=1;
-\end{codecache}
-\begin{exemplev}{1}
+\begin{exemple}[listing above text]
posprob:=0.5;
typeprob:=3;
shiftev:=1.5cm;
@@ -798,15 +1018,38 @@
endedgeshift:=5;
draw tree[2][1]((5cm,-2cm))("","Diagonals of equal length");
draw tree[2][2]((5cm,2cm))(square,"Diagonals perpendicular");
-\end{exemplev}
-
-\begin{codecache}
-end
-\end{codecache}
+\end{exemple}
-\makeatletter
-\immediate\closeout\verbatim at out
-\makeatother
+\begin{exemple}[listing above text]
+dirtree:=-90;
+branchtype:="curve"; tenscurve:=0.75;
+linewidth:=1; linecolor:=(0.2,0.2,0.7);
+widthbranch:=1cm; scalebranch:=0.9;
+gapnode:=1cm;
+leaveformat:="bbox";
+nodeformat:="superellipse"; nodebgcolor:=(0.6,0.6,1);
+begintree;
+label.top(textext("\Large Huffman tree (source Wikipedia)"),(0,1cm));
+draw startlabel("36");
+draw stree[1][1]()("20","16");
+draw stree[2][1]()("12","8");
+draw stree[2][2]()("8","8");
+draw stree[3][1]()("' '|7","5");
+draw stree[3][2]()("4","4");
+draw stree[3][3]()("4","'a'|4");
+draw stree[3][4]()("4","'e',4");
+draw stree[4][2]()("'f'|3","2");
+draw stree[4][3]()("'s'|2","'h'|2");
+draw stree[4][4]()("2","'i'|2");
+draw stree[4][5]()("'m'|2","'t'|2");
+draw stree[4][7]()("2","'n'|2");
+draw stree[5][2]()("'l'|1","'r'|1");
+draw stree[5][5]()("'p'|1","'x'|1");
+draw stree[5][9]()("'u'|1","'o'|1");
+endtree;
+\end{exemple}
+
+
\end{document}
Modified: trunk/Master/texmf-dist/metapost/mptrees/mptrees.mp
===================================================================
--- trunk/Master/texmf-dist/metapost/mptrees/mptrees.mp 2023-04-26 23:49:55 UTC (rev 66951)
+++ trunk/Master/texmf-dist/metapost/mptrees/mptrees.mp 2023-04-27 20:36:32 UTC (rev 66952)
@@ -2,10 +2,10 @@
%% mptrees.mp %%
%% Probability trees with MetaPost %%
%% o.peault at posteo.net %%
-%% Version 21.11 (November 2021) %%
+%% Version 23.04 (April 2023) %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
string mptreesversion;
-mptreesversion:="21.11";
+mptreesversion:="23.04";
%
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, either version 1.3 of this license
@@ -20,6 +20,30 @@
boolean arbres_latexmp;
arbres_latexmp:=true;
+
+boolean mpt_begtr; % is begintree used ?
+mpt_begtr:=false;
+numeric mpt_passe;
+mpt_passe:=1;
+
+
+% begintree permet de stocker les instructions de la figure dans mpt_tree pour calculs éventuels
+
+def begintree=
+ mpt_begtr:=true;
+ scantokens "def mpt_tree="
+enddef;
+
+let endtree = enddef;
+
+numeric mpt_tmpdirtree;
+
+
+% à la fin de begintree, on exécute deux fois mpt_tree
+extra_endfig:="if mpt_begtr: mpt_tree currentpicture:=nullpicture; mpt_passe:=2; AdjustNodes; mpt_tree; mpt_begtr:=false;mpt_passe:=1 fi;" & extra_endfig;
+%extra_endfig:="if mpt_begtr: mpt_tree drawoptions(withcolor blue); mpt_passe:=2; AdjustNodes; mpt_tree; mpt_begtr:=false;mpt_passe:=1 fi;" & extra_endfig;
+
+
numeric posprob; % position de l'étiquette sur la branche
posprob:=0.6;
@@ -42,17 +66,36 @@
numeric brokenlineratio;
brokenlineratio:=0.2;
+numeric linewidth;
+linewidth:=0.5bp;
+
+color linecolor;
+linecolor:=black;
+
pair Orig_arbre[][]; % sommet de l'arbre i,j
Orig_arbre[1][1]:=origin;
+pair mpt_dec_ori[][]; % Décalage avec la fin de la branche précédente
+mpt_dec_ori[1][1]:=(0,0);
+
+pair mpt_tmp_ori[][]; % Branche i,j,k
+
+pair mpt_br[][][]; % Branche i,j,k
+
+boolean exist.arbre[][]; % L'arbre i,j est-il dessiné ?
+exist.arbre[0][1]:=true;
+
+
numeric colonne_cour,ligne_cour;
+numeric mptLargeur[][],mptHauteur[][]; % diff largeur au rang i, diff hauteur rang i
numeric countligne[]; % nombre de ligne pour le niveau i
+for i=0 upto 128: countligne[i]:=0; endfor
-numeric typedec; % 0 origine dépend de la taille de l'évènement, 1 taille fixée
+%numeric typedec; % 0 origine dépend de la taille de l'évènement, 1 taille fixée
numeric shiftev; % taille du décalage dans le cas où typedec=1
-shiftev:=0; % dans ce cas, typedec =0
-extra_beginfig:=extra_beginfig & "shiftev:=0;"; % remise à zéro en début de figure
+shiftev:=-1; % dans ce cas, typedec =0
+%extra_beginfig:=extra_beginfig & "shiftev:=-1;"; % remise à zéro en début de figure
numeric typeprob; % affichage de la proba sur la branche
@@ -72,6 +115,11 @@
endlabelspace:=1cm;
+% Pour rendre les paramètres "locaux" à chaque figure
+extra_beginfig:=extra_beginfig & "init_loc_var;";
+
+
+
% Étiquette au début de l'arbre
picture mptreestartlabel;
@@ -78,12 +126,13 @@
mptreestartlabel:=nullpicture;
vardef startlabel(expr s)=
+ colonne_cour:=0;
mptreestartlabel:=labelarbres(s);
if dirtree<>0: dirlabel:=dirtree fi;
if dirlabel>0:
- theevlabel(labelarbres(s) scaled scaleev,origin,-180+dirlabel)
+ theevlabel(formatnodeev(labelarbres(s)) scaled scaleev,origin,-180+dirlabel)
else:
- theevlabel(labelarbres(s) scaled scaleev,origin,180+dirlabel)
+ theevlabel(formatnodeev(labelarbres(s)) scaled scaleev,origin,180+dirlabel)
fi
enddef;
@@ -131,14 +180,161 @@
fi
enddef;
+%%%%%%%%%%%%%%
+%% format nodes, leaves and probabilities
+%%%%%%%%%%%%%%
+
+% Colors
+color nodelinecolor,nodebgcolor,nodefgcolor;
+nodelinecolor:=black;
+nodebgcolor:=white;
+nodefgcolor:=black;
+
+color leavelinecolor,leavebgcolor,leavefgcolor;
+leavelinecolor:=black;
+leavebgcolor:=white;
+leavefgcolor:=black;
+
+color problinecolor,probbgcolor,probfgcolor;
+problinecolor:=black;
+probbgcolor:=white;
+probfgcolor:=black;
+
+
+% Superellipse
+numeric superellipseparam;
+superellipseparam:=0.85;
+
+vardef superellipsebox(expr p)=
+ save a,b,c,d,l;
+ pair a,b,c,d;
+ path l;
+ l := bbox p;
+ a=0.5[lrcorner l,urcorner l];
+ b=0.5[urcorner l,ulcorner l];
+ c=0.5[ulcorner l,llcorner l];
+ d=0.5[llcorner l,lrcorner l];
+ l:=superellipse(a,b,c,d,superellipseparam);
+ l
+enddef;
+
+vardef supellformat(expr p,cl,cb,cf)=
+image(%
+ fill superellipsebox(p) withcolor cb;
+ draw superellipsebox(p) withcolor cl;
+ draw p withcolor cf;
+)
+enddef;
+
+% Circle
+vardef circlebox(expr p)=
+ save a,b,c;
+ pair a,b,c;
+ a:=urcorner bbox p;
+ b:=llcorner bbox p;
+ c:=0.5[a,b];
+ fullcircle scaled (abs(b-a)-2) shifted c
+enddef;
+
+vardef circleformat(expr p,cl,cb,cf)=
+image(%
+ fill circlebox(p) withcolor cb;
+ draw circlebox(p) withcolor cl;
+ draw p withcolor cf;
+)
+enddef;
+
+% bbox
+vardef bboxformat(expr p,cl,cb,cf)=
+image(%
+ fill bbox p withcolor cb;
+ draw bbox p withcolor cl;
+ draw p withcolor cf;
+)
+enddef;
+
+
+% Format nodes
+
+string nodeformat,leaveformat,probformat; %How nodes and leaves should be printed
+nodeformat:="";
+leaveformat:="";
+probformat:="";
+
+
+
+
+vardef formatprob(expr p)=
+ save cl,cb,cf;
+ color cl,cb,cf;
+ cl:=problinecolor;
+ cb:=probbgcolor;
+ cf:=probfgcolor;
+ if probformat="superellipse":
+ supellformat(p,cl,cb,cf)
+ elseif probformat="circle":
+ circleformat(p,cl,cb,cf)
+ elseif probformat="bbox":
+ bboxformat(p,cl,cb,cf)
+ else:
+ image (draw p withcolor cf)
+ fi
+enddef;
+
+vardef formatnodeev(expr p)=
+ save cl,cb,cf;
+ color cl,cb,cf;
+ cl:=nodelinecolor;
+ cb:=nodebgcolor;
+ cf:=nodefgcolor;
+ if nodeformat="superellipse":
+ supellformat(p,cl,cb,cf)
+ elseif nodeformat="circle":
+ circleformat(p,cl,cb,cf)
+ elseif nodeformat="bbox":
+ bboxformat(p,cl,cb,cf)
+ else:
+ image (draw p withcolor cf)
+ fi
+enddef;
+
+vardef formatnodeleave(expr p)=
+ save cl,cb,cf;
+ color cl,cb,cf;
+ cl:=leavelinecolor;
+ cb:=leavebgcolor;
+ cf:=leavefgcolor;
+ if leaveformat="superellipse":
+ supellformat(p,cl,cb,cf)
+ elseif leaveformat="circle":
+ circleformat(p,cl,cb,cf)
+ elseif leaveformat="bbox":
+ bboxformat(p,cl,cb,cf)
+ elseif leaveformat="none":
+ image (draw p withcolor cf)
+ else:
+ formatnodeev(p)
+ fi
+enddef;
+
+
+vardef formatnode(expr p)=
+ if known exist.arbre[colonne_cour+1][counttmp]:
+ formatnodeev(p)
+ else:
+ formatnodeleave(p)
+ fi
+enddef;
+
+
+%%% Prints events
+
vardef theevlabel(expr s,z,inc)=
- save p; picture p;
save d; numeric d;
- if picture s: p=s
- else: p = textext(s)
- fi;
- d=0.5*longdir(p,inc);
- p shifted (z - center p + (d+labeloffset)*dir(inc))
+% save p;picture p;
+% p:=formatnode(s);
+ d=0.5*longdir(s,inc);
+ s shifted (z - center s + (d+labeloffset)*dir(inc))
enddef;
def evlabel = draw theevlabel enddef;
@@ -225,12 +421,24 @@
Ori -- (Ori + M) -- (Fin - M) -- Fin
enddef;
+numeric tenscurve;
+tenscurve:=0;
+
+vardef curveline(expr Ori,Fin)=
+ save tmp_angle;
+ numeric tmp_angle;
+ tmp_angle:=dirlabel+tenscurve*angle((Fin-Ori) rotated -dirlabel);
+ Ori{dir tmp_angle}..{dir tmp_angle}Fin
+enddef;
+
+
+
%%%%%%%% Dessin de la branche
vardef dessinbranche(expr Ori,Fin)=
if branchtype="segment":
Ori--Fin
elseif branchtype="curve":
- Ori{dir dirlabel}..{dir dirlabel}Fin
+ curveline(Ori,Fin)
elseif branchtype="broken":
brokenline(Ori,Fin)
else:
@@ -239,7 +447,7 @@
enddef;
-%%%%%%%% Dessin complet de la branche (avec proba, évènement
+%%%%%%%% Dessin complet de la branche (avec proba, évènement)
vardef branche_abs(expr Ori,Fin,Eve,Pro)=
save figtmp,thelab,figlab,tmpshft;
@@ -246,87 +454,108 @@
picture figtmp,thelab,figlab;
numeric tmpshft;
thelab:=labelarbres(Pro) scaled scaleprob;
- if ypart Ori > ypart Fin: %le décalage se fait en fonction de la direction de la branche
+ if ypart (Ori rotated -dirtree) > ypart (Fin rotated -dirtree): %le décalage se fait en fonction de la direction de la branche
tmpshft:=endedgeshift
else:
tmpshft:=-endedgeshift
fi;
- figlab:=thelabelbranche(Ori,(Fin+ (0,tmpshft)) rotatedaround(Ori,dirtree),thelab);
+ figlab:=thelabelbranche(Ori,(Fin+ (0,tmpshft)),thelab);
figtmp=image(%
if branchtype<>"none":
- if edgearrow:
+ if edgearrow:
drawarrow
else:
draw
fi
-% dessinbranche(Ori,Fin + (0,tmpshft)) rotatedaround(Ori,dirtree)
- dessinbranche(Ori,(Fin + (0,tmpshft)) rotatedaround(Ori,dirtree))
- fi;
+ dessinbranche(Ori,(Fin + (0,tmpshft))) withpen pencircle scaled linewidth withcolor linecolor;
+ fi
draw figlab;
- evlabel(Eve,Fin rotatedaround(Ori,dirtree),dirlabel)
+ evlabel(Eve,Fin,dirlabel)
);
figtmp
enddef;
+
vardef branche_rel(expr Ori,dx,dy,Eve,Pro)=
branche_abs(Ori,Ori+(dx,dy),Eve,Pro)
enddef;
+pair mptFinBranche[][]; % Branche qui mène au noeud [][]
+mptFinBranche[1][1]:=origin;
+pair mptFinBrancheRel[][][]; % k-ieme branche qui part de i,j
+mptFinBrancheRel[0][1][1]:=origin;
+
+numeric mptLargBranche[][], mptHautBranche[][]; % Branche qui mène au noeud [][]
+numeric mptNbBranches[][]; % Nombre de branches de l'arbre [][]
+for i=0 upto 10: for j=0 upto 100: mptNbBranches[i][j]:=1; endfor endfor
+mptNbBranches[0][1]:=1;
+
+
+numeric mptAbs[]; % Abscisse noeud i
+mptAbs[1]:=0;
+
+pair mptchild[][][];
+mptchild[0][1][1]:=(1,1);
+
+color mptparent[][];
+mptparent[1][1]:=(0,1,1);
+
+
vardef _arbre_(expr Ori)(text t)(text r)= % (pt)(pt1,pt2...)(ev,proba,ev,proba...)
- save figtmp,n,Fintmp,labeltmp,counttmp,countlab;
+ save figtmp,n,Fintmp,labeltmp,counttmp,countlab,tmpcountligne;
picture figtmp,labeltmp[];
- numeric counttmp,countlab;
+ numeric counttmp,countlab,tmpcountligne;
pair Fintmp[];
if dirtree<>0: dirlabel:=dirtree fi;
- if colonne_cour=1: for i=1 upto 128: countligne[i]:=0; endfor fi
+ if colonne_cour=1:
+ countligne[1]:=1;countligne[0]:=1;
+ for i=2 upto 128: countligne[i]:=0; endfor
+ fi
+ tmpcountligne:=countligne[colonne_cour+1];
+ counttmp:=tmpcountligne;
+ for i=t:
+ counttmp:=counttmp+1;
+ countligne[colonne_cour+1]:=countligne[colonne_cour+1]+1;
+ mptFinBrancheRel[colonne_cour][ligne_cour][counttmp-tmpcountligne]:=i rotatedaround(Ori,dirtree);
+ mptFinBranche[colonne_cour+1][counttmp]:=i rotatedaround(Ori,dirtree);
+ mptLargBranche[colonne_cour+1][counttmp]:= xpart i - xpart Ori;
+ mptHautBranche[colonne_cour+1][counttmp]:= ypart i - ypart Ori;
+ mptchild[colonne_cour][ligne_cour][counttmp-tmpcountligne]:=(colonne_cour+1,counttmp);
+ mptparent[colonne_cour+1][counttmp]:=(colonne_cour,ligne_cour,counttmp-tmpcountligne);
+ endfor;
+ mptAbs[colonne_cour+1]:= xpart mptFinBranche[colonne_cour+1][counttmp];
+ mptNbBranches[colonne_cour][ligne_cour]:=counttmp-tmpcountligne;
figtmp=image(%
- counttmp:=0;
- for i=t:
- counttmp:=counttmp+1;
- Fintmp[counttmp]:=i;
- endfor;
- counttmp:=0;countlab:=0;
- for i=r:
- countlab:=countlab+1;
- labeltmp[countlab]:=labelarbres(i);
- if countlab=2:
- counttmp:=counttmp+1;countligne[colonne_cour+1]:=countligne[colonne_cour+1]+1;
- draw branche_abs(Ori,Fintmp[counttmp],labeltmp[1] scaled scaleev,labeltmp[2]);
- Orig_arbre[colonne_cour+1][countligne[colonne_cour+1]]:=Fintmp[counttmp] shifted
- if typedec=0: ((longdir(labeltmp[1] scaled scaleev,dirlabel)+2labeloffset)*(1,0))
+ counttmp:=tmpcountligne;countlab:=0;
+ for i=r:
+ countlab:=countlab+1;
+ labeltmp[countlab]:=labelarbres(i);
+ if countlab=2:
+ counttmp:=counttmp+1;
+ labeltmp[1]:=formatnode(labeltmp[1]);
+ labeltmp[2]:=formatprob(labeltmp[2]);
+ draw branche_abs(Ori,mptFinBranche[colonne_cour+1][counttmp],labeltmp[1] scaled scaleev,labeltmp[2]);
+ Orig_arbre[colonne_cour+1][counttmp]:=mptFinBranche[colonne_cour+1][counttmp] shifted
+ if shiftev<0: ((longdir(labeltmp[1] scaled scaleev,dirlabel) + 2labeloffset)*(1,0))
else: (shiftev,0)
fi
- if dirtree=0: rotatedaround(Fintmp[counttmp],dirlabel) fi
- rotatedaround(Ori,dirtree);
- countlab:=0
+ rotatedaround(mptFinBranche[colonne_cour+1][counttmp],dirlabel);
+ if mpt_passe=1:
+ mpt_dec_ori[colonne_cour+1][counttmp]:= (Orig_arbre[colonne_cour+1][counttmp] rotatedaround(Ori,-dirtree))- mptFinBranche[colonne_cour+1][counttmp]
fi;
- endfor);
+ countlab:=0
+ fi;
+ endfor
+ );
figtmp
enddef;
-vardef arbre_var(expr Ori,horiz,Ymax)(text t)(text r)= % (pt,dec horiz,Ymax)(dy1,dy2...)(ev,proba,ev,proba...)
- save Fin,compt,Ytmp;
- numeric compt,Ytmp;
- pair Fin[];
- Fin[0]:=Ori+(horiz,Ymax);
- compt:=0;Ytmp:=Ymax;
- for i=t:
- compt:=compt+1;Ytmp:=Ytmp-i;
- Fin[compt]:=Ori+(horiz,Ytmp);
- endfor
- def ptarr=
- Fin[0]
- for i=1 upto compt:
- ,Fin[i]
- endfor
- enddef;
- _arbre_(Ori)(ptarr)(r)
-enddef;
+
vardef arbre_decv(expr Ori,horiz,Ymax)(text t)(text r)=
% (pt,dec horiz)(dy1,dy2...)(ev,proba,ev,proba...)
save Fin,compt,Ytmp;
@@ -379,7 +608,7 @@
endfor
def ptarr=
Fin[0]
- for i=1 upto compt:
+ for i=1 upto compt/2-1:
,Fin[i]
endfor
enddef;
@@ -399,22 +628,24 @@
@
enddef;
+vardef colonne.calc.arbre[]=
+ @
+enddef;
+vardef colonne.arbre[]=
+ @
+enddef;
+
vardef reg.arbre[][](text t)(text r)=
save compt,decal;
numeric compt,decal[];
colonne_cour:=colonne.#@;
ligne_cour:=@;
- typedec:=0;
- if shiftev<>0: typedec:=1 fi;
compt:=0;
for i=t:
if numeric i:
compt:=compt+1;
decal[compt]:=i
- else:
- typedec:=1;
- scantokens i
fi;
endfor
compt:=0;
@@ -429,17 +660,9 @@
vardef comp.arbre[][](text t)(text r)=
colonne_cour:=colonne.#@;
ligne_cour:=@;
- typedec:=0;
- if shiftev<>0: typedec:=1 fi;
save tmp_compt;
numeric tmp_compt;
tmp_compt:=0;
- for i=t:
- if string i:
- typedec:=1;
- scantokens i
- fi;
- endfor
if abscoord:
def tmp_text=t enddef
else:
@@ -464,8 +687,6 @@
numeric decal[];
colonne_cour:=colonne.#@;
ligne_cour:=@;
- typedec:=0;
- if shiftev<>0: typedec:=1 fi;
save tmp_compt;
numeric tmp_compt;
tmp_compt:=0;
@@ -473,9 +694,6 @@
if numeric i:
tmp_compt:=tmp_compt+1;
decal[tmp_compt]:=i
- else:
- typedec:=1;
- scantokens i
fi;
endfor
def tmp_text=
@@ -486,29 +704,298 @@
enddef;
arbre_decv(Orig_arbre[colonne_cour][ligne_cour],decal[1],decal[2])(tmp_text)(r)
enddef;
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
+
+vardef calc.arbre[][](text r)=
+ colonne_cour:=colonne.#@;
+ ligne_cour:=@;
+ save mpt_O,mpt_dec_calc;
+ pair mpt_O;
+ numeric mpt_dec_calc[];
+ for i=1 upto mptNbBranches[colonne_cour][ligne_cour]:
+ mpt_dec_calc[i]:=mpt_decbranche[colonne_cour][ligne_cour][i];
+ endfor
+ mpt_dec_calc[0]:=widthbranch*(scalebranch**colonne_cour);
+ def tmp_text_calc=
+ mpt_dec_calc[0]
+ for i=1 upto mptNbBranches[colonne_cour][ligne_cour]:
+ ,mpt_dec_calc[i]
+ endfor
+ enddef;
+ mpt_O:= mpt_tmp_ori[colonne_cour][ligne_cour];
+ dec.arbre[colonne_cour][ligne_cour](tmp_text_calc)(r)
+% _arbre_(mpt_O)(tmp_text_calc)(r)
+enddef;
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Macro principale - Modification Mars 2022 (variables locales)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+% Conversion des ' en " pour les variables locales.
+
+vardef singletodoublequote(expr chdb)=
+ save chsi;
+ string chsi;
+ chsi:="";
+ for i=1 upto length(chdb):
+ if ASCII(substring(i-1,i) of chdb) = 39:
+ chsi := chsi & char(34)
+ else:
+ chsi := chsi & substring(i-1,i) of chdb
+ fi;
+ endfor
+ chsi
+enddef;
+
+% Initialisation variables locales
+
+def init_loc_var=
+ numeric tmp_posprob, tmp_shiftev, tmp_typeprob, tmp_scaleev, tmp_scaleprob, tmp_proboffset, tmp_endedgeshift;
+ boolean tmp_edgearrow;
+ string tmp_branchtype;
+ tmp_posprob := posprob;
+ tmp_typeprob := typeprob;
+ tmp_shiftev:= shiftev;
+ tmp_scaleev := scaleev;
+ tmp_scaleprob := scaleprob;
+ tmp_proboffset := proboffset;
+ tmp_endedgeshift := endedgeshift;
+ tmp_edgearrow := edgearrow;
+ tmp_branchtype := branchtype;
+ save posprob, shiftev, typeprob, scaleev, scaleprob, proboffset, endedgeshift, edgearrow, branchtype;
+ numeric posprob, shiftev, typeprob, scaleev, scaleprob, proboffset, endedgeshift;
+ boolean edgearrow;
+ string branchtype;
+ posprob:=tmp_posprob;
+ typeprob:=tmp_typeprob;
+ shiftev:=tmp_shiftev;
+ scaleev := tmp_scaleev;
+ scaleprob := tmp_scaleprob;
+ proboffset := tmp_proboffset;
+ endedgeshift := tmp_endedgeshift;
+ edgearrow := tmp_edgearrow;
+ branchtype := tmp_branchtype;
+enddef;
+
+
+pair current_tree;
+
vardef arbre[][](text t)(text r)=
- save tmp_type,tmp_compt;
- numeric tmp_type,tmp_compt;
- tmp_compt:=0;
+ init_loc_var;
+ save tmp_type,tmp_compt,tmp_chdb;
+ numeric tmp_type,tmp_compt,tmp_comptii;
+ string tmp_chdb;
+ tmp_compt:=0;tmp_comptii:=0;
for i=t:
- if numeric i: tmp_compt:=tmp_compt+1 fi;
+ tmp_comptii:=tmp_comptii+1;
+ if numeric i:
+ tmp_compt:=tmp_compt+1
+ elseif string i:
+ tmp_chdb:=singletodoublequote(i);
+ scantokens tmp_chdb;
+ fi;
endfor
- if tmp_compt=0: % Arbre défini par des points (dec_horiz,dec_vert)
- comp.#@.@(t)(r)
- elseif tmp_compt=2: % Arbre régulier, on donne largeur et esp. vert.
- reg.#@.@(t)(r)
+ exist.#@.@:=true;
+ current_tree:=(colonne.#@,@);
+ if tmp_comptii=0:
+ if mpt_passe=1:
+ reg.#@.@(widthbranch*(scalebranch**colonne_cour),gapnode*(2**(3-colonne_cour)))(r)
+ else:
+ calc.#@.@(r)
+ fi
else:
- dec.#@.@(t)(r) % Arbre semi-régulier, largeur fixe, decalages vert.
+ Orig_arbre[1][1]:=origin;
+ if tmp_compt=0: % Arbre défini par des points (dec_horiz,dec_vert)
+ comp.#@.@(t)(r)
+ elseif tmp_compt=2: % Arbre régulier, on donne largeur et esp. vert.
+ reg.#@.@(t)(r)
+ else:
+ dec.#@.@(t)(r) % Arbre semi-régulier, largeur fixe, decalages vert.
+ fi
fi
enddef;
+
def tree = arbre enddef;
+%%%%% stree (simple tree) Arbre sans les probas
+vardef colonne.stree[]=
+ @
+enddef;
+
+vardef stree[][](text t)(text r)=
+ save cc,ll;
+ numeric cc,ll;
+ cc:=colonne.#@;
+ ll:=@;
+ def tmptxt=
+ for i=r:
+ i,"",
+ endfor
+ enddef;
+ tree[cc][ll](t)(tmptxt)
+enddef;
+
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%% "Calculated" trees
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+vardef ymean(expr i,j)=
+ (0
+ for k=1 upto mptNbBranches[i][j]:
+ + ypart (mptFinBrancheRel[i][j][k] rotated -dirtree)
+ endfor)/mptNbBranches[i][j]
+enddef;
+
+
+vardef barycentre(expr A,a,B,b)=
+ (a*A+b*B)/(a+b)
+enddef;
+
+numeric mpt_fact_gap;
+mpt_fact_gap:=1.5;
+
+vardef exlignes(expr col,lig)=
+% renvoie (x,y) tel que x<lig<y, x et y ont des child, 0 sinon
+ save tmpcl,tmpx,tmpy,ytrue;
+ pair tmpcl;
+ numeric tmpx,tmpy;
+ boolean ytrue;
+ tmpx:=0;tmpy:=0;ytrue:=false;
+ for i=1 upto countligne[col+1]:
+ if known exist.arbre[col+1][i]:
+ if i<lig:
+ tmpx:=i
+ else:
+ tmpy:=i;ytrue:=true;
+ fi
+ fi;
+ exitif ytrue;
+ endfor
+ (tmpx,tmpy)
+enddef;
+
+
+vardef mptCalcIsol(expr a,b,c,l)=
+ save tmpmin,tmpmax;
+ numeric tmpmin,tmpmax;
+ tmpmin:=xpart exlignes(a,l);
+ tmpmax:=ypart exlignes(a,l);
+ if tmpmin=0:
+ mptFinBrancheRel[a][greenpart mptparent[a+1][tmpmax]][bluepart mptparent[a+1][tmpmax]] + (tmpmax-l)*gapnode*mpt_fact_gap*((0,1) rotated dirtree)
+ elseif tmpmax=0:
+ mptFinBrancheRel[a][greenpart mptparent[a+1][tmpmin]][bluepart mptparent[a+1][tmpmin]] - (l-tmpmin)*gapnode*mpt_fact_gap*((0,1) rotated dirtree)
+ else:
+ barycentre(mptFinBrancheRel[a][greenpart mptparent[a+1][tmpmin]][bluepart mptparent[a+1][tmpmin]],tmpmax-l,mptFinBrancheRel[a][greenpart mptparent[a+1][tmpmax]][bluepart mptparent[a+1][tmpmax]],l-tmpmin)
+ fi
+enddef;
+
+
+numeric tmplig,tmpligii;
+
+numeric mpt_decbranche[][][];
+
+
+
+def AdjustNodes=
+ tmplig:=0;
+ for i=1 upto countligne[colonne_cour]:
+ for j= 1 upto mptNbBranches[colonne_cour][i]:
+ mptFinBrancheRel[colonne_cour][i][j]:=mptFinBranche[colonne_cour+1][1] -tmplig*gapnode*((0,1) rotated dirtree);
+ tmplig:=tmplig+1;
+ endfor
+ endfor
+ for cmpttmp:=1 upto colonne_cour-1: % plusieurs tours pour tout régler...
+ for col=colonne_cour-1 downto 0:
+ tmplig:=0;
+ for i=1 upto countligne[col]:
+ if known mptNbBranches[col][i]:
+ for j= 1 upto mptNbBranches[col][i]:
+ if known exist.arbre[col][i]:
+ tmplig:=tmplig+1;
+ if known exist.arbre[col+1][tmplig]:
+ mptFinBrancheRel[col][i][j]:=
+ (xpart (mptFinBrancheRel[col][i][j] rotated -dirtree),ymean(col+1,tmplig)) rotated dirtree;
+ else:
+ mptFinBrancheRel[col][i][j]:=mptCalcIsol(col,i,j,tmplig);
+ fi;
+ Orig_arbre[col+1][tmplig]:=(xpart (Orig_arbre[col+1][tmplig] rotated -dirtree),ypart (mptFinBrancheRel[col][i][j] rotated -dirtree)) rotated dirtree;
+ fi;
+ endfor
+ fi
+ endfor
+ endfor
+% adjustii;
+ endfor
+ for col=1 upto colonne_cour:
+ for i=1 upto countligne[col]:
+ if known exist.arbre[col][i]:
+ for j=1 upto mptNbBranches[col][i]:
+ mpt_decbranche[col][i][j]:=ypart (mptFinBrancheRel[col][i][j] rotated -dirtree) - ypart (Orig_arbre[col][i] rotated -dirtree);
+ endfor
+ fi
+ endfor
+ endfor
+ Orig_arbre[1][1]:=origin;
+enddef;
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%% regular trees
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+numeric scalebranch;
+scalebranch := 0.8;
+
+numeric widthbranch,gapnode;
+widthbranch:=3.5cm;
+gapnode:=0.7cm;
+
+vardef regulartree(expr n)(text t)(text r)=
+ save tmp,ll,shiftev,tmpstr,count,cc,tmp_compt,h;
+ numeric ll,count,cc,tmp_compt,h;
+ string tmpstr[][];
+ count:=0;cc:=1;
+ for i = r:
+ count := count + cc;
+ cc := 1 - cc;
+ tmpstr[count][cc] := i;
+ endfor
+ shiftev:=-1;
+ for j=1 upto count:
+ if shiftev < longdir(labelarbres(tmpstr[j][0]),dirtree):
+ shiftev := longdir(labelarbres(tmpstr[j][0]),dirtree)
+ fi;
+ endfor
+ shiftev := shiftev + 2*labeloffset;
+ tmp_compt:=1;
+ for i=t:
+ if (not string i) and (tmp_compt=1):
+ ll := i; tmp_compt:=2
+ elseif (not string i) and (tmp_compt=2):
+ h := i
+ else:
+ scantokens i
+ fi;
+ endfor
+ picture tmp;
+ tmp := image(%
+ for i := 1 upto n:
+ for j := 1 upto (count**(i-1)):
+ draw tree[i][j](ll,h*(count**(n-i)))(r);
+ endfor
+ ll := ll * scalebranch;
+ endfor
+ );
+ tmp
+enddef;
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% Binomial
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
string bernoullisuccessevent, bernoullifailureevent, bernoullisuccessprob, bernoullifailureprob;
bernoullisuccessevent := "$S$";
@@ -518,36 +1005,65 @@
numeric bernoulliscalebranch;
bernoulliscalebranch := 0.8;
-vardef bernoulliprocess(expr n)(expr l,h)=
- save tmp,ll,shiftev;
- numeric ll;
- shiftev:=max(longdir(labelarbres(bernoullisuccessevent),dirtree),longdir(labelarbres(bernoullifailureevent),dirtree))+2*labeloffset;
- ll := l;
- picture tmp;
- tmp := image(%
- for i := 1 upto n:
- for j := 1 upto (2**(i-1)):
- draw tree[i][j](ll,h*(2**(n-i)))(bernoullisuccessevent, bernoullisuccessprob, bernoullifailureevent, bernoullifailureprob);
- endfor
- ll := ll * bernoulliscalebranch;
+vardef bernoulliprocess(expr n)(text t)(text r)=
+ save tmp_ct,tmp_ch;
+ numeric tmp_ct;
+ string tmp_ch[];
+ tmp_ch[1]:=bernoullisuccessevent;
+ tmp_ch[2]:=bernoullisuccessprob;
+ tmp_ch[3]:=bernoullifailureevent;
+ tmp_ch[4]:=bernoullifailureprob;
+ tmp_ct:=0;
+ for i=r:
+ tmp_ct:=tmp_ct+1;
+ if string i:
+ tmp_ch[tmp_ct]:=i
+ fi;
endfor
- );
- tmp
+ regulartree(n)(t)(tmp_ch[1],tmp_ch[2],tmp_ch[3],tmp_ch[4])
enddef;
-vardef bernoulliprocessL(expr n)(expr L,H)=
- save l,h,lpic,hpic;
- numeric l,h,lpic,hpic;
- hpic:=0.5*longdir(labelarbres(bernoullisuccessevent),90+dirtree) + 0.5*longdir(labelarbres(bernoullifailureevent),90+dirtree);
- h := (H-hpic)/((2**n)-1);
- lpic:=longdir(mptreestartlabel,dirtree) + n*max(longdir(labelarbres(bernoullisuccessevent),dirtree) , longdir(labelarbres(bernoullifailureevent),dirtree)) + (2*n-1)*labeloffset;
+
+vardef bernoulliprocessL(expr n)(text t)(text r)=
+ save L,H,l,hh,lpic,hpic;
+ numeric L,H,l,hh,lpic,hpic;
+ save tmp_ct,tmp_chi,tmp_b;
+ numeric tmp_ct;
+ string tmp_chi[];
+ boolean tmp_b;
+ tmp_chi[1]:=bernoullisuccessevent;
+ tmp_chi[2]:=bernoullisuccessprob;
+ tmp_chi[3]:=bernoullifailureevent;
+ tmp_chi[4]:=bernoullifailureprob;
+ tmp_b:=true;
+ for i=t:
+ if numeric i:
+ if tmp_b: L:=i; tmp_b := false else: H:=i fi
+ fi;
+ endfor
+ tmp_ct:=0;
+ for i=r:
+ tmp_ct:=tmp_ct+1;
+ if string i:
+ tmp_chi[tmp_ct]:=i
+ fi;
+ endfor
+ hpic:=0.5*longdir(labelarbres(tmp_chi[1]),90+dirtree) + 0.5*longdir(labelarbres(tmp_chi[3]),90+dirtree);
+ hh := (H-hpic)/((2**n)-1);
+ lpic:=longdir(mptreestartlabel,dirtree) + n*max(longdir(labelarbres(tmp_chi[1]),dirtree) , longdir(labelarbres(tmp_chi[3]),dirtree)) + (2*n-1)*labeloffset;
if bernoulliscalebranch<>1:
l:= (L-lpic)*(1-bernoulliscalebranch)/(1-bernoulliscalebranch**n)
else:
l:= (L-lpic)/n
fi;
- bernoulliprocess(n)(l,h)
+ def tmp_text=
+ l,hh
+ for i=t:
+ if string i: ,i fi
+ endfor
+ enddef;
+ regulartree(n)(tmp_text)(tmp_chi[1],tmp_chi[2],tmp_chi[3],tmp_chi[4])
enddef;
More information about the tex-live-commits
mailing list.