diff options
author | Karl Berry <karl@freefriends.org> | 2017-05-11 22:45:06 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2017-05-11 22:45:06 +0000 |
commit | b08a68c7f825771ab5765589131b681b98bb6547 (patch) | |
tree | 7a2e749887d785f81247d2d4a39b6e40c88b340b /Master/texmf-dist | |
parent | c67847d183e3c1c94e3d6f644b03b99cbd601a25 (diff) |
mptrees (11may17)
git-svn-id: svn://tug.org/texlive/trunk@44297 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r-- | Master/texmf-dist/doc/metapost/mptrees/README.md | 8 | ||||
-rw-r--r-- | Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.pdf | bin | 0 -> 388957 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.tex | 543 | ||||
-rw-r--r-- | Master/texmf-dist/metapost/mptrees/mptrees.mp | 381 |
4 files changed, 932 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/metapost/mptrees/README.md b/Master/texmf-dist/doc/metapost/mptrees/README.md new file mode 100644 index 00000000000..c038dca046a --- /dev/null +++ b/Master/texmf-dist/doc/metapost/mptrees/README.md @@ -0,0 +1,8 @@ +Package mptrees - Version 17.05 - May 10, 2017 + +This package provides MetaPost tools for drawing simple probability trees. +One command and several parameters to control the output are provided. + + +License LPPL 1.3 + diff --git a/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.pdf b/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.pdf Binary files differnew file mode 100644 index 00000000000..f86d52150ce --- /dev/null +++ b/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.pdf diff --git a/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.tex b/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.tex new file mode 100644 index 00000000000..78fb19f8b14 --- /dev/null +++ b/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.tex @@ -0,0 +1,543 @@ +\documentclass[11pt,a4paper,english]{article} + +% To compile: +% (pdf)latex mptrees-doc.tex +% mpost mptrees-doc.mp +% mpost mptrees-doc.mp +% (pdf)latex mptrees-doc.tex + + \usepackage{calc,ifthen} + + \usepackage[utf8]{inputenc} + \usepackage[T1]{fontenc} + \usepackage{lmodern} + \usepackage{textcomp} + \usepackage{mathtools} + + \usepackage{geometry} + \geometry{twoside,hmargin=2cm,vmargin={1.5cm,1.8cm},includefoot} + + \usepackage[bottom]{footmisc} + + \usepackage{mflogo} + + + \usepackage{multicol} + \setlength{\multicolsep}{3pt} + \setlength{\columnsep}{0pt} + + \usepackage[toc]{multitoc} + + \usepackage{enumitem} + \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{babel} + \usepackage[colorlinks=true,urlcolor=blue]{hyperref} + + + +%%%%%%%%%%%%%%%%%%% moreverb.sty +\makeatletter +\newwrite\verbatim@out + \immediate\openout \verbatim@out \jobname.mp +\newwrite\temp@code +\def\verbatimwrite{% + \@bsphack + \immediate\openout \temp@code figtmp.mp + \let\do\@makeother\dospecials + \catcode`\^^M\active \catcode`\^^I=12 + \def\verbatim@processline{% + \immediate\write\verbatim@out + {\the\verbatim@line}% + \immediate\write\temp@code + {\the\verbatim@line} + }% + \immediate\write\temp@code{beginfig(\thenumfig)} + \verbatim@start} + +\def\endverbatimwrite{% + \immediate\closeout\temp@code + \@esphack + }% +\makeatother +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newlength{\largeurcode} +\newlength{\largeurfig} +\newcounter{numfig} +\setcounter{numfig}{-1} + +\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 + } + +\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@out{beginfig(\thenumfig)} + \verbatimwrite + }% + {% + \immediate\write\temp@code{endfig;} + \immediate\write\verbatim@out{endfig;} + + \endverbatimwrite + \par + \noindent + \inscode + \IfFileExists{\jobname.\thenumfig}% + {\begin{minipage}[c]{\largeurfig} + \centering \includegraphics{\jobname.\thenumfig}\par + \end{minipage}}{} + \par} +\makeatother + +\newenvironment{codecache}% + {\verbatimwrite}{\endverbatimwrite} + +\newcounter{reptmp} + + +\newcounter{repexemple} +\setcounter{repexemple}{0} + +\newcommand{\debutexemple}{\par\vspace{2ex} + \refstepcounter{repexemple} + \noindent {\bfseries \color{blue!20!black} + Example \arabic{repexemple}} + \par\nopagebreak\vspace{1ex} + } + + +\newenvironment{exemple}[1][0.5]% + {\debutexemple + \codefigure{0}{#1}{1} + }% + {\endcodefigure + \par\vspace{2ex}} + +\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}}{} + } + + + +\begin{document} +\title{Documentation of \texttt{mptrees.mp}} +\date{\today} +\author{Olivier \textsc{Péault}% +\footnote{E-mail : \href{mailto:o.peault@posteo.net}{\texttt{o.peault@posteo.net}}}} +\maketitle + +\setcounter{tocdepth}{2} + +%\setlength{\columnsep}{25pt} +%\tableofcontents +%\setlength{\columnsep}{10pt} + + +\newcommand{\ijc}{[i][j]} + +\begin{codecache} +input mptrees; +%input latexmp; +setupLaTeXMP(inputencoding="utf8", + packages="fourier,amsmath,nicefrac,babel[english]"); +dirtree:=0; +\end{codecache} + + + + +\section{Overview} + +This package is intended to simplify the drawing of probability trees with \MP. It provides one 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. + + +\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|... are strings and will be printed (using \verb|latexmp|) 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} + +\begin{center} +\begin{figreperedoc} +beginfig(0) +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$"); +draw tree[3][2](3cm,1cm)("$C$","$c$","$\overline{C}$","$1-c$"); +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; +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; +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; +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; +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; + +\end{figreperedoc} + +\end{center} + + +\section{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{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"; + +\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} +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} +} + +\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{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} +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} + +\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{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} +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} + +\begin{codecache} +extra_endfig:=""; +\end{codecache} + +\end{description} + +\section{Parameters} +\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. It should be used inside the first set of parameters of the tree (see example below). + +\begin{exemplev}{1} + draw arbre[1][1](80,120)("$A$","$0.5$","$\overline{A}$","$0.5$"); + draw arbre[2][1](70,40)("Yes","$p$","No","$q$","Maybe","$r$"); + draw arbre[2][2](70,40,"shiftev:=1.5cm")("Yes","$p$","No","$q$","Maybe","$r$"); + draw arbre[3][1](50,20)("$B$","$b$","$C$","$c$"); + draw arbre[3][2](50,20)("$B$","$b$","$C$","$c$"); + draw arbre[3][3](50,20)("$B$","$b$","$C$","$c$"); + draw arbre[3][4](50,20)("$B$","$b$","$C$","$c$"); + draw arbre[3][5](50,20)("$B$","$b$","$C$","$c$"); + draw arbre[3][6](50,20)("$B$","$b$","$C$","$c$"); +\end{exemplev} + + +\item[scaleprob] numeric controlling the scale of the label above the edge (the probability). Default is $0.85$. + +\item[posprob] numeric controlling the position of the label above the edge. Default is $0.6$. + +\begin{exemple}[0.65] + scaleprob:=1.5; + draw tree[1][1](3cm,2cm)("$A$","$p$","$B$","$q$"); +\end{exemple} + +\begin{codecache} +scaleprob:=0.85; +\end{codecache} + +\begin{exemple}[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{exemple}[0.7] + typeprob:=2; + draw tree[1][1](3cm,2cm)("$A$","$p$","$B$","$1-p$"); +\end{exemple} + +\begin{exemple}[0.7] + typeprob:=3; + draw tree[1][1](3cm,2cm)("$A$","$p$","$B$","$1-p$"); +\end{exemple} + +\begin{exemple}[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{exemple}[0.75] + draw tree[1][1](3cm,3cm)("$A$","$p+q+r$","$B$","$s$"); +\end{exemple} + + + +\begin{exemple}[0.75] + proboffset:=6bp; + draw tree[1][1](3cm,3cm)("$A$","$p+q+r$","$B$","$s$"); +\end{exemple} + + + +\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$. +\end{description} + +\begin{codecache} +proboffset:=3bp; +\end{codecache} + +\begin{exemplev}{1} +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} + + +\begin{exemplev}{1} +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} + + +\section{Embedded code in \LaTeX{} files} + +You can embed your code in \LaTeX{} files. + +\subsection{With \texttt{pdftex}} + +\medskip + +\begin{minipage}[t]{0.45\linewidth} +{\centering \textbf{Using \texttt{emp} package}\par} + + + +\verb|pdflatex myfile.tex| + +\verb|mpost myfile.mp| + +\verb|mpost myfile.mp| + +\verb|pdflatex myfile.tex| + + +\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} + + +\verb|pdflatex -shell-escape myfile.tex| + +\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{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} + + + + +\begin{codecache} +end +\end{codecache} + +\makeatletter +\immediate\closeout\verbatim@out +\makeatother +\end{document} + + diff --git a/Master/texmf-dist/metapost/mptrees/mptrees.mp b/Master/texmf-dist/metapost/mptrees/mptrees.mp new file mode 100644 index 00000000000..73adff12cf6 --- /dev/null +++ b/Master/texmf-dist/metapost/mptrees/mptrees.mp @@ -0,0 +1,381 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% mptrees.mp %% +%% Probability trees with MetaPost %% +%% o.peault@posteo.net %% +%% Version 17.05 (May 2017) %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% This work may be distributed and/or modified under the conditions of +% the LaTeX Project Public License, either version 1.3 of this license +% or (at your option) any later version. The latest version of this +% license is in http://www.latex-project.org/lppl.txt +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if not known mplib: input latexmp fi; + +boolean arbres_latexmp; +arbres_latexmp:=true; + +numeric posprob; % position de l'étiquette sur la branche +posprob:=0.6; + +numeric scaleprob; +scaleprob:=0.85; % échelle de l'étiquette sur la branche + +numeric dirtree; % direction de l'arbre +dirtree:=0; + +numeric proboffset; % redéfinition temporaire de labeloffset pour affichage probas +proboffset:=labeloffset; + +pair Orig_arbre[][]; % sommet de l'arbre i,j +Orig_arbre[1][1]:=origin; + +numeric colonne_cour,ligne_cour; + +numeric countligne[]; % nombre de ligne pour le niveau i + +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 + + +numeric typeprob; % affichage de la proba sur la branche +typeprob:=1; + + +vardef labelarbres(expr s)= + save p; picture p; + if picture s: p=s + else: p=textext(s) + fi; + p +enddef; + +vardef theevlabel(expr s,z,inc)= + save p; picture p; + save d; numeric d; + if picture s: p=s + else: p = textext(s) scaled defaultscale + fi; + if abs inc < abs angle (urcorner p -llcorner p): + d=abs(0.5(lrcorner p - llcorner p)/cosd(inc)) + else: + d=abs(0.5(ulcorner p - llcorner p)/sind(inc)) + fi; + p shifted (z - 0.5(lrcorner p - llcorner p) - 0.5(ulcorner p - llcorner p) + (d+labeloffset)*dir(inc)) +enddef; + +def evlabel = draw theevlabel enddef; + + +vardef thelabelbranchehaut(expr Ori,Fin,Fig)= + interim labeloffset:=proboffset; + if xpart Ori <= xpart Fin: + thelabel.rt(Fig rotated -(dirtree+90),origin) rotated (dirtree+90) shifted posprob[Ori,Fin] + else: + thelabel.rt(Fig rotated -(dirtree-90),origin) rotated (dirtree-90) shifted posprob[Ori,Fin] + fi +enddef; + + +vardef thelabelbranchehautrot(expr Ori,Fin,Fig)= + interim labeloffset:=proboffset; + if xpart Ori <= xpart Fin: + Fig shifted (0.5*(ulcorner Fig - lrcorner Fig) + llcorner Fig+(0,proboffset)) rotated (angle(Fin-Ori)) shifted posprob[Ori,Fin] + else: + Fig shifted (0.5*(ulcorner Fig - lrcorner Fig) + llcorner Fig+(0,proboffset)) rotated (angle(Ori-Fin)) shifted posprob[Ori,Fin] + fi +enddef; + + + + + +vardef thelabelbranchesuper(expr Ori,Fin,Fig)= + save figtmp; + picture figtmp; + figtmp:=Fig shifted (posprob[Ori,Fin]-0.5*(lrcorner Fig + ulcorner Fig)); + image(fill bbox figtmp withcolor background; + draw figtmp) +enddef; + + +vardef thelabelbranchesuperrot(expr Ori,Fin,Fig)= + save figtmp; + picture figtmp; + figtmp:=Fig shifted (-0.5*(lrcorner Fig + ulcorner Fig)) rotated (angle(Fin-Ori)) shifted posprob[Ori,Fin]; + image(fill bbox figtmp withcolor background; + draw figtmp) +enddef; + + + +vardef thelabelbranche(expr Ori,Fin,Fig)= + if typeprob=1: + thelabelbranchehaut(Ori,Fin,Fig) + elseif typeprob=2: + thelabelbranchesuper(Ori,Fin,Fig) + elseif typeprob=3: + thelabelbranchehautrot(Ori,Fin,Fig) + elseif typeprob=4: + thelabelbranchesuperrot(Ori,Fin,Fig) + fi +enddef; + + + +%%%%%%%% Dessin complet de la branche + +vardef branche_abs(expr Ori,Fin,Eve,Pro)= + save figtmp,thelab,figlab; + picture figtmp,thelab,figlab; + thelab:=labelarbres(Pro) scaled scaleprob; + figlab:=thelabelbranche(Ori,Fin rotatedaround(Ori,dirtree),thelab); + figtmp=image(% + draw Ori--Fin rotatedaround(Ori,dirtree); + draw figlab; + evlabel(Eve,Fin rotatedaround(Ori,dirtree),dirtree) + ); + figtmp +enddef; + + +vardef branche_rel(expr Ori,dx,dy,Eve,Pro)= + branche_abs(Ori,Ori+(dx,dy),Eve,Pro) +enddef; + + +vardef _arbre_(expr Ori)(text t)(text r)= % (pt)(pt1,pt2...)(ev,proba,ev,proba...) + save figtmp,n,Fintmp,labeltmp,counttmp,countlab; + picture figtmp,labeltmp[]; + numeric counttmp,countlab; + pair Fintmp[]; + if colonne_cour=1: for i=1 upto 6: countligne[i]:=0; endfor fi + 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],labeltmp[2]); + Orig_arbre[colonne_cour+1][countligne[colonne_cour+1]]:=Fintmp[counttmp] shifted + if typedec=0: (lrcorner labeltmp[1]-llcorner labeltmp[1]+2labeloffset*(1,0)) + else: (shiftev,0) + fi + rotatedaround(Ori,dirtree); + 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; + numeric compt,Ytmp; + pair Fin[]; + Fin[0]:=Ori+(horiz,Ymax); + compt:=0;Ytmp:=Ymax; + for i=t: + compt:=compt+1;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_fixe(expr Ori,horiz,Ymax,decy)(text r)= + save Fin,compt,compt_par; + numeric compt,compt_par; + pair Fin[]; + Fin[0]:=Ori+(horiz,Ymax); + compt:=0;compt_par:=0; + for i=r: + compt:=compt+1;compt_par:=compt_par+1; + if compt_par=2: + compt_par:=0; + Fin[compt/2]:=Ori+(horiz,Ymax-decy*compt/2); + fi + endfor + def ptarr= + Fin[0] + for i=1 upto compt: + ,Fin[i] + endfor + enddef; + _arbre_(Ori)(ptarr)(r) +enddef; + + +vardef colonne.reg.arbre[]= + @ +enddef; + +vardef colonne.comp.arbre[]= + @ +enddef; + +vardef colonne.dec.arbre[]= + @ +enddef; + + +vardef reg.arbre[][](text t)(text r)= + save compt,decal; +% numeric compt,decal[],shiftev; + numeric compt,decal[]; + colonne_cour:=colonne.#@; + ligne_cour:=@; + typedec:=0; + compt:=0; + for i=t: + if numeric i: + compt:=compt+1; + decal[compt]:=i + else: + typedec:=1; + scantokens i + fi; + endfor + compt:=0; + for i=r: + compt:=compt+1; + endfor + arbre_fixe(Orig_arbre[colonne_cour][ligne_cour],decal[1],(compt/2-1)*decal[2]/2,decal[2])(r) +enddef; + + + +vardef comp.arbre[][](text t)(text r)= + colonne_cour:=colonne.#@; + ligne_cour:=@; + typedec:=0; + save tmp_compt; + numeric tmp_compt; + tmp_compt:=0; + for i=t: + if string i: + typedec:=1; + scantokens i + fi; + endfor + def tmp_text= + for i=t: + hide(tmp_compt:=tmp_compt+1;) + if (tmp_compt>1) and (not string i): + ,Orig_arbre[colonne_cour][ligne_cour]+i + elseif not string i: + Orig_arbre[colonne_cour][ligne_cour]+i + fi + endfor + enddef; + _arbre_(Orig_arbre[colonne_cour][ligne_cour])(tmp_text)(r) +enddef; + + +vardef ddec.arbre[][](text t)(text r)= + save decal; + numeric decal[]; + colonne_cour:=colonne.#@; + ligne_cour:=@; + typedec:=0; + save tmp_compt; + numeric tmp_compt; + tmp_compt:=0; + for i=t: + if numeric i: + tmp_compt:=tmp_compt+1; + decal[tmp_compt]:=i + else: + typedec:=1; + scantokens i + fi; + endfor + def tmp_text= + -decal[3] + for i=4 upto tmp_compt: + ,-decal[i] + endfor + enddef; + arbre_var(Orig_arbre[colonne_cour][ligne_cour],decal[1],decal[2])(tmp_text)(r) +enddef; + +%%%%%%%%%%%%%%%%%%%%%%%%% Modif 10/16 - Décalage par rapport à l'origine +vardef dec.arbre[][](text t)(text r)= + save decal; + numeric decal[]; + colonne_cour:=colonne.#@; + ligne_cour:=@; + typedec:=0; + save tmp_compt; + numeric tmp_compt; + tmp_compt:=0; + for i=t: + if numeric i: + tmp_compt:=tmp_compt+1; + decal[tmp_compt]:=i + else: + typedec:=1; + scantokens i + fi; + endfor + def tmp_text= + decal[3] + for i=4 upto tmp_compt: + ,decal[i] + endfor + enddef; + arbre_decv(Orig_arbre[colonne_cour][ligne_cour],decal[1],decal[2])(tmp_text)(r) +enddef; +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5 + +vardef arbre[][](text t)(text r)= + save tmp_type,tmp_compt; + numeric tmp_type,tmp_compt; + tmp_compt:=0; + for i=t: + if numeric i: tmp_compt:=tmp_compt+1 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) + else: + dec.#@.@(t)(r) % Arbre semi-régulier, largeur fixe, decalages vert. + fi +enddef; + +def tree = arbre enddef; |