diff options
author | Karl Berry <karl@freefriends.org> | 2024-02-23 22:01:24 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2024-02-23 22:01:24 +0000 |
commit | 56c250a15c21205405acd7c0f05a958ef89387af (patch) | |
tree | 7ec2d6f2c0cc44ad2e924eb60311e22c4acfda1f /Master/texmf-dist/doc/metapost | |
parent | 6c6b18f01afe23c23ee93f9822de86efc67623fa (diff) |
mptrees (23feb24)
git-svn-id: svn://tug.org/texlive/trunk@70091 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/metapost')
-rw-r--r-- | Master/texmf-dist/doc/metapost/mptrees/README.md | 5 | ||||
-rw-r--r-- | Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.pdf | bin | 146573 -> 203314 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.tex | 461 |
3 files changed, 451 insertions, 15 deletions
diff --git a/Master/texmf-dist/doc/metapost/mptrees/README.md b/Master/texmf-dist/doc/metapost/mptrees/README.md index b982e778ca7..f74fa1c30c7 100644 --- a/Master/texmf-dist/doc/metapost/mptrees/README.md +++ b/Master/texmf-dist/doc/metapost/mptrees/README.md @@ -1,9 +1,8 @@ -Package mptrees - Version 23.04 - April 27, 2023 +Package mptrees - Version 24.02 - February 22, 2024 --- -This package provides MetaPost tools for drawing simple probability trees. -One main command, some variants and several parameters to control the output are provided. +This package provides MetaPost tools for drawing simple probability trees and graphs (in discrete geometry). --- diff --git a/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.pdf b/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.pdf Binary files differindex 300937fc617..5a62a3b5176 100644 --- a/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.pdf +++ 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 index 907e2eca9f1..1cc7339d014 100644 --- a/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.tex +++ b/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.tex @@ -17,7 +17,7 @@ \usepackage[bottom]{footmisc} \usepackage{mflogo} - + \usepackage[output-decimal-marker={,}]{siunitx} \usepackage{esvect} \usepackage{nicefrac} @@ -25,12 +25,11 @@ \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} @@ -38,7 +37,7 @@ \usepackage{url} \usepackage{verbatim} \usepackage{fancyvrb} - + \usepackage{array} \usepackage{colortbl} \usepackage{tabularx} @@ -53,7 +52,7 @@ beginfig(1);} \everyendmplib{endfig;} \mplibnumbersystem{decimal} - + \usepackage{tcolorbox} \tcbuselibrary{listings,skins}%,documentation} @@ -263,15 +262,14 @@ colback=red!10!white,colframe=red!50!black] - +\part{Trees} \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. +The first aim of this package is to simplify the drawing of probability trees (or other kind of "tree") 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 also with Lua\LaTeX{} and \verb|luamplib| package. -%Some of the following constructions need to be enclosed between \verb|begintree| and \verb|endtree|. \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). @@ -514,7 +512,7 @@ draw tree[2][1](3cm,2cm)(...); 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{mptparam}{scaleev}{numeric}{1} @@ -789,7 +787,7 @@ Note that double quotes have to be replaced by single quotes when this parameter \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 stree[1][1](3cm,3cm)("$A$","$B$"); @@ -1049,6 +1047,445 @@ draw stree[5][9]()("'u'|1","'o'|1"); endtree; \end{exemple} +\part{Graphs} +\section{Overview} +This package can also be used to draw graphs. In this case, you need to define the nodes by their coordinates and indicate the edges to be drawn. Various commands allow you to draw graphs quickly, but it is also possible to finely control the drawing of each node and edge. + +\section{Nodes} +\subsection{Definition} + +\begin{rpdeclaration}{defnodes(<pair1>,<pair2>,...)} +The easiest way to define the nodes : just put a list of pairs. This command does not draw anything, it just defines an array of pairs corresponding to the coordinates. By default the array name is \verb|A[]|. +\end{rpdeclaration} + +\begin{mptparam}{defnodename}{string}{"A"} +Default node array name. +\end{mptparam} + +\begin{mptparam}{nodename}{string}{"array"} +String indicating how the nodes are stored and labels are drawns: +\begin{itemize}[nosep] +\item with \verb|nodename="array"|, nodes are stored in \verb|A[]| and labelled \verb|A1|, \verb|A2|,... +\item with \verb|nodename="Alph"|, nodes are stored and labelled \verb|A|, \verb|B|,... +\item with \verb|nodename="alph"|, nodes are stored and labelled \verb|a|, \verb|b|,... +\item with \verb|nodename="arabic"|, nodes are stored in \verb|A[]|,... but are labelled $1$, $2$,... +\end{itemize} +\end{mptparam} + +\begin{rpdeclaration}{defnode(<token>,<pair>)} +Nodes can be defined one by one. \verb|<token>| is the node's name and \verb|<pair>| its coordinates. +\end{rpdeclaration} + +\subsection{Drawing} + +\begin{rplabel}{drawnodes.<pos>(<nodei>,<nodej>,...)} +Draw all the indicated nodes. These nodes can be designated either by name or by rank. If the list is empty, all the nodes are drawn. \verb|pos| can be empty or \verb|lft|, \verb|rt|, etc. or an angle. +\end{rplabel} + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,0),(4cm,0)); +drawnodes(1,3); +\end{exemple} + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,0),(4cm,0)); +drawnodes(A1,A3); +\end{exemple} + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,0),(4cm,0)); +drawnodes(); +\end{exemple} + + +\begin{exemple}[lefthand ratio = 0.6] +defnodename:="N"; +defnodes((0cm,0cm),(2cm,0),(4cm,0)); +drawnodes(); +\end{exemple} + + +\begin{exemple}[lefthand ratio = 0.6] +nodename:="Alph"; +defnodes((0cm,0cm),(2cm,0),(4cm,0)); +drawnodes(); +\end{exemple} + +\begin{exemple}[lefthand ratio = 0.6] +nodename:="alph"; +defnodes((0cm,0cm),(2cm,0),(4cm,0)); +drawnodes(); +\end{exemple} + +\begin{exemple}[lefthand ratio = 0.6] +nodename:="arabic"; +defnodes((0cm,0cm),(2cm,0),(4cm,0)); +drawnodes(); +\end{exemple} + +\begin{mptparam}{printnodename}{boolean}{true} +When set to false, node names are not printed. +\end{mptparam} + +\begin{exemple}[lefthand ratio = 0.6] +printnodename:=false; +defnodes((0cm,0cm),(2cm,0),(4cm,0)); +drawnodes(); +\end{exemple} + + +\begin{mptparam}{nodeformat}{string}{""} +String that indicates how the nodes are printed (the shape of path around the node). Possible values are (for now) \verb|"bbox"|, \verb|"circle"|, \verb|"superellipse"| and \verb|"square"|. +\end{mptparam} + + +\begin{mptparam}{nodewidth}{numeric}{0.6cm} +Node width... +\end{mptparam} + +\begin{exemple}[lefthand ratio = 0.6] +nodeformat:="square"; +nodewidth:=1cm; +defnodes((0cm,0cm),(2cm,0),(4cm,0)); +drawnodes(); +\end{exemple} + +\begin{exemple}[lefthand ratio = 0.6] +nodewidth:=0.2cm; +defnodes((0cm,0cm),(2cm,0),(4cm,0)); +drawnodes.bot(); +\end{exemple} + +\begin{mptparam}{naturalwidth}{boolean}{false} +When set to true, the width of the node adapts to the content. +\end{mptparam} + +\begin{exemple}[lefthand ratio = 0.6] +defnodename:="AA"; +naturalwidth:=true; +defnodes((0cm,0cm),(2cm,0),(4cm,0)); +drawnodes(); +\end{exemple} + +\begin{mptparam}{nodelinewidth}{numeric}{1} +Line width of the path around the node. +\end{mptparam} + +\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.6] +nodelinecolor:=(0.8,0,0); +nodebgcolor:=(1,0.5,0.5); +nodefgcolor:=white; +nodeformat:="superellipse"; +defnodes((0cm,0cm),(2cm,0),(4cm,0)); +drawnodes(); +\end{exemple} + + +\begin{rpdeclaration}{drawnodes(<nodes>) withbgcolor <color>} +While \verb|withcolor| applies to lines and labels, \verb|withbgcolor| applies to the filling of nodes. +\end{rpdeclaration} + +\begin{exemple}[lefthand ratio = 0.63] +nodelinecolor:=(0.8,0,0); +nodebgcolor:=(1,0.5,0.5); +nodefgcolor:=white; +nodeformat:="superellipse"; +defnodes((0cm,0cm),(2cm,0),(4cm,0)); +drawnodes() withcolor black withbgcolor (0.6,0.6,1); +\end{exemple} + + +\begin{rplabel}{drawnode.<pos>(<node>,<label>)} +The nodes can be drawn one by one, specifying the text to be displayed if necessary. +\end{rplabel} + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,0),(4cm,0)); +drawnode[60](1); +drawnode(2,"$\sqrt{2}$") withbgcolor 0.7white; +drawnode.bot(A3,"Node"); +\end{exemple} + +\section{Edges} +\subsection{Undirected edges} + +\begin{rplabel}{drawedges.<pos>(<(Na,Nb)>,<string1>,<(Nc,Nd)>,<string2>,...)(<angle1>,<angle2>)} +Draw undirected edges between Node Na and node Nb, between node Nc and node Nd,... Na, Nb, Nc, Nd... must be integers. You can't refer to the nodes with their name. + +If present, the string is printed at the position indicated in relation to the middle of the edge (by default). + +By default, the edge is a segment. If an angle is specified, it is added to the angle at the start of the edge and subtracted from the angle at the end of the edge. If two angles are specified, they are added to the start and end angles respectively. +\end{rplabel} + + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +drawnodes(); +drawedges((1,2),(3,1))(); +\end{exemple} + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +drawnodes(); +drawedges((1,2),(3,1),"$p$")(); +\end{exemple} + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +drawnodes(); +drawedges.bot((1,2),(3,1),"$p$")(); +\end{exemple} + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +drawnodes(); +drawedges((1,2),(3,1))(30); +\end{exemple} + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +drawnodes(); +drawedges((1,2),(3,1))(40,10); +\end{exemple} + + + +\begin{rplabel}{drawedge.<pos>(<Na>,<Nb>)(<angle1>,<angle2>,<string>)} +The edges can be drawn one by one.In this case, Na, Nb can be the node name. The label or weight must be indicated in the second set of parameters. +\end{rplabel} + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +drawnodes(); +drawedge(1,2)(); +drawedge.bot(1,3)("$p$"); +drawedge(2,3)(30,"2"); +\end{exemple} + +\subsection{Directed edges} + +\begin{rplabel}{drawdiredges.<pos>(<(Na,Nb)>,<string1>,<(Nc,Nd)>,<string2>,...)(<angle1>,<angle2>)} +Draw directed edges from Node Na to node Nb, from node Nc to node Nd,... Na, Nb, Nc, Nd... must be integers. You can't refer to the nodes with their name. + +If present, the string is printed at the position indicated in relation to the middle of the edge (by default). + +By default, the edge is a segment. If an angle is specified, it is added to the angle at the start of the edge and subtracted from the angle at the end of the edge. If two angles are specified, they are added to the start and end angles respectively. +\end{rplabel} + + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +drawnodes(); +drawdiredges((1,2),"35",(3,1),"$p$")(); +\end{exemple} + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +drawnodes(); +drawdiredges.bot((1,2),(3,1),"$p$")(30); +\end{exemple} + +\begin{rplabel}{drawdiredge.<pos>(<Na>,<Nb>)(<angle1>,<angle2>,<string>)} +The directed edges can be drawn one by one. In this case, Na, Nb can be the node name. The label or weight must be indicated in the second set of parameters. +\end{rplabel} + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +drawnodes(); +drawdiredge(1,2)(); +drawdiredge.bot(1,3)("$p$"); +drawdiredge(2,3)(30,"2"); +\end{exemple} + +\subsection{Loops} +\begin{rplabel}{draw(dir)edge.<pos>(<Na>,<Na>)(<angle1>,<angle2>,<string>)} +Previous commands can be used to draw loops. If present, \verb|angle1| indicates the angle of the loop with horizontal direction. Default value is 90. +\end{rplabel} + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +drawnodes(); +drawdiredge(1,1)(); +drawedge(3,3)(-150); +drawdiredge.bot(2,2)(-90,"a"); +\end{exemple} + + +\subsection{Parameters} +\begin{mptparam}{edgelinewidth}{numeric}{1} +Width of the edge. +\end{mptparam} + +\begin{exemple}[lefthand ratio = 0.6] +edgelinewidth:=2; +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +drawnodes(); +drawedges((1,2),(3,1),"$p$")(); +\end{exemple} + +\begin{mptparam}{nodeedgeoffset}{numeric}{0} +Space between the node and the edge. +\end{mptparam} + +\begin{exemple}[lefthand ratio = 0.6] +nodeedgeoffset:=0.3cm; +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +drawnodes(); +drawedges((1,2),(3,1),"$p$")(); +\end{exemple} + + +\begin{mptparam}{probformat}{string}{""} +String that indicates how the weights are printed (the shape of the path). Possible values are (for now) \verb|"bbox"|, \verb|"circle"|, \verb|"superellipse"| and \verb|"square"|. + +\end{mptparam} + + +\begin{mptparam}{problinecolor}{color}{black} +Color of the path around the weight. +\end{mptparam} + +\begin{mptparam}{probgcolor}{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} + +\begin{exemple}[lefthand ratio = 0.6] +problinecolor:=(0.8,0,0); +probbgcolor:=(1,0.5,0.5); +probfgcolor:=white; +probformat:="square"; +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +drawnodes(); +drawedges((1,2),"35",(3,1),"$p$")(); +\end{exemple} + +\begin{mptparam}{posprob}{numeric}{0.5} +Position of the weight on the edge. +\end{mptparam} + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +posprob:=0.75; +drawnodes(); +drawedges((1,2),"35",(3,1),"$p$")(); +\end{exemple} + +\begin{mptparam}{edgearrowpos}{numeric}{1} +Position of arrowhead on the edge. +\end{mptparam} + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +edgearrowpos:=0.5; +drawnodes(); +drawdiredges.bot((1,2),(3,1),"$p$")(); +\end{exemple} + +\begin{mptparam}{loopangle}{numeric}{90} +Loop direction. It can be specified in the command parameters. +\end{mptparam} + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +loopangle:=-90; +drawnodes(); +drawdiredges((1,1),(2,2),(3,3))(); +\end{exemple} + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +drawnodes(); +drawdiredges((1,1),(2,2),(3,3))(-90); +\end{exemple} + +\begin{mptparam}{loopstartangle}{numeric}{30} +Angle between the path direction at node center and loop direction. +\end{mptparam} + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +loopstartangle:=90; +drawnodes(); +drawdiredges((1,1),(2,2),(3,3))(-90); +\end{exemple} + + +\begin{mptparam}{loopsize}{numeric}{1.5nodesize} +Loop size. +\end{mptparam} + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,0cm),(4cm,0)); +loopsize:=1.5cm; +drawnodes(); +drawdiredges((1,1),(2,2),(3,3))(); +\end{exemple} + +\section{Complete graphs} + +\begin{rplabel}{draw(dir)graph.<pos>(<(Na,Nb)>,<string1>,<(Nc,Nd)>,<string2>,...)(<angle1>,<angle2>)} +These commands are shortcuts for drawing both nodes and edges. +\end{rplabel} + + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +drawgraph((1,2),"35",(3,1),"$p$")(); +\end{exemple} + +\begin{exemple}[lefthand ratio = 0.6] +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +nodewidth:=0.2cm; +drawdirgraph.bot((1,2),(3,1),(2,2))(30); +\end{exemple} + + +\section{Grids} +To facilitate node placement, use the following command to draw a grid. + +\begin{rplabel}{drawgrid(<xmin>,<ymin>,<xmax>,<ymax>)(<unit>,<step>)} +Command for drawing a grid. Minimum values are optional and equal to 0 by default. The unit and step values are also optional and default to 1 cm and 1 respectively. +\end{rplabel} + +\begin{exemple}[lefthand ratio = 0.6] +drawgrid(4,4)(); +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +drawnodes(); +drawedges((1,2),(3,1))(); +\end{exemple} + +\begin{exemple}[lefthand ratio = 0.6] +drawgrid(-1,-1,5,3)(1cm,0.5); +defnodes((0cm,0cm),(2cm,2cm),(4cm,0)); +drawnodes(); +drawedges((1,2),(3,1))(); +\end{exemple} + +\begin{exemple}[lefthand ratio = 0.6] +u:=0.75cm; +drawgrid(-1,-1,5,3)(u); +defnodes((0,0),(2u,2u),(4u,0)); +drawnodes(); +drawedges((1,2),(3,1))(); +\end{exemple} + \end{document} |