initial commit
This commit is contained in:
commit
ef91426863
45 changed files with 1731 additions and 0 deletions
47
README.md
Normal file
47
README.md
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
# Generate graph in PNG using metapost
|
||||||
|
|
||||||
|
First you need to install `metapost` and `imagemagick`.
|
||||||
|
|
||||||
|
Then this code provide a nice code to draw graphs and automata.
|
||||||
|
Furthermore the script `gen` generate only PNG optimized for the web.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
~~~
|
||||||
|
z0=(1.3u,0);
|
||||||
|
z1=z0 shifted (u,0);
|
||||||
|
z2=z1 shifted (u,0);
|
||||||
|
|
||||||
|
nodesize:=4bp;
|
||||||
|
nodespace:=6bp;
|
||||||
|
|
||||||
|
drawstate(z0);
|
||||||
|
drawstate(z1);
|
||||||
|
drawstate(z2);
|
||||||
|
|
||||||
|
drawarrow edge(z0,z1);
|
||||||
|
drawarrow edge(z1,z2);
|
||||||
|
drawarrow edgeAngle(z0,z2,-35);
|
||||||
|
|
||||||
|
nodesize:=6bp;
|
||||||
|
ahlength:=.3nodesize;
|
||||||
|
drawarrow edge(z0,z0);
|
||||||
|
drawarrow edge(z1,z1);
|
||||||
|
drawarrow edge(z2,z2);
|
||||||
|
|
||||||
|
label(btex $ = 3 = $ etex,origin);
|
||||||
|
drawstate((-1.5u,.2u));
|
||||||
|
drawstate((-1.5u-.2u,-.2u));
|
||||||
|
drawstate((-1.5u+.2u,-.2u));
|
||||||
|
~~~
|
||||||
|
|
||||||
|
Render as
|
||||||
|
|
||||||
|
<figure>
|
||||||
|
<img src="./abstraction.png" alt="The category for the number 3">
|
||||||
|
<figcaption>
|
||||||
|
The category corresponding to number 3.
|
||||||
|
</figcaption>
|
||||||
|
</figure>
|
||||||
|
|
||||||
|
|
BIN
abstraction.png
Normal file
BIN
abstraction.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
5
clean
Executable file
5
clean
Executable file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
|
listfic=( *.png(N.) )
|
||||||
|
((${#listfic} > 0)) && \rm -f $listfic
|
||||||
|
[[ -e /tmp/mp ]] && \rm -rf /tmp/mp
|
3
examples/README.md
Normal file
3
examples/README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Examples
|
||||||
|
|
||||||
|
Put the mp file in the upper directory then just run `./gen` in the upper directory.
|
25
examples/abstraction.mp
Normal file
25
examples/abstraction.mp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
z0=(1.3u,0);
|
||||||
|
z1=z0 shifted (u,0);
|
||||||
|
z2=z1 shifted (u,0);
|
||||||
|
|
||||||
|
nodesize:=4bp;
|
||||||
|
nodespace:=6bp;
|
||||||
|
|
||||||
|
drawstate(z0);
|
||||||
|
drawstate(z1);
|
||||||
|
drawstate(z2);
|
||||||
|
|
||||||
|
drawarrow edge(z0,z1);
|
||||||
|
drawarrow edge(z1,z2);
|
||||||
|
drawarrow edgeAngle(z0,z2,-35);
|
||||||
|
|
||||||
|
nodesize:=6bp;
|
||||||
|
ahlength:=.3nodesize;
|
||||||
|
drawarrow edge(z0,z0);
|
||||||
|
drawarrow edge(z1,z1);
|
||||||
|
drawarrow edge(z2,z2);
|
||||||
|
|
||||||
|
label(btex $ = 3 = $ etex,origin);
|
||||||
|
drawstate((-1.5u,.2u));
|
||||||
|
drawstate((-1.5u-.2u,-.2u));
|
||||||
|
drawstate((-1.5u+.2u,-.2u));
|
22
examples/associativecomposition.mp
Normal file
22
examples/associativecomposition.mp
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
z0=origin;
|
||||||
|
z1=(gu,0);
|
||||||
|
z2=(2gu,0);
|
||||||
|
z3=(3gu,0);
|
||||||
|
|
||||||
|
drawState(z0,"A");
|
||||||
|
drawState(z1,"B");
|
||||||
|
drawState(z2,"C");
|
||||||
|
drawState(z3,"D");
|
||||||
|
|
||||||
|
drawEdge(z1,z2,"g");
|
||||||
|
|
||||||
|
drawoptions(withcolor blue);
|
||||||
|
drawEdgeAngle(z0,z2,"g\circ f",35);
|
||||||
|
drawEdge(z2,z3,"h");
|
||||||
|
|
||||||
|
drawoptions(withcolor green);
|
||||||
|
drawEdge(z0,z1,"f");
|
||||||
|
drawEdgeAngle(z1,z3,"h\circ g",-35);
|
||||||
|
|
||||||
|
drawoptions(withcolor yellow);
|
||||||
|
drawEdgeAngle(z0,z3,"(h\circ g)\circ f = h\circ (g\circ f)",50);
|
43
examples/boxfunctor.mp
Normal file
43
examples/boxfunctor.mp
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
pair a,b;
|
||||||
|
a:=origin;
|
||||||
|
b:=a shifted (1.7gu,0);
|
||||||
|
|
||||||
|
drawState(a,"a");
|
||||||
|
drawState(b,"b");
|
||||||
|
drawEdge(a,b,"f");
|
||||||
|
|
||||||
|
pair fa,fb;
|
||||||
|
fa=a shifted (0,-.6gu);
|
||||||
|
fb=b shifted (0,-.6gu);
|
||||||
|
|
||||||
|
drawbox(fa,"F");
|
||||||
|
drawState(fa,"a");
|
||||||
|
drawbox(fb,"F");
|
||||||
|
drawState(fb,"b");
|
||||||
|
|
||||||
|
pair mf,mff;
|
||||||
|
path ab,fafb;
|
||||||
|
ab :=edge(a,b);
|
||||||
|
fafb:=edge(fa,fb);
|
||||||
|
mf := midpoint(ab);
|
||||||
|
mff := midpoint(fafb);
|
||||||
|
path p, arr;
|
||||||
|
p := mf -- mff;
|
||||||
|
arr := subpath (0.05,0.65) of p;
|
||||||
|
drawoptions(withcolor yellow);
|
||||||
|
label.rt(btex $\mathtt{fmap}$ etex,midpoint(arr));
|
||||||
|
drawoptions(withcolor yellow withpen pencircle scaled 1 dashed evenly);
|
||||||
|
drawarrow arr;
|
||||||
|
p:=edge(a,fa);
|
||||||
|
arr := subpath (0,0.7) of p;
|
||||||
|
drawarrow arr;
|
||||||
|
label.rt(btex $F$ etex,midpoint(arr));
|
||||||
|
p:=edge(b,fb);
|
||||||
|
arr := subpath (0,0.7) of p;
|
||||||
|
drawarrow arr;
|
||||||
|
label.rt(btex $F$ etex,midpoint(arr));
|
||||||
|
drawoptions(withcolor base1 dashed evenly);
|
||||||
|
drawEdgeAngle(fa,fb,"f",-35);
|
||||||
|
nodespace:=2u+1mm;
|
||||||
|
drawoptions(withcolor base1);
|
||||||
|
drawEdge(fa,fb,"\mathtt{fmap}\ f");
|
21
examples/cat-example1.mp
Normal file
21
examples/cat-example1.mp
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
z0=(0,0);
|
||||||
|
z1=2(u,0);
|
||||||
|
z2=2(2u,0);
|
||||||
|
|
||||||
|
nodesize:=4bp;
|
||||||
|
nodespace:=6bp;
|
||||||
|
|
||||||
|
drawarrow edge(z0,z1);
|
||||||
|
drawarrow edge(z1,z2);
|
||||||
|
drawarrow edgeAngle(z0,z2,35);
|
||||||
|
|
||||||
|
drawstate(z0);
|
||||||
|
drawstate(z1);
|
||||||
|
drawstate(z2);
|
||||||
|
|
||||||
|
nodesize:=6bp;
|
||||||
|
ahlength:=.3nodesize;
|
||||||
|
drawarrow edge(z0,z0);
|
||||||
|
drawarrow edge(z1,z1);
|
||||||
|
drawarrow edge(z2,z2);
|
||||||
|
|
13
examples/cat-example2.mp
Normal file
13
examples/cat-example2.mp
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
z0=(0,0); z1=3(u,0); z2=3(2u,0);
|
||||||
|
nodesize:=4bp;
|
||||||
|
nodespace:=6bp;
|
||||||
|
drawstate(z0); drawstate(z1); drawstate(z2);
|
||||||
|
|
||||||
|
drawEdge(z0,z1,"f");
|
||||||
|
drawEdge(z1,z2,"g");
|
||||||
|
|
||||||
|
nodesize:=6bp;
|
||||||
|
ahlength:=.3nodesize;
|
||||||
|
drawarrow edge(z0,z0);
|
||||||
|
drawarrow edge(z1,z1);
|
||||||
|
drawarrow edge(z2,z2);
|
17
examples/cat-example3.mp
Normal file
17
examples/cat-example3.mp
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
z0=(0,0); z1=(4u,0); z2=(2u,-3u);
|
||||||
|
nodesize:=4bp;
|
||||||
|
nodespace:=6bp;
|
||||||
|
|
||||||
|
drawarrow edgeAngle(z0,z1,35);
|
||||||
|
drawarrow edgeAngle(z1,z0,35);
|
||||||
|
drawarrow edgeAngle(z1,z2,35);
|
||||||
|
drawarrow edgeAngle(z0,z2,-35);
|
||||||
|
drawstate(z0);
|
||||||
|
drawstate(z1);
|
||||||
|
drawstate(z2);
|
||||||
|
|
||||||
|
nodesize:=6bp;
|
||||||
|
ahlength:=.3nodesize;
|
||||||
|
drawarrow edge(z0,z0);
|
||||||
|
drawarrow edge(z1,z1);
|
||||||
|
drawarrow edge(z2,z2);
|
12
examples/cat-example4.mp
Normal file
12
examples/cat-example4.mp
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
z0=(0,0); z1=(gu,0); z2=(.5gu,-.75gu);
|
||||||
|
drawState(z0,"A");
|
||||||
|
drawState(z1,"B");
|
||||||
|
drawState(z2,"C");
|
||||||
|
|
||||||
|
drawarrow edgeAngle(z0,z1,35);
|
||||||
|
drawarrow edgeAngle(z1,z0,35);
|
||||||
|
drawarrow edgeAngle(z1,z2,35);
|
||||||
|
drawarrow edgeAngle(z2,z0,35);
|
||||||
|
drawarrow edge(z0,z0);
|
||||||
|
drawarrow edge(z1,z1);
|
||||||
|
drawarrow edge(z2,z2);
|
10
examples/cat-example5.mp
Normal file
10
examples/cat-example5.mp
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
z0=origin;
|
||||||
|
z1=(gu,0);
|
||||||
|
|
||||||
|
drawState(z0,"A");
|
||||||
|
drawState(z1,"B");
|
||||||
|
drawEdgeAngle(z0,z1,"f",35);
|
||||||
|
drawEdge(z1,z0,"g");
|
||||||
|
drawEdgeAngle(z0,z1,"h",-35);
|
||||||
|
drawEdge(z0,z0,"id_A");
|
||||||
|
drawEdge(z1,z1,"id_B");
|
108
examples/cat-hask-endofunctor.mp
Normal file
108
examples/cat-hask-endofunctor.mp
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
% DPI 180
|
||||||
|
pair int,bool,func,intlist,list;
|
||||||
|
resize(.8cm);
|
||||||
|
int=origin;
|
||||||
|
% drawoptions (withcolor baseOne withpen pencircle scaled 1.2);
|
||||||
|
|
||||||
|
intlist=int shifted (gu,0);
|
||||||
|
func=int shifted (0,-.6gu);
|
||||||
|
bool=func shifted (gu,0);
|
||||||
|
list=func shifted (2u,0);
|
||||||
|
|
||||||
|
|
||||||
|
drawLoopPoint(int,int shifted (0,1.6u),"\mathtt{sqrt}");
|
||||||
|
drawEdge(int,int,"\mathtt{id}");
|
||||||
|
drawEdgeAngle(int,bool,"\mathtt{odd}",-30);
|
||||||
|
drawEdgeAngle(int,bool,"\mathtt{even}",30);
|
||||||
|
drawEdge(intlist,intlist,"\mathtt{tail}");
|
||||||
|
drawEdge(intlist,int,"\mathtt{length}");
|
||||||
|
|
||||||
|
% ---------- F ----------------
|
||||||
|
|
||||||
|
pair decal;
|
||||||
|
pair fint,fbool,ffunc,fintlist,flist;
|
||||||
|
decal := (-1.2gu,-1.5gu);
|
||||||
|
fint=int shifted decal;
|
||||||
|
fintlist=intlist shifted decal;
|
||||||
|
ffunc= func shifted decal;
|
||||||
|
fbool= bool shifted decal;
|
||||||
|
flist= list shifted decal;
|
||||||
|
|
||||||
|
drawLoopPoint(fint,fint shifted (0,1.9u),"\scriptstyle\mathtt{fmap\ sqrt}");
|
||||||
|
drawEdge(fint,fint,"\scriptstyle\mathtt{fmap\ id}");
|
||||||
|
drawEdgeAngle(fint,fbool,"\scriptstyle\mathtt{fmap\ odd}",-30);
|
||||||
|
drawEdgeAngle(fint,fbool,"\scriptstyle\mathtt{fmap\ even}",30);
|
||||||
|
drawEdge(fintlist,fintlist,"\scriptstyle\mathtt{fmap\ tail}");
|
||||||
|
drawEdge(fintlist,fint,"\scriptstyle\mathtt{fmap\ length}");
|
||||||
|
|
||||||
|
drawblock(fint,fbool,"\mathtt{F}");
|
||||||
|
|
||||||
|
pair ff;
|
||||||
|
ff = .5[fint,fintlist] shifted (0,u);
|
||||||
|
path b;
|
||||||
|
b := block(origin,origin);
|
||||||
|
draw b scaled .5 shifted ff;
|
||||||
|
label.top(btex $\mathtt{F\ F}$ etex, blockLabelPosition(b)) scaled .5 shifted ff;
|
||||||
|
draw b scaled .25 shifted ff;
|
||||||
|
label.top(btex $\mathtt{F\ F\ F}$ etex, blockLabelPosition(b)) scaled .25 shifted ff;
|
||||||
|
|
||||||
|
% ------------ G --------------
|
||||||
|
pair gdecal;
|
||||||
|
pair gint,gbool,gfunc,gintlist,glist;
|
||||||
|
gdecal := (1.2gu,-1.5gu);
|
||||||
|
gint=int shifted gdecal;
|
||||||
|
gintlist=intlist shifted gdecal;
|
||||||
|
gfunc= func shifted gdecal;
|
||||||
|
gbool= bool shifted gdecal;
|
||||||
|
glist= list shifted gdecal;
|
||||||
|
|
||||||
|
drawLoopPoint(gint,gint shifted (0,1.9u),"\scriptstyle\mathtt{fmap\ sqrt}");
|
||||||
|
drawEdge(gint,gint,"\scriptstyle\mathtt{fmap\ id}");
|
||||||
|
drawEdgeAngle(gint,gbool,"\scriptstyle\mathtt{fmap\ odd}",-30);
|
||||||
|
drawEdgeAngle(gint,gbool,"\scriptstyle\mathtt{fmap\ even}",30);
|
||||||
|
drawEdge(gintlist,gintlist,"\scriptstyle\mathtt{fmap\ tail}");
|
||||||
|
drawEdge(gintlist,gint,"\scriptstyle\mathtt{fmap\ length}");
|
||||||
|
|
||||||
|
drawblock(gint,gbool,"\mathtt{G}");
|
||||||
|
|
||||||
|
pair gf;
|
||||||
|
gf = .5[gint,gintlist] shifted (0,u);
|
||||||
|
path b;
|
||||||
|
b := block(origin,origin);
|
||||||
|
draw b scaled .5 shifted gf;
|
||||||
|
label.top(btex $\mathtt{G\ G}$ etex, blockLabelPosition(b)) scaled .5 shifted gf;
|
||||||
|
draw b scaled .25 shifted gf;
|
||||||
|
label.top(btex $\mathtt{G\ G\ G}$ etex, blockLabelPosition(b)) scaled .25 shifted gf;
|
||||||
|
|
||||||
|
|
||||||
|
drawState(int,"\mathtt{Int}");
|
||||||
|
drawState(intlist,"\mathtt{[Int]}");
|
||||||
|
drawState(func,"\mathtt{a\rightarrow b}");
|
||||||
|
drawState(list,"\mathtt{[a]}");
|
||||||
|
drawState(bool,"\mathtt{Bool}");
|
||||||
|
|
||||||
|
drawState(fint,"\mathtt{F\ Int}");
|
||||||
|
drawState(fintlist,"\mathtt{F\ [Int]}");
|
||||||
|
drawState(ffunc,"\mathtt{F\ a\rightarrow b}");
|
||||||
|
drawState(flist,"\mathtt{F\ [a]}");
|
||||||
|
drawState(fbool,"\mathtt{F\ Bool}");
|
||||||
|
|
||||||
|
drawState(gint,"\mathtt{G\ Int}");
|
||||||
|
drawState(gintlist,"\mathtt{G\ [Int]}");
|
||||||
|
drawState(gfunc,"\mathtt{G\ a\rightarrow b}");
|
||||||
|
drawState(glist,"\mathtt{G\ [a]}");
|
||||||
|
drawState(gbool,"\mathtt{G\ Bool}");
|
||||||
|
|
||||||
|
drawoptions(withcolor yellow);
|
||||||
|
label.top(btex $I$ etex, .5[int,intlist] shifted (0,u));
|
||||||
|
|
||||||
|
drawoptions(withpen pencircle scaled 2bp withcolor yellow);
|
||||||
|
ahlength:=.3u;
|
||||||
|
|
||||||
|
drawEdgeAngle(.5[int,func] shifted (-.5u,0), ff shifted (0,2.2u), "?", -30);
|
||||||
|
drawEdgeAngle(ff shifted (-u,2.2u), .5[int,func] shifted (-.5u,u), "?", 30);
|
||||||
|
drawEdgeAngle(.5[intlist,bool] shifted (.5u,0), gf shifted (0,2.2u), "?", 30);
|
||||||
|
drawEdgeAngle(gf shifted (u,2.2u), .5[intlist,bool] shifted (.5u,u), "?", -30);
|
||||||
|
|
||||||
|
drawEdgeAngle(.5[fintlist,fbool] shifted (1.1u,u), .5[gint,gfunc] shifted (-1.1u,u), "?", 30);
|
||||||
|
drawEdgeAngle(.5[gint,gfunc] shifted (-1.1u,u), .5[fintlist,fbool] shifted (1.1u,u), "?", 30);
|
24
examples/commutative-diagram-assoc.mp
Normal file
24
examples/commutative-diagram-assoc.mp
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
z0=(0,0);
|
||||||
|
z1=(gu,0);
|
||||||
|
z2=(0,-gu);
|
||||||
|
z3=(gu,-gu);
|
||||||
|
|
||||||
|
label("A",z0);
|
||||||
|
label("B",z1);
|
||||||
|
label("B",z2);
|
||||||
|
label("C",z3);
|
||||||
|
|
||||||
|
drawEdge(z0,z1,"f");
|
||||||
|
|
||||||
|
drawEdge(z1,z2,"g");
|
||||||
|
|
||||||
|
path ac,ab;
|
||||||
|
drawEdge(z2,z3,"h");
|
||||||
|
|
||||||
|
ac:=edge(z1,z3);
|
||||||
|
drawarrow ac;
|
||||||
|
label.rt(btex $h \circ g$ etex,midpoint(ac));
|
||||||
|
|
||||||
|
ab:=edge(z0,z2);
|
||||||
|
drawarrow ab;
|
||||||
|
label.lft(btex $g \circ f$ etex,midpoint(ab));
|
23
examples/commutative-diagram-id.mp
Normal file
23
examples/commutative-diagram-id.mp
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
z0=(0,0);
|
||||||
|
z1=(gu,0);
|
||||||
|
z2=(0,-gu);
|
||||||
|
z3=(gu,-gu);
|
||||||
|
path ac,ab;
|
||||||
|
|
||||||
|
label("A",z0);
|
||||||
|
label("A",z1);
|
||||||
|
label("B",z2);
|
||||||
|
label("B",z3);
|
||||||
|
|
||||||
|
drawEdge(z0,z1,"id_A");
|
||||||
|
drawEdge(z1,z2,"f");
|
||||||
|
ab:=edge(z0,z2);
|
||||||
|
drawarrow ab;
|
||||||
|
label.lft(btex $f$ etex,midpoint(ab));
|
||||||
|
|
||||||
|
drawEdge(z2,z3,"id_B");
|
||||||
|
|
||||||
|
ac:=edge(z1,z3);
|
||||||
|
drawarrow ac;
|
||||||
|
label.rt(btex $f$ etex,midpoint(ac));
|
||||||
|
|
27
examples/composition.mp
Normal file
27
examples/composition.mp
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
|
||||||
|
z0=(0,0);
|
||||||
|
z1=z0 shifted (gu,0);
|
||||||
|
|
||||||
|
z2=z0 shifted (2gu,0);
|
||||||
|
z3=z1 shifted (2gu,0);
|
||||||
|
|
||||||
|
z4=(0.5gu,-.5gu);
|
||||||
|
z5=(1.5gu,0);
|
||||||
|
z6=(2.5gu,-.5gu);
|
||||||
|
|
||||||
|
|
||||||
|
drawState(z4, "A");
|
||||||
|
drawState(z5, "B");
|
||||||
|
drawState(z6, "C");
|
||||||
|
|
||||||
|
|
||||||
|
drawoptions(withcolor red);
|
||||||
|
drawEdgeAngle(z4,z5, "f",30);
|
||||||
|
|
||||||
|
drawoptions(withcolor blue);
|
||||||
|
drawEdgeAngle(z5,z6, "g",30);
|
||||||
|
|
||||||
|
|
||||||
|
drawoptions(withcolor yellow);
|
||||||
|
drawEdgeAngle(z4,z6, "g\circ f", 0);
|
||||||
|
|
46
examples/endofunctor.mp
Normal file
46
examples/endofunctor.mp
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
z0=(0,0);
|
||||||
|
z1=(gu,0);
|
||||||
|
z2=(.5gu,-.75gu);
|
||||||
|
|
||||||
|
z3=z0 shifted (2gu,0);
|
||||||
|
z4=z1 shifted (2gu,0);
|
||||||
|
z5=z2 shifted (2gu,0);
|
||||||
|
|
||||||
|
drawblock(z0,(xpart z1,ypart z2),"\mathcal{C}");
|
||||||
|
drawblock(z3,(xpart z4,ypart z5),"\mathcal{C}");
|
||||||
|
|
||||||
|
drawoptions(withcolor yellow );
|
||||||
|
drawState(z0,"A");
|
||||||
|
drawState(z1,"B");
|
||||||
|
drawState(z4,"B");
|
||||||
|
|
||||||
|
drawoptions(withcolor red );
|
||||||
|
drawState(z2,"C");
|
||||||
|
drawState(z5,"C");
|
||||||
|
|
||||||
|
|
||||||
|
drawoptions(withcolor green );
|
||||||
|
drawEdge(z2,z2,"id_C");
|
||||||
|
|
||||||
|
|
||||||
|
drawoptions(withcolor magenta );
|
||||||
|
drawarrow edgeFull(z1,z2,-90,180);
|
||||||
|
drawarrow edgeFull(z0,z2,-90,0);
|
||||||
|
drawarrow edgeFull(z4,z5,-90,180);
|
||||||
|
|
||||||
|
drawoptions(withcolor blue );
|
||||||
|
drawEdge(z0,z0,"id_A");
|
||||||
|
drawEdge(z1,z1,"id_B");
|
||||||
|
drawEdge(z4,z4,"id_B");
|
||||||
|
drawarrow edgeAngle(z0,z1,35);
|
||||||
|
drawarrow edgeAngle(z1,z0,35);
|
||||||
|
|
||||||
|
drawoptions(withcolor green );
|
||||||
|
drawEdge(z5,z5,"id_C");
|
||||||
|
|
||||||
|
drawoptions(withcolor base01);
|
||||||
|
drawState(z3,"A");
|
||||||
|
drawEdge(z3,z3,"id_A");
|
||||||
|
drawarrow edgeAngle(z3,z4,35);
|
||||||
|
drawarrow edgeAngle(z4,z3,35);
|
||||||
|
drawarrow edgeFull(z3,z5,-90,0);
|
37
examples/functor-morphism-color.mp
Normal file
37
examples/functor-morphism-color.mp
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
z0=(0,0);
|
||||||
|
z1=(gu,0);
|
||||||
|
z2=(.5gu,-.75gu);
|
||||||
|
z3=z0 shifted (2gu,0);
|
||||||
|
z4=z3 shifted (0,-.75gu);
|
||||||
|
|
||||||
|
drawblock(z0,(xpart z1,ypart z2),"\mathcal{C}");
|
||||||
|
drawblock(z3,z4,"\mathcal{D}=\mathbf{F}(\mathcal{C})");
|
||||||
|
|
||||||
|
drawoptions(withcolor yellow );
|
||||||
|
drawState(z0,"A");
|
||||||
|
drawState(z1,"B");
|
||||||
|
drawState(z3,"X");
|
||||||
|
|
||||||
|
drawoptions(withcolor red );
|
||||||
|
drawState(z2,"C");
|
||||||
|
drawState(z4,"Y");
|
||||||
|
|
||||||
|
|
||||||
|
drawoptions(withcolor green );
|
||||||
|
drawEdge(z2,z2,"id_C");
|
||||||
|
|
||||||
|
|
||||||
|
drawoptions(withcolor magenta );
|
||||||
|
drawarrow edgeFull(z1,z2,-90,180);
|
||||||
|
drawarrow edgeFull(z0,z2,-90,0);
|
||||||
|
drawarrow edgeFull(z3,z4,-35,35+180);
|
||||||
|
|
||||||
|
drawoptions(withcolor blue );
|
||||||
|
drawEdge(z0,z0,"id_A");
|
||||||
|
drawEdge(z1,z1,"id_B");
|
||||||
|
drawarrow edgeAngle(z0,z1,35);
|
||||||
|
drawarrow edgeAngle(z1,z0,35);
|
||||||
|
drawEdge(z3,z3,"id_X");
|
||||||
|
|
||||||
|
drawoptions(withcolor green );
|
||||||
|
drawEdge(z4,z4,"id_Y");
|
87
examples/functor-morphism.mp
Normal file
87
examples/functor-morphism.mp
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
z0=(0,0);
|
||||||
|
z1=(gu,0);
|
||||||
|
z2=(.5gu,-.75gu);
|
||||||
|
z3=z0 shifted (2gu,0);
|
||||||
|
z4=z3 shifted (0,-.75gu);
|
||||||
|
|
||||||
|
drawblock(z0,(xpart z1,ypart z2),"\mathcal{C}");
|
||||||
|
drawblock(z3,z4,"\mathcal{D}=\mathbf{F}(\mathcal{C})");
|
||||||
|
|
||||||
|
drawState(z0,"A");
|
||||||
|
drawState(z1,"B");
|
||||||
|
drawState(z2,"C");
|
||||||
|
|
||||||
|
drawState(z4,"Y");
|
||||||
|
drawState(z3,"X");
|
||||||
|
|
||||||
|
|
||||||
|
drawoptions(withcolor green withpen pencircle scaled 1);
|
||||||
|
drawEdge(z2,z2,"id_C");
|
||||||
|
|
||||||
|
|
||||||
|
drawoptions(withcolor magenta withpen pencircle scaled 1);
|
||||||
|
drawarrow edgeFull(z1,z2,-90,180);
|
||||||
|
drawarrow edgeFull(z0,z2,-90,0);
|
||||||
|
drawarrow edgeFull(z3,z4,-35,35+180);
|
||||||
|
|
||||||
|
drawoptions(withcolor blue withpen pencircle scaled 1);
|
||||||
|
drawEdge(z0,z0,"id_A");
|
||||||
|
drawEdge(z1,z1,"id_B");
|
||||||
|
drawarrow edgeAngle(z0,z1,35);
|
||||||
|
drawarrow edgeAngle(z1,z0,35);
|
||||||
|
drawEdge(z3,z3,"id_X");
|
||||||
|
|
||||||
|
drawoptions(withcolor green withpen pencircle scaled 1);
|
||||||
|
drawEdge(z4,z4,"id_Y");
|
||||||
|
|
||||||
|
% drawarrow edgeAngle(z0,z3,45);
|
||||||
|
% drawarrow edge(z1,z3);
|
||||||
|
% drawarrow edge(z2,z4);
|
||||||
|
|
||||||
|
path la,lb,lc,lx,ly;
|
||||||
|
la := edge(z0,z0);
|
||||||
|
lb := edge(z1,z1);
|
||||||
|
lc := edge(z2,z2);
|
||||||
|
lx := edge(z3,z3);
|
||||||
|
ly := edge(z4,z4);
|
||||||
|
|
||||||
|
pair ia,ib,ic,ix,iy;
|
||||||
|
ia := midpoint( la );
|
||||||
|
ib := midpoint( lb );
|
||||||
|
ic := midpoint( lc );
|
||||||
|
ix := midpoint( lx );
|
||||||
|
iy := midpoint( ly );
|
||||||
|
|
||||||
|
nodesize:= .5u;
|
||||||
|
nodespace:= .5u;
|
||||||
|
drawoptions(withcolor blue dashed evenly withpen pencircle scaled 1);
|
||||||
|
|
||||||
|
drawarrow edgeAngle(ia,ix,35);
|
||||||
|
drawarrow edgeAngle(ib,ix,20);
|
||||||
|
|
||||||
|
drawoptions(withcolor green dashed evenly withpen pencircle scaled 1);
|
||||||
|
drawarrow edgeAngle(ic,iy,0);
|
||||||
|
|
||||||
|
path f,g,h,i;
|
||||||
|
f:= edgeAngle(z0,z1,35);
|
||||||
|
g:= edgeAngle(z1,z0,35);
|
||||||
|
h:= edgeFull(z1,z2,-90,180);
|
||||||
|
i:= edgeFull(z0,z2,-90,0);
|
||||||
|
|
||||||
|
path k;
|
||||||
|
k:= edgeFull(z3,z4,-35,35+180);
|
||||||
|
|
||||||
|
pair mf,mg,mh,mi,mk;
|
||||||
|
mf := midpoint(f);
|
||||||
|
mg := midpoint(g);
|
||||||
|
mh := midpoint(h);
|
||||||
|
mi := midpoint(i);
|
||||||
|
mk := midpoint(k);
|
||||||
|
|
||||||
|
|
||||||
|
drawoptions(withcolor blue dashed evenly withpen pencircle scaled 1);
|
||||||
|
drawarrow edgeAngle(mf,ix,40);
|
||||||
|
drawarrow edgeAngle(mg,ix,-15);
|
||||||
|
drawoptions(withcolor magenta dashed evenly withpen pencircle scaled 1);
|
||||||
|
drawarrow edgeAngle(mi,mk,30);
|
||||||
|
drawarrow edgeAngle(mh,mk,15);
|
34
examples/functor.mp
Normal file
34
examples/functor.mp
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
z0=(0,0);
|
||||||
|
z1=(gu,0);
|
||||||
|
z2=(.5gu,-.75gu);
|
||||||
|
z3=z0 shifted (2gu,0);
|
||||||
|
z4=z3 shifted (0,-.75gu);
|
||||||
|
|
||||||
|
drawblock(z0,(xpart z1,ypart z2),"\mathcal{C}");
|
||||||
|
drawblock(z3,z4,"\mathcal{D}=\mathbf{F}(\mathcal{C})");
|
||||||
|
|
||||||
|
drawEdge(z0,z0,"id_A");
|
||||||
|
drawEdge(z1,z1,"id_B");
|
||||||
|
drawEdge(z2,z2,"id_C");
|
||||||
|
drawarrow edgeAngle(z0,z1,35);
|
||||||
|
drawarrow edgeAngle(z1,z0,35);
|
||||||
|
drawarrow edgeFull(z1,z2,-90,180);
|
||||||
|
drawarrow edgeFull(z0,z2,-90,0);
|
||||||
|
|
||||||
|
drawEdge(z3,z3,"id_X");
|
||||||
|
drawEdge(z4,z4,"id_Y");
|
||||||
|
drawarrow edgeFull(z3,z4,-35,35+180);
|
||||||
|
|
||||||
|
drawoptions(withcolor yellow withpen pencircle scaled 1);
|
||||||
|
drawState(z0,"A");
|
||||||
|
drawState(z1,"B");
|
||||||
|
drawState(z3,"X");
|
||||||
|
drawoptions(withcolor yellow withpen pencircle scaled 1 dashed evenly);
|
||||||
|
drawarrow edgeAngle(z0,z3,45);
|
||||||
|
drawarrow edge(z1,z3);
|
||||||
|
|
||||||
|
drawoptions(withcolor red withpen pencircle scaled 1);
|
||||||
|
drawState(z2,"C");
|
||||||
|
drawState(z4,"Y");
|
||||||
|
drawoptions(withcolor red withpen pencircle scaled 1 dashed evenly);
|
||||||
|
drawarrow edge(z2,z4);
|
11
examples/graph-category.mp
Normal file
11
examples/graph-category.mp
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
pair a,b,c;
|
||||||
|
a=origin;
|
||||||
|
b=a shifted (gu,0);
|
||||||
|
c=a shifted (gu,0) rotated -60;
|
||||||
|
|
||||||
|
drawState(a,"X");
|
||||||
|
drawState(b,"Y");
|
||||||
|
drawState(c,"Z");
|
||||||
|
drawEdgeAngle(a,b,"\alpha",30);
|
||||||
|
drawEdgeAngle(b,c,"\beta",30);
|
||||||
|
drawEdgeAngle(c,a,"\gamma",30);
|
103
examples/hask-endofunctor-morphisms.mp
Normal file
103
examples/hask-endofunctor-morphisms.mp
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
pair int,bool,func,intlist,list;
|
||||||
|
resize(.8cm);
|
||||||
|
int=origin;
|
||||||
|
% drawoptions (withcolor baseOne withpen pencircle scaled 1.2);
|
||||||
|
|
||||||
|
intlist=int shifted (gu,0);
|
||||||
|
func=int shifted (0,-.6gu);
|
||||||
|
bool=func shifted (gu,0);
|
||||||
|
list=func shifted (2u,0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
pair decal;
|
||||||
|
pair fint,fbool,ffunc,fintlist,flist;
|
||||||
|
decal := (1.7gu,0);
|
||||||
|
fint=int shifted decal;
|
||||||
|
fintlist=intlist shifted decal;
|
||||||
|
ffunc= func shifted decal;
|
||||||
|
fbool= bool shifted decal;
|
||||||
|
flist= list shifted decal;
|
||||||
|
|
||||||
|
drawoptions(withcolor yellow withpen pencircle scaled 1);
|
||||||
|
drawLoopPoint(int,int shifted (0,1.6u),"\mathtt{sqrt}");
|
||||||
|
drawLoopPoint(fint,fint shifted (0,1.9u),"\scriptstyle\mathtt{fmap\ sqrt}");
|
||||||
|
|
||||||
|
drawoptions(withcolor green withpen pencircle scaled 1);
|
||||||
|
drawEdge(int,int,"\mathtt{id}");
|
||||||
|
drawEdge(fint,fint,"\scriptstyle\mathtt{fmap\ id}");
|
||||||
|
|
||||||
|
drawoptions(withcolor red withpen pencircle scaled 1);
|
||||||
|
drawEdgeAngle(int,bool,"\mathtt{odd}",-30);
|
||||||
|
drawEdgeAngle(fint,fbool,"\scriptstyle\mathtt{fmap\ odd}",-30);
|
||||||
|
|
||||||
|
drawoptions(withcolor magenta withpen pencircle scaled 1);
|
||||||
|
drawEdgeAngle(int,bool,"\mathtt{even}",30);
|
||||||
|
drawEdgeAngle(fint,fbool,"\scriptstyle\mathtt{fmap\ even}",30);
|
||||||
|
|
||||||
|
drawoptions(withcolor violet withpen pencircle scaled 1);
|
||||||
|
drawEdge(intlist,intlist,"\mathtt{tail}");
|
||||||
|
drawEdge(fintlist,fintlist,"\scriptstyle\mathtt{fmap\ tail}");
|
||||||
|
|
||||||
|
drawoptions(withcolor blue withpen pencircle scaled 1);
|
||||||
|
drawEdge(intlist,int,"\mathtt{length}");
|
||||||
|
drawEdge(fintlist,fint,"\scriptstyle\mathtt{fmap\ length}");
|
||||||
|
|
||||||
|
drawoptions(withcolor base1);
|
||||||
|
drawState(int,"\mathtt{Int}");
|
||||||
|
drawState(fint,"\mathtt{F\ Int}");
|
||||||
|
drawState(intlist,"\mathtt{[Int]}");
|
||||||
|
drawState(fintlist,"\mathtt{F\ [Int]}");
|
||||||
|
drawState(func,"\mathtt{a\rightarrow b}");
|
||||||
|
drawState(ffunc,"\mathtt{F\ a\rightarrow b}");
|
||||||
|
drawState(list,"\mathtt{[a]}");
|
||||||
|
drawState(flist,"\mathtt{F\ [a]}");
|
||||||
|
drawState(bool,"\mathtt{Bool}");
|
||||||
|
drawState(fbool,"\mathtt{F\ Bool}");
|
||||||
|
|
||||||
|
drawblock(fint,fbool,"\mathtt{F}");
|
||||||
|
|
||||||
|
% Draw blocks
|
||||||
|
pair ff;
|
||||||
|
ff = .5[fint,fintlist] shifted (0,u);
|
||||||
|
path b;
|
||||||
|
b := block(origin,origin);
|
||||||
|
draw b scaled .5 shifted ff;
|
||||||
|
label.top(btex $\mathtt{F\ F}$ etex, blockLabelPosition(b)) scaled .5 shifted ff;
|
||||||
|
draw b scaled .25 shifted ff;
|
||||||
|
label.top(btex $\mathtt{F\ F\ F}$ etex, blockLabelPosition(b)) scaled .25 shifted ff;
|
||||||
|
|
||||||
|
pair psqrt,pid,plength,podd,peven,ptail;
|
||||||
|
pair pfsqrt,pfid,pflength,pfodd,pfeven,pftail;
|
||||||
|
|
||||||
|
psqrt := midpoint(loopPoint(int,int shifted (0,1.6u)));
|
||||||
|
pid := midpoint(edge(int,int));
|
||||||
|
podd := midpoint(edgeAngle(int,bool,-30));
|
||||||
|
peven := midpoint(edgeAngle(int,bool,30));
|
||||||
|
ptail := midpoint(edge(intlist,intlist));
|
||||||
|
plength := midpoint(edge(intlist,int));
|
||||||
|
pfsqrt := midpoint(loopPoint(fint,fint shifted (0,1.9u)));
|
||||||
|
pfid := midpoint(edge(fint,fint));
|
||||||
|
pfodd := midpoint(edgeAngle(fint,fbool,-30));
|
||||||
|
pfeven := midpoint(edgeAngle(fint,fbool,30));
|
||||||
|
pftail := midpoint(edge(fintlist,fintlist));
|
||||||
|
pflength := midpoint(edge(fintlist,fint));
|
||||||
|
|
||||||
|
nodespace := 6bp;
|
||||||
|
drawoptions(withcolor yellow withpen pencircle scaled 1);
|
||||||
|
drawarrow edgeAngle(psqrt,pfsqrt,20) dashed evenly;
|
||||||
|
|
||||||
|
drawoptions(withcolor green withpen pencircle scaled 1);
|
||||||
|
drawarrow edgeAngle(pid,pfid,20) dashed evenly;
|
||||||
|
|
||||||
|
drawoptions(withcolor blue withpen pencircle scaled 1);
|
||||||
|
drawarrow edgeAngle(plength,pflength,-20) dashed evenly;
|
||||||
|
|
||||||
|
drawoptions(withcolor red withpen pencircle scaled 1);
|
||||||
|
drawarrow edgeAngle(podd,pfodd,0) dashed evenly;
|
||||||
|
|
||||||
|
drawoptions(withcolor magenta withpen pencircle scaled 1);
|
||||||
|
drawarrow edgeAngle(peven,pfeven,-20) dashed evenly;
|
||||||
|
|
||||||
|
drawoptions(withcolor violet withpen pencircle scaled 1);
|
||||||
|
drawarrow edgeAngle(ptail,pftail,-5) dashed evenly;
|
70
examples/hask-endofunctor-objects.mp
Normal file
70
examples/hask-endofunctor-objects.mp
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
pair int,bool,func,intlist,list;
|
||||||
|
resize(.8cm);
|
||||||
|
int=origin;
|
||||||
|
% drawoptions (withcolor baseOne withpen pencircle scaled 1.2);
|
||||||
|
|
||||||
|
intlist=int shifted (gu,0);
|
||||||
|
func=int shifted (0,-.6gu);
|
||||||
|
bool=func shifted (gu,0);
|
||||||
|
list=func shifted (2u,0);
|
||||||
|
|
||||||
|
|
||||||
|
drawLoopPoint(int,int shifted (0,1.6u),"\mathtt{sqrt}");
|
||||||
|
drawEdge(int,int,"\mathtt{id}");
|
||||||
|
drawEdgeAngle(int,bool,"\mathtt{odd}",-30);
|
||||||
|
drawEdgeAngle(int,bool,"\mathtt{even}",30);
|
||||||
|
drawEdge(intlist,intlist,"\mathtt{tail}");
|
||||||
|
drawEdge(intlist,int,"\mathtt{length}");
|
||||||
|
|
||||||
|
pair decal;
|
||||||
|
pair fint,fbool,ffunc,fintlist,flist;
|
||||||
|
decal := (1.7gu,0);
|
||||||
|
fint=int shifted decal;
|
||||||
|
fintlist=intlist shifted decal;
|
||||||
|
ffunc= func shifted decal;
|
||||||
|
fbool= bool shifted decal;
|
||||||
|
flist= list shifted decal;
|
||||||
|
|
||||||
|
drawLoopPoint(fint,fint shifted (0,1.9u),"\scriptstyle\mathtt{fmap\ sqrt}");
|
||||||
|
drawEdge(fint,fint,"\scriptstyle\mathtt{fmap\ id}");
|
||||||
|
drawEdgeAngle(fint,fbool,"\scriptstyle\mathtt{fmap\ odd}",-30);
|
||||||
|
drawEdgeAngle(fint,fbool,"\scriptstyle\mathtt{fmap\ even}",30);
|
||||||
|
drawEdge(fintlist,fintlist,"\scriptstyle\mathtt{fmap\ tail}");
|
||||||
|
drawEdge(fintlist,fint,"\scriptstyle\mathtt{fmap\ length}");
|
||||||
|
|
||||||
|
|
||||||
|
drawblock(fint,fbool,"\mathtt{F}");
|
||||||
|
|
||||||
|
pair ff;
|
||||||
|
ff = .5[fint,fintlist] shifted (0,u);
|
||||||
|
path b;
|
||||||
|
b := block(origin,origin);
|
||||||
|
draw b scaled .5 shifted ff;
|
||||||
|
label.top(btex $\mathtt{F\ F}$ etex, blockLabelPosition(b)) scaled .5 shifted ff;
|
||||||
|
draw b scaled .25 shifted ff;
|
||||||
|
label.top(btex $\mathtt{F\ F\ F}$ etex, blockLabelPosition(b)) scaled .25 shifted ff;
|
||||||
|
|
||||||
|
drawoptions(withcolor yellow withpen pencircle scaled 1);
|
||||||
|
drawarrow edgeAngle(int,fint,45) dashed evenly;
|
||||||
|
drawState(int,"\mathtt{Int}");
|
||||||
|
drawState(fint,"\mathtt{F\ Int}");
|
||||||
|
|
||||||
|
drawoptions(withcolor green withpen pencircle scaled 1);
|
||||||
|
drawarrow edgeAngle(intlist,fintlist,-20) dashed evenly;
|
||||||
|
drawState(intlist,"\mathtt{[Int]}");
|
||||||
|
drawState(fintlist,"\mathtt{F\ [Int]}");
|
||||||
|
|
||||||
|
drawoptions(withcolor blue withpen pencircle scaled 1);
|
||||||
|
drawarrow edgeAngle(func,ffunc,-20) dashed evenly;
|
||||||
|
drawState(func,"\mathtt{a\rightarrow b}");
|
||||||
|
drawState(ffunc,"\mathtt{F\ a\rightarrow b}");
|
||||||
|
|
||||||
|
drawoptions(withcolor red withpen pencircle scaled 1);
|
||||||
|
drawarrow edgeAngle(list,flist,25) dashed evenly;
|
||||||
|
drawState(list,"\mathtt{[a]}");
|
||||||
|
drawState(flist,"\mathtt{F\ [a]}");
|
||||||
|
|
||||||
|
drawoptions(withcolor magenta withpen pencircle scaled 1);
|
||||||
|
drawarrow edgeAngle(bool,fbool,-20) dashed evenly;
|
||||||
|
drawState(bool,"\mathtt{Bool}");
|
||||||
|
drawState(fbool,"\mathtt{F\ Bool}");
|
56
examples/hask-endofunctor.mp
Normal file
56
examples/hask-endofunctor.mp
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
pair int,bool,func,intlist,list;
|
||||||
|
resize(.8cm);
|
||||||
|
int=origin;
|
||||||
|
% drawoptions (withcolor baseOne withpen pencircle scaled 1.2);
|
||||||
|
|
||||||
|
intlist=int shifted (gu,0);
|
||||||
|
func=int shifted (0,-.6gu);
|
||||||
|
bool=func shifted (gu,0);
|
||||||
|
list=func shifted (2u,0);
|
||||||
|
|
||||||
|
|
||||||
|
drawLoopPoint(int,int shifted (0,1.6u),"\mathtt{sqrt}");
|
||||||
|
drawEdge(int,int,"\mathtt{id}");
|
||||||
|
drawEdgeAngle(int,bool,"\mathtt{odd}",-30);
|
||||||
|
drawEdgeAngle(int,bool,"\mathtt{even}",30);
|
||||||
|
drawEdge(intlist,intlist,"\mathtt{tail}");
|
||||||
|
drawEdge(intlist,int,"\mathtt{length}");
|
||||||
|
|
||||||
|
pair decal;
|
||||||
|
pair fint,fbool,ffunc,fintlist,flist;
|
||||||
|
decal := (1.7gu,0);
|
||||||
|
fint=int shifted decal;
|
||||||
|
fintlist=intlist shifted decal;
|
||||||
|
ffunc= func shifted decal;
|
||||||
|
fbool= bool shifted decal;
|
||||||
|
flist= list shifted decal;
|
||||||
|
|
||||||
|
|
||||||
|
drawLoopPoint(fint,fint shifted (0,1.9u),"\scriptstyle\mathtt{fmap\ sqrt}");
|
||||||
|
drawEdge(fint,fint,"\scriptstyle\mathtt{fmap\ id}");
|
||||||
|
drawEdgeAngle(fint,fbool,"\scriptstyle\mathtt{fmap\ odd}",-30);
|
||||||
|
drawEdgeAngle(fint,fbool,"\scriptstyle\mathtt{fmap\ even}",30);
|
||||||
|
drawEdge(fintlist,fintlist,"\scriptstyle\mathtt{fmap\ tail}");
|
||||||
|
drawEdge(fintlist,fint,"\scriptstyle\mathtt{fmap\ length}");
|
||||||
|
|
||||||
|
drawblock(fint,fbool,"\mathtt{F}");
|
||||||
|
|
||||||
|
pair ff;
|
||||||
|
ff = .5[fint,fintlist] shifted (0,u);
|
||||||
|
path b;
|
||||||
|
b := block(origin,origin);
|
||||||
|
draw b scaled .5 shifted ff;
|
||||||
|
label.top(btex $\mathtt{F\ F}$ etex, blockLabelPosition(b)) scaled .5 shifted ff;
|
||||||
|
draw b scaled .25 shifted ff;
|
||||||
|
label.top(btex $\mathtt{F\ F\ F}$ etex, blockLabelPosition(b)) scaled .25 shifted ff;
|
||||||
|
|
||||||
|
drawState(int,"\mathtt{Int}");
|
||||||
|
drawState(fint,"\mathtt{F\ Int}");
|
||||||
|
drawState(intlist,"\mathtt{[Int]}");
|
||||||
|
drawState(fintlist,"\mathtt{F\ [Int]}");
|
||||||
|
drawState(func,"\mathtt{a\rightarrow b}");
|
||||||
|
drawState(ffunc,"\mathtt{F\ a\rightarrow b}");
|
||||||
|
drawState(list,"\mathtt{[a]}");
|
||||||
|
drawState(flist,"\mathtt{F\ [a]}");
|
||||||
|
drawState(bool,"\mathtt{Bool}");
|
||||||
|
drawState(fbool,"\mathtt{F\ Bool}");
|
22
examples/hask.mp
Normal file
22
examples/hask.mp
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
pair int,bool,func,intlist,list;
|
||||||
|
resize(.8cm);
|
||||||
|
int=origin;
|
||||||
|
% drawoptions (withcolor baseOne withpen pencircle scaled 1.2);
|
||||||
|
|
||||||
|
intlist=int shifted (gu,0);
|
||||||
|
func=int shifted (0,-.6gu);
|
||||||
|
bool=func shifted (gu,0);
|
||||||
|
list=func shifted (2u,0);
|
||||||
|
|
||||||
|
drawState(int,"\mathtt{Int}");
|
||||||
|
drawState(bool,"\mathtt{Bool}");
|
||||||
|
drawState(func,"\mathtt{a\rightarrow b}");
|
||||||
|
drawState(intlist,"\mathtt{[Int]}");
|
||||||
|
drawState(list,"\mathtt{[a]}");
|
||||||
|
|
||||||
|
drawLoopPoint(int,int shifted (0,1.6u),"\mathtt{sqrt}");
|
||||||
|
drawEdge(int,int,"\mathtt{id}");
|
||||||
|
drawEdgeAngle(int,bool,"\mathtt{odd}",-30);
|
||||||
|
drawEdgeAngle(int,bool,"\mathtt{even}",30);
|
||||||
|
drawEdge(intlist,intlist,"\mathtt{tail}");
|
||||||
|
drawEdge(intlist,int,"\mathtt{length}");
|
11
examples/identity.mp
Normal file
11
examples/identity.mp
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
z0=(0,0);
|
||||||
|
z1=z0 shifted (2gu,0);
|
||||||
|
|
||||||
|
drawState(z0, "A");
|
||||||
|
drawState(z1, "B");
|
||||||
|
|
||||||
|
drawoptions(withcolor yellow);
|
||||||
|
drawEdge(z0,z1, "id_B\circ f = f = f \circ id_A");
|
||||||
|
drawEdge(z0,z0, "id_A");
|
||||||
|
drawEdge(z1,z1, "id_B");
|
8
examples/list-maybe-endofunctor-morphism.mp
Normal file
8
examples/list-maybe-endofunctor-morphism.mp
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
pair tree,list;
|
||||||
|
resize(.8cm);
|
||||||
|
|
||||||
|
list=origin;
|
||||||
|
tree=list shifted (gu,0);
|
||||||
|
drawState(list,"\mathtt{[]}");
|
||||||
|
drawState(tree,"\mathtt{Maybe}");
|
||||||
|
drawEdgeAngle(list,tree,"\mathtt{toMaybe}",30);
|
7
examples/list-tree-endofunctor-morphism.mp
Normal file
7
examples/list-tree-endofunctor-morphism.mp
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
pair tree,list;
|
||||||
|
resize(.8cm);
|
||||||
|
list=origin;
|
||||||
|
tree=list shifted (gu,0);
|
||||||
|
drawState(list,"\mathtt{[]}");
|
||||||
|
drawState(tree,"\mathtt{List}");
|
||||||
|
drawEdgeAngle(list,tree,"\mathtt{toList}",30);
|
9
examples/maybe-list-endofunctor-morphsm.mp
Normal file
9
examples/maybe-list-endofunctor-morphsm.mp
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
pair tree,list;
|
||||||
|
resize(.8cm);
|
||||||
|
list=origin;
|
||||||
|
|
||||||
|
tree=list shifted (gu,0);
|
||||||
|
drawState(list,"\mathtt{[]}");
|
||||||
|
drawState(tree,"\mathtt{Maybe}");
|
||||||
|
drawEdgeAngle(list,tree,"\mathtt{toMaybe}",30);
|
||||||
|
drawEdgeAngle(tree,list,"\mathtt{mToList}",30);
|
14
examples/monoid.mp
Normal file
14
examples/monoid.mp
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
pair A,B,C,D,E,F;
|
||||||
|
A:=(0,0); B:=(0,u); C:=(0,2u);
|
||||||
|
D:=(0,3u); E:=(0,4u); F:=(0,6u);
|
||||||
|
|
||||||
|
nodesize:=4bp;
|
||||||
|
nodespace:=6bp;
|
||||||
|
|
||||||
|
drawLoopPoint(A,B,"\varepsilon");
|
||||||
|
drawLoopPoint(A,C,"a");
|
||||||
|
drawLoopPoint(A,D,"b");
|
||||||
|
drawLoopPoint(A,E,"ab");
|
||||||
|
drawLoopPoint(A,F,"\omega");
|
||||||
|
draw (0,4.8u)--(0,5.8u) dashed withdots;
|
||||||
|
draw A withpen pencircle scaled 4bp;
|
46
examples/morphisms.mp
Normal file
46
examples/morphisms.mp
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
|
||||||
|
z0=(0,0);
|
||||||
|
z1=z0 shifted (gu,0);
|
||||||
|
z2=z1 shifted (gu,0);
|
||||||
|
z3=z2 shifted (gu,-0.5gu);
|
||||||
|
z4=z3 shifted (gu,0);
|
||||||
|
z5=z4 shifted (1.5u,0);
|
||||||
|
z6=z5 shifted (2u,0);
|
||||||
|
|
||||||
|
drawblock(z0,z6,"\mathcal{C}");
|
||||||
|
|
||||||
|
drawState(z0, "A");
|
||||||
|
drawState(z1, "B");
|
||||||
|
drawState(z2, "C");
|
||||||
|
|
||||||
|
drawState(z3, "D");
|
||||||
|
|
||||||
|
drawoptions(withcolor base01);
|
||||||
|
drawarrow loopPoint(z3,z3 shifted (0,3.8u)) dashed evenly;
|
||||||
|
drawarrow loopPoint(z3,z3 shifted (0,4u)) dashed evenly;
|
||||||
|
drawState(z4, "E");
|
||||||
|
drawEdge(z4,z4, "id_E");
|
||||||
|
drawarrow edgeAngle(z3,z4,0) dashed evenly;
|
||||||
|
drawarrow edgeAngle(z3,z4,20) dashed evenly;
|
||||||
|
drawarrow edgeAngle(z3,z4,-20) dashed evenly;
|
||||||
|
draw z5 -- z6 dashed withdots withpen pencircle scaled 2bp;
|
||||||
|
|
||||||
|
drawoptions(withcolor yellow);
|
||||||
|
drawarrow loopPoint(z3,z3 shifted (0,3.5u)) dashed evenly;
|
||||||
|
drawEdge(z3,z3, "id_D");
|
||||||
|
drawLoopPoint(z3,z3 shifted (0,2.5u),"\ell");
|
||||||
|
|
||||||
|
drawEdge(z0,z1, "f");
|
||||||
|
drawEdgeAngle(z0,z1, "f'", 45);
|
||||||
|
|
||||||
|
drawEdge(z0,z0, "id_A");
|
||||||
|
drawEdge(z1,z1, "id_B");
|
||||||
|
drawEdge(z2,z2, "id_C");
|
||||||
|
|
||||||
|
drawEdgeAngle(z1,z2, "g", 0);
|
||||||
|
drawEdgeAngle(z1,z2, "g'", 45);
|
||||||
|
|
||||||
|
drawEdgeAngle(z0,z2, "h", -30);
|
||||||
|
drawarrow edgeAngle(z0,z2,-45) dashed evenly;
|
||||||
|
drawarrow edgeAngle(z0,z2,-55) dashed evenly withcolor base01;
|
||||||
|
drawarrow edgeAngle(z0,z2,-60) dashed evenly withcolor base01;
|
20
examples/nattrans-list-maybe.mp
Normal file
20
examples/nattrans-list-maybe.mp
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
z0=(0,0);
|
||||||
|
z1=(1.5gu,0);
|
||||||
|
z2=(0,-gu);
|
||||||
|
z3=(1.5gu,-gu);
|
||||||
|
path ac,ab;
|
||||||
|
|
||||||
|
label(btex $\mathtt{[a]}$ etex,z0);
|
||||||
|
label(btex $\mathtt{[b]}$ etex,z1);
|
||||||
|
label(btex $\mathtt{Maybe\ a}$ etex,z2 shifted (-u,0));
|
||||||
|
label(btex $\mathtt{Maybe\ b}$ etex,z3 shifted (u,0));
|
||||||
|
|
||||||
|
drawEdge(z0,z1,"\mathtt{fmap_{[]}\ f}");
|
||||||
|
drawEdge(z2,z3,"\mathtt{fmap_{Maybe}\ f}");
|
||||||
|
ab:=edge(z0,z2);
|
||||||
|
drawarrow ab;
|
||||||
|
label.lft(btex $\mathtt{toMaybe}$ etex,midpoint(ab));
|
||||||
|
|
||||||
|
ac:=edge(z1,z3);
|
||||||
|
drawarrow ac;
|
||||||
|
label.rt(btex $\mathtt{toMaybe}$ etex,midpoint(ac));
|
21
examples/nattrans-list-tree.mp
Normal file
21
examples/nattrans-list-tree.mp
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
z0=(0,0);
|
||||||
|
z1=(1.5gu,0);
|
||||||
|
z2=(0,-gu);
|
||||||
|
z3=(1.5gu,-gu);
|
||||||
|
path ac,ab;
|
||||||
|
|
||||||
|
label(btex $\mathtt{[a]}$ etex,z0);
|
||||||
|
label(btex $\mathtt{[b]}$ etex,z1);
|
||||||
|
label(btex $\mathtt{List\ a}$ etex,z2 shifted (-u,0));
|
||||||
|
label(btex $\mathtt{List\ b}$ etex,z3 shifted (u,0));
|
||||||
|
|
||||||
|
drawEdge(z0,z1,"\mathtt{fmap_{[]}\ f}");
|
||||||
|
drawEdge(z2,z3,"\mathtt{fmap_{List}\ f}");
|
||||||
|
ab:=edge(z0,z2);
|
||||||
|
drawarrow ab;
|
||||||
|
label.lft(btex $\mathtt{toList}$ etex,midpoint(ab));
|
||||||
|
|
||||||
|
ac:=edge(z1,z3);
|
||||||
|
drawarrow ac;
|
||||||
|
label.rt(btex $\mathtt{toList}$ etex,midpoint(ac));
|
||||||
|
|
21
examples/nattrans-maybe-list.mp
Normal file
21
examples/nattrans-maybe-list.mp
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
z0=(0,0);
|
||||||
|
z1=(1.5gu,0);
|
||||||
|
z2=(0,-gu);
|
||||||
|
z3=(1.5gu,-gu);
|
||||||
|
path ac,ab;
|
||||||
|
|
||||||
|
label(btex $\mathtt{[a]}$ etex,z0);
|
||||||
|
label(btex $\mathtt{[b]}$ etex,z1);
|
||||||
|
label(btex $\mathtt{Maybe\ a}$ etex,z2 shifted (-u,0));
|
||||||
|
label(btex $\mathtt{Maybe\ b}$ etex,z3 shifted (u,0));
|
||||||
|
|
||||||
|
drawEdge(z0,z1,"\mathtt{fmap_{[]}\ f}");
|
||||||
|
drawEdge(z2,z3,"\mathtt{fmap_{Maybe}\ f}");
|
||||||
|
|
||||||
|
path abb,acb;
|
||||||
|
abb:=edge(z2 shifted (.2u,0),z0 shifted (.2u,0));
|
||||||
|
acb:=edge(z3 shifted (-.2u,0),z1 shifted (-.2u,0));
|
||||||
|
drawarrow abb;
|
||||||
|
drawarrow acb;
|
||||||
|
label.rt(btex $\mathtt{mToList}$ etex,midpoint(abb));
|
||||||
|
label.lft(btex $\mathtt{mToList}$ etex,midpoint(acb));
|
29
examples/nattrans-tree-list.mp
Normal file
29
examples/nattrans-tree-list.mp
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
z0=(0,0);
|
||||||
|
z1=(1.5gu,0);
|
||||||
|
z2=(0,-gu);
|
||||||
|
z3=(1.5gu,-gu);
|
||||||
|
path ac,ab;
|
||||||
|
|
||||||
|
label(btex $\mathtt{[a]}$ etex,z0);
|
||||||
|
label(btex $\mathtt{[b]}$ etex,z1);
|
||||||
|
label(btex $\mathtt{List\ a}$ etex,z2 shifted (-u,0));
|
||||||
|
label(btex $\mathtt{List\ b}$ etex,z3 shifted (u,0));
|
||||||
|
|
||||||
|
drawEdge(z0,z1,"\mathtt{fmap_{[]}\ f}");
|
||||||
|
drawEdge(z2,z3,"\mathtt{fmap_{List}\ f}");
|
||||||
|
ab:=edge(z0,z2);
|
||||||
|
drawarrow ab;
|
||||||
|
label.lft(btex $\mathtt{toList}$ etex,midpoint(ab));
|
||||||
|
|
||||||
|
ac:=edge(z1,z3);
|
||||||
|
drawarrow ac;
|
||||||
|
label.rt(btex $\mathtt{toList}$ etex,midpoint(ac));
|
||||||
|
|
||||||
|
drawoptions(withcolor yellow);
|
||||||
|
path abb,acb;
|
||||||
|
abb:=edge(z2 shifted (.2u,0),z0 shifted (.2u,0));
|
||||||
|
acb:=edge(z3 shifted (-.2u,0),z1 shifted (-.2u,0));
|
||||||
|
drawarrow abb;
|
||||||
|
drawarrow acb;
|
||||||
|
label.rt(btex $\mathtt{toHList}$ etex,midpoint(abb));
|
||||||
|
label.lft(btex $\mathtt{toHList}$ etex,midpoint(acb));
|
21
examples/natural-transformation.mp
Normal file
21
examples/natural-transformation.mp
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
z0=(0,0);
|
||||||
|
z1=(gu,0);
|
||||||
|
z2=(0,-gu);
|
||||||
|
z3=(gu,-gu);
|
||||||
|
path ac,ab;
|
||||||
|
|
||||||
|
label(btex $F X$ etex,z0);
|
||||||
|
label(btex $F Y$ etex,z1);
|
||||||
|
label(btex $G X$ etex,z2);
|
||||||
|
label(btex $G Y$ etex,z3);
|
||||||
|
|
||||||
|
drawEdge(z0,z1,"F f");
|
||||||
|
drawEdge(z2,z3,"G f");
|
||||||
|
ab:=edge(z0,z2);
|
||||||
|
drawarrow ab;
|
||||||
|
label.lft(btex $\eta_X$ etex,midpoint(ab));
|
||||||
|
|
||||||
|
ac:=edge(z1,z3);
|
||||||
|
drawarrow ac;
|
||||||
|
label.rt(btex $\eta_Y$ etex,midpoint(ac));
|
||||||
|
|
19
examples/numbers.mp
Normal file
19
examples/numbers.mp
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
z0=(0,0);
|
||||||
|
drawblock(z0,z0,"0");
|
||||||
|
|
||||||
|
z1=(gu,0);
|
||||||
|
|
||||||
|
drawblock(z1,z1,"1");
|
||||||
|
drawState(z1, "0");
|
||||||
|
drawEdge(z1,z1, "id_0");
|
||||||
|
|
||||||
|
z2=z1 shifted (gu,0);
|
||||||
|
z3=z2 shifted (gu,0);
|
||||||
|
|
||||||
|
drawblock(z2,z3,"2");
|
||||||
|
|
||||||
|
drawState(z2, "0");
|
||||||
|
drawState(z3, "1");
|
||||||
|
drawEdge(z2,z2, "id_0");
|
||||||
|
drawEdge(z3,z3, "id_1");
|
||||||
|
drawarrow edge(z2,z3);
|
19
examples/objects.mp
Normal file
19
examples/objects.mp
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
|
||||||
|
z0=(0,0);
|
||||||
|
z1=z0 shifted (gu,0);
|
||||||
|
z2=z1 shifted (gu,0);
|
||||||
|
z3=z2 shifted (gu,-0.5gu);
|
||||||
|
z4=z3 shifted (gu,0);
|
||||||
|
z5=z4 shifted (1.5u,0);
|
||||||
|
z6=z5 shifted (2u,0);
|
||||||
|
|
||||||
|
drawblock(z0,z6,"\mathcal{C}");
|
||||||
|
draw z5 -- z6 dashed withdots withpen pencircle scaled 2bp;
|
||||||
|
|
||||||
|
drawoptions(withcolor yellow);
|
||||||
|
drawState(z0, "A");
|
||||||
|
drawState(z1, "B");
|
||||||
|
drawState(z2, "C");
|
||||||
|
|
||||||
|
drawState(z3, "D");
|
||||||
|
drawState(z4, "E");
|
149
examples/pipe.mp
Normal file
149
examples/pipe.mp
Normal file
|
@ -0,0 +1,149 @@
|
||||||
|
|
||||||
|
vardef inmouthsize(expr pos,size) =
|
||||||
|
fullcircle xscaled 0.6 scaled size shifted pos
|
||||||
|
enddef;
|
||||||
|
vardef outmouthsize(expr pos,size) =
|
||||||
|
(subpath (0,4) of fullcircle rotated -90) xscaled 0.6 scaled size shifted pos
|
||||||
|
enddef;
|
||||||
|
vardef hiddenoutmouthsize(expr pos,size) =
|
||||||
|
(subpath (4,8) of fullcircle rotated -90) xscaled 0.6 scaled size shifted pos
|
||||||
|
enddef;
|
||||||
|
vardef inmouth(expr pos) =
|
||||||
|
inmouthsize(pos,2u)
|
||||||
|
enddef;
|
||||||
|
vardef outmouth(expr pos) =
|
||||||
|
outmouthsize(pos,2u)
|
||||||
|
enddef;
|
||||||
|
vardef hiddenoutmouth(expr pos) =
|
||||||
|
hiddenoutmouthsize(pos,2u)
|
||||||
|
enddef;
|
||||||
|
def drawoutmouth(expr pos) =
|
||||||
|
draw outmouth(pos);
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
def drawtube(expr pos) =
|
||||||
|
begingroup;
|
||||||
|
save midin,midout;
|
||||||
|
pair midin,midout;
|
||||||
|
midin := pos;
|
||||||
|
midout := pos shifted (gu,0);
|
||||||
|
drawoutmouth(midin);
|
||||||
|
drawoutmouth(midout);
|
||||||
|
|
||||||
|
save topin,topout,botin,botout;
|
||||||
|
pair topin,topout,botin,botout;
|
||||||
|
topin=pos shifted (0,u);
|
||||||
|
topout=topin shifted (gu,0);
|
||||||
|
botin=pos shifted (0,-u);
|
||||||
|
botout=botin shifted (gu,0);
|
||||||
|
draw topin -- topout;
|
||||||
|
draw botin -- botout;
|
||||||
|
endgroup;
|
||||||
|
enddef;
|
||||||
|
def drawtubelabel(expr pos,l) =
|
||||||
|
drawtube(pos);
|
||||||
|
label(l,pos shifted (.5gu,0));
|
||||||
|
enddef;
|
||||||
|
def drawtwotubes(expr posintop,posinbot,posout) =
|
||||||
|
begingroup;
|
||||||
|
draw outmouth(posintop);
|
||||||
|
draw outmouth(posinbot);
|
||||||
|
draw outmouth(posout);
|
||||||
|
|
||||||
|
save intopt,intopb,inbott,inbotb,outt,outb;
|
||||||
|
pair intopt,intopb,inbott,inbotb,outt,outb;
|
||||||
|
intopt=posintop shifted (0,u);
|
||||||
|
intopb=posintop shifted (0,-u);
|
||||||
|
inbott=posinbot shifted (0,u);
|
||||||
|
inbotb=posinbot shifted (0,-u);
|
||||||
|
outt=posout shifted (0,u);
|
||||||
|
outb=posout shifted (0,-u);
|
||||||
|
|
||||||
|
draw intopt{right} .. {right}outt;
|
||||||
|
draw intopb{right} .. {left}inbott;
|
||||||
|
draw inbotb{right} .. {right}outb;
|
||||||
|
|
||||||
|
endgroup;
|
||||||
|
enddef;
|
||||||
|
def drawtwotubeslabel(expr ptop,pbot,pout,l) =
|
||||||
|
begingroup;
|
||||||
|
drawtwotubes(ptop,pbot,pout);
|
||||||
|
save mid;
|
||||||
|
pair mid;
|
||||||
|
mid = 6/30ptop+6/30pbot+18/30pout;
|
||||||
|
label(l,mid);
|
||||||
|
endgroup;
|
||||||
|
enddef;
|
||||||
|
def drawlongbegintube (expr pos,len) =
|
||||||
|
draw (subpath (4,8) of fullcircle rotated -90) scaled 2u shifted pos shifted (-len,0);
|
||||||
|
draw (pos shifted (-len,u)){right}..{right}(pos shifted (0,u));
|
||||||
|
draw (pos shifted (-len,-u)){right}..{right}(pos shifted (0,-u));
|
||||||
|
draw outmouth(pos);
|
||||||
|
enddef;
|
||||||
|
def drawbegintube (expr pos) =
|
||||||
|
drawlongbegintube(pos,2u);
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
def drawbegintubelabel(expr pos,l) =
|
||||||
|
drawbegintube(pos);
|
||||||
|
label(l,pos shifted (-1.5u,0));
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
def drawtube(expr pos) =
|
||||||
|
begingroup;
|
||||||
|
save midin,midout;
|
||||||
|
pair midin,midout;
|
||||||
|
midin := pos;
|
||||||
|
midout := pos shifted (gu,0);
|
||||||
|
draw outmouth(midin);
|
||||||
|
draw outmouth(midout);
|
||||||
|
|
||||||
|
save topin,topout,botin,botout;
|
||||||
|
pair topin,topout,botin,botout;
|
||||||
|
topin=pos shifted (0,u);
|
||||||
|
topout=topin shifted (gu,0);
|
||||||
|
botin=pos shifted (0,-u);
|
||||||
|
botout=botin shifted (gu,0);
|
||||||
|
draw topin -- topout;
|
||||||
|
draw botin -- botout;
|
||||||
|
endgroup;
|
||||||
|
enddef;
|
||||||
|
def drawtubelabel(expr pos,l) =
|
||||||
|
drawtube(pos);
|
||||||
|
label(l,pos shifted (.5gu,0));
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
pair pos;
|
||||||
|
pos:=origin;
|
||||||
|
z0=(2.5gu,.5gu);
|
||||||
|
z1=(0,-1.5gu);
|
||||||
|
z2=z1 shifted (3gu,0);
|
||||||
|
|
||||||
|
drawbegintubelabel(pos shifted (-.5gu,.5gu),btex $42$ etex);
|
||||||
|
drawbegintubelabel(pos shifted (-.5gu,-.5gu),btex $\mathtt{"foo"}$ etex);
|
||||||
|
drawtwotubeslabel(pos shifted (0,.5gu), pos shifted (0,-.5gu), pos shifted (gu,0),btex $+$ etex);
|
||||||
|
draw inmouth(pos shifted (0,.5gu) );
|
||||||
|
draw inmouth(pos shifted (0,-.5gu) );
|
||||||
|
|
||||||
|
drawbegintubelabel(z0 shifted (-2u,-gu),btex $\mathtt{"foo"}$ etex);
|
||||||
|
drawoptions(withcolor green);
|
||||||
|
drawbegintubelabel(z0,btex $42$ etex);
|
||||||
|
drawtwotubeslabel(z0, z0 shifted (0,-gu), z0 shifted (gu,-0.5gu),btex $+$ etex);
|
||||||
|
draw inmouth(z0 shifted (0,-gu));
|
||||||
|
|
||||||
|
|
||||||
|
drawoptions(withcolor green);
|
||||||
|
drawbegintubelabel(z1,btex $\mathtt{"foo"}$ etex);
|
||||||
|
drawtubelabel(z1,btex $\mathtt{(+\ 42)}$ etex)
|
||||||
|
|
||||||
|
drawoptions(withcolor red);
|
||||||
|
drawlongbegintube(z2,5u);
|
||||||
|
label(btex $\mathtt{(+\ 42\ "foo")}$ etex,z2 shifted (-3u,0));
|
||||||
|
draw z2 shifted (-4u,2u) -- z2 shifted (0,-2u) dashed evenly withpen pencircle scaled 1bp;
|
||||||
|
draw z2 shifted (-4u,-2u) -- z2 shifted (0,2u) dashed evenly withpen pencircle scaled 1bp;
|
||||||
|
|
||||||
|
drawoptions(withcolor base01);
|
||||||
|
drawarrow pos shifted (gu+2u,0) -- pos shifted (gu+4u,0);
|
||||||
|
drawarrow z0 shifted (-gu,-gu-u) .. z1 shifted (gu,2u);
|
||||||
|
drawarrow pos shifted (gu+u,-1.5gu) -- pos shifted (gu+3u,-1.5gu);
|
||||||
|
|
20
examples/preorder.mp
Normal file
20
examples/preorder.mp
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
pair A,B,C,D;
|
||||||
|
A=(0,0);
|
||||||
|
B=A shifted (-1.5gu,0);
|
||||||
|
C=A shifted (1.5gu,0);
|
||||||
|
D=C shifted (1.5gu,0);
|
||||||
|
|
||||||
|
drawState(A, "A");
|
||||||
|
drawState(B, "B");
|
||||||
|
drawState(C, "C");
|
||||||
|
drawState(D, "D");
|
||||||
|
|
||||||
|
drawEdge(B,A,"A \leq B");
|
||||||
|
drawEdge(C,A,"A \leq C");
|
||||||
|
drawEdge(D,C,"C \leq D");
|
||||||
|
drawEdgeAngle(D,A,"A \leq D", 35);
|
||||||
|
|
||||||
|
drawEdge(A,A,"A \leq A");
|
||||||
|
drawEdge(B,B,"B \leq B");
|
||||||
|
drawEdge(C,C,"C \leq C");
|
||||||
|
drawEdge(D,D,"D \leq D");
|
15
examples/set.mp
Normal file
15
examples/set.mp
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
pair A,B,C,D;
|
||||||
|
A=(0,0);
|
||||||
|
B=A shifted (.7gu,1/2gu);
|
||||||
|
C=A shifted (.7gu,-1/2gu);
|
||||||
|
D=C shifted (.7gu,0);
|
||||||
|
|
||||||
|
drawState(A, "A");
|
||||||
|
drawState(B, "B");
|
||||||
|
drawState(C, "C");
|
||||||
|
drawState(D, "D");
|
||||||
|
|
||||||
|
drawEdge(A,A,"id_A");
|
||||||
|
drawEdge(B,B,"id_B");
|
||||||
|
drawEdge(C,C,"id_C");
|
||||||
|
drawEdge(D,D,"id_D");
|
12
examples/strings.mp
Normal file
12
examples/strings.mp
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
pair A,B,C,D,E,F;
|
||||||
|
A:=(0,0); B:=(0,u); C:=(0,2u);
|
||||||
|
D:=(0,3u); E:=(0,4u); F:=(0,6u);
|
||||||
|
nodesize:=4bp;
|
||||||
|
nodespace:=6bp;
|
||||||
|
drawLoopPoint(A,B,"''");
|
||||||
|
drawLoopPoint(A,C,"a");
|
||||||
|
drawLoopPoint(A,D,"b");
|
||||||
|
drawLoopPoint(A,E,"ab");
|
||||||
|
drawLoopPoint(A,F,"\omega");
|
||||||
|
draw (0,4.8u)--(0,5.8u) dashed withdots;
|
||||||
|
draw A withpen pencircle scaled 4bp;
|
9
examples/tree-list-endofunctor-morphism.mp
Normal file
9
examples/tree-list-endofunctor-morphism.mp
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
pair tree,list;
|
||||||
|
resize(.8cm);
|
||||||
|
list=origin;
|
||||||
|
tree=list shifted (gu,0);
|
||||||
|
drawState(list,"\mathtt{[]}");
|
||||||
|
drawState(tree,"\mathtt{List}");
|
||||||
|
drawEdgeAngle(list,tree,"\mathtt{toList}",30);
|
||||||
|
drawoptions(withcolor yellow);
|
||||||
|
drawEdgeAngle(tree,list,"\mathtt{toHList}",30);
|
76
gen
Executable file
76
gen
Executable file
|
@ -0,0 +1,76 @@
|
||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
|
function err(){ print -- $@ >&2; exit 1 }
|
||||||
|
|
||||||
|
# scriptdir is the directory of the current executable
|
||||||
|
if [[ ${0[0]} = '/' ]]; then
|
||||||
|
scriptdir="${0:h}"
|
||||||
|
else
|
||||||
|
scriptdir="$PWD/${0:h}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# the tmp directory where compilation occurs with a lot of temporary files
|
||||||
|
tmpdir=/tmp/mp
|
||||||
|
[[ ! -d $tmpdir ]] && mkdir $tmpdir
|
||||||
|
|
||||||
|
# the list of mp files without argument all file in the current tree
|
||||||
|
typeset -a fics
|
||||||
|
if (($#<1)); then
|
||||||
|
fics=( $scriptdir/*.mp(N) )
|
||||||
|
else
|
||||||
|
for f in $@; fics=( $fics $scriptdir/$f )
|
||||||
|
fi
|
||||||
|
|
||||||
|
(( ${#fics} == 0 )) && err "No .mp files into $scriptdir"
|
||||||
|
|
||||||
|
(( ${#fics} == 1 )) && [[ ${fics[1]} = "$scriptdir/graph.mp" ]] && \
|
||||||
|
err "Only graph.mp files indo $scriptdir"
|
||||||
|
|
||||||
|
\cp -f $fics $tmpdir
|
||||||
|
cd $tmpdir
|
||||||
|
for fpfic in $fics; do
|
||||||
|
fic=${fpfic:t}
|
||||||
|
tmp=${fic:r}-tmp.mp
|
||||||
|
eps=${fic:r}-tmp.1
|
||||||
|
png=${fic:r}.png
|
||||||
|
old=${fic:r}.old
|
||||||
|
[[ $fic = "graph.mp" ]] && continue
|
||||||
|
{
|
||||||
|
echo -n >&2 "MPOST [$fic]"
|
||||||
|
cat $scriptdir/graph.mp
|
||||||
|
echo 'beginfig(1)'
|
||||||
|
echo ' drawoptions (withcolor base01);'
|
||||||
|
cat $fic
|
||||||
|
echo 'endfig;'
|
||||||
|
echo 'bye;'
|
||||||
|
} | sed 's/base00/baseZeroZero/g' \
|
||||||
|
| sed 's/base01/baseZeroOne/g' \
|
||||||
|
| sed 's/base02/baseZeroTwo/g' \
|
||||||
|
| sed 's/base03/baseZeroThree/g' \
|
||||||
|
| sed 's/base0/baseZero/g' \
|
||||||
|
| sed 's/base1/baseOne/g' \
|
||||||
|
| sed 's/base2/baseTwo/g' \
|
||||||
|
| sed 's/base3/baseThree/g' \
|
||||||
|
| sed 's/red/s_red/g' \
|
||||||
|
| sed 's/blue/s_blue/g' \
|
||||||
|
| sed 's/green/s_green/g' > $tmp
|
||||||
|
[[ -e $old ]] && diff $tmp $old >/dev/null && { echo " identical"; continue }
|
||||||
|
|
||||||
|
dpi=$(grep '% DPI' $tmp | awk '{print $3}')
|
||||||
|
[[ $dpi = "" ]] && dpi=600
|
||||||
|
|
||||||
|
print
|
||||||
|
print "[DPI]: $dpi"
|
||||||
|
|
||||||
|
# addshadow="'(' +clone -background black -shadow 90x4+0+1 ')' +swap -background none -layers merge +repage"
|
||||||
|
addshadow=""
|
||||||
|
reducesize=" -colors 254 -quality 75"
|
||||||
|
cmd="convert -colorspace rgb -density $((4*dpi)) $eps -resize 25% $addshadow $reducesize $png"
|
||||||
|
|
||||||
|
print -- "[$PWD]: mpost $tmp && convert -density $dpi $tmp.1 $png"
|
||||||
|
mpost --tex=latex $tmp && \
|
||||||
|
eval $cmd && \
|
||||||
|
\cp -f $png $scriptdir && \
|
||||||
|
\cp -f $tmp $old && \
|
||||||
|
echo "updated"
|
||||||
|
done
|
339
graph.mp
Normal file
339
graph.mp
Normal file
|
@ -0,0 +1,339 @@
|
||||||
|
% solarized color scheme
|
||||||
|
color baseZeroThree, baseZeroTwo, baseZeroOne, baseZeroZero
|
||||||
|
, baseZero, baseOne, baseTwo, baseThree, yellow, orange
|
||||||
|
, red, magenta, violet, blue, cyan, green;
|
||||||
|
baseZeroThree :=(0.0 ,0.168627450980392,0.211764705882353);
|
||||||
|
baseZeroTwo :=(0.0274509803921569,0.211764705882353,0.258823529411765);
|
||||||
|
baseZeroOne :=(0.345098039215686 ,0.431372549019608,0.458823529411765);
|
||||||
|
baseZeroZero :=(0.396078431372549 ,0.482352941176471,0.513725490196078);
|
||||||
|
baseZero :=(0.513725490196078 ,0.580392156862745,0.588235294117647);
|
||||||
|
baseOne :=(0.576470588235294 ,0.631372549019608,0.631372549019608);
|
||||||
|
baseTwo :=(0.933333333333333 ,0.909803921568627,0.835294117647059);
|
||||||
|
baseThree :=(0.992156862745098 ,0.964705882352941,0.890196078431372);
|
||||||
|
yellow :=(0.709803921568627 ,0.537254901960784,0.0);
|
||||||
|
orange :=(0.796078431372549 ,0.294117647058824,0.0862745098039216);
|
||||||
|
red :=(0.862745098039216 ,0.196078431372549,0.184313725490196);
|
||||||
|
magenta :=(0.827450980392157 ,0.211764705882353,0.509803921568627);
|
||||||
|
violet :=(0.423529411764706 ,0.443137254901961,0.768627450980392);
|
||||||
|
blue :=(0.149019607843137 ,0.545098039215686,0.823529411764706);
|
||||||
|
cyan :=(0.164705882352941 ,0.631372549019608,0.596078431372549);
|
||||||
|
green :=(0.52156862745098 ,0.6 ,0.0);
|
||||||
|
|
||||||
|
|
||||||
|
%%%%%%%%%%%%%%%%%%%%
|
||||||
|
% Automata drawing %
|
||||||
|
%%%%%%%%%%%%%%%%%%%%
|
||||||
|
u:=.5cm; % unity
|
||||||
|
gu:=5u; % distance between states
|
||||||
|
nodesize := u; %size of a node
|
||||||
|
nodespace := u+.1cm; %size of a node
|
||||||
|
|
||||||
|
def resize(expr nu)=
|
||||||
|
u:=nu;
|
||||||
|
gu:=5u; % distance between states
|
||||||
|
nodesize := u; %size of a node
|
||||||
|
nodespace := u+.1cm; %size of a node
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
% return the middle of a path
|
||||||
|
vardef midpoint(expr p)=
|
||||||
|
save r; pair r;
|
||||||
|
r:=point 1/2length(p) of p;
|
||||||
|
r
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
% shorten a path of length d at the beginning and the end
|
||||||
|
vardef shorten(expr p,d) =
|
||||||
|
save q,bcirc,ecirc;
|
||||||
|
path q,bcirc,ecirc;
|
||||||
|
bcirc := fullcircle scaled d shifted point 0 of p;
|
||||||
|
ecirc := fullcircle scaled d shifted point length(p) of p;
|
||||||
|
q := p cutbefore bcirc cutafter ecirc;
|
||||||
|
q
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
% Return a rounded box around top left and bottom right point.
|
||||||
|
vardef block(expr tl,br) =
|
||||||
|
save p;
|
||||||
|
save d,shift;
|
||||||
|
save topleft,bottomright;
|
||||||
|
save tll,tlt,trt,trr,brr,brb,blb,bll;
|
||||||
|
path p;
|
||||||
|
numeric d,shift;
|
||||||
|
d := 1/3u;
|
||||||
|
shift := 1.2u;
|
||||||
|
pair topleft,bottomright;
|
||||||
|
topleft := tl shifted (-shift,2shift);
|
||||||
|
bottomright := br shifted (shift,-.5shift);
|
||||||
|
pair tll,tlt,trt,trr,brr,brb,blb,bll;
|
||||||
|
tll := topleft shifted (-d,0);
|
||||||
|
tlt := topleft shifted (0,d);
|
||||||
|
trt := (xpart bottomright, ypart topleft) shifted (0,d);
|
||||||
|
trr := (xpart bottomright, ypart topleft) shifted (d,0);
|
||||||
|
brr := bottomright shifted (d,0);
|
||||||
|
brb := bottomright shifted (0,-d);
|
||||||
|
blb := (xpart topleft, ypart bottomright) shifted (0,-d);
|
||||||
|
bll := (xpart topleft, ypart bottomright) shifted (-d,0);
|
||||||
|
p:=tlt---trt..trr---brr..brb---blb..bll---tll..cycle;
|
||||||
|
p
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
% b being the path of the block
|
||||||
|
vardef blockLabelPosition(expr b)=
|
||||||
|
save pos;
|
||||||
|
pair pos;
|
||||||
|
pos := point 0.5 of b;
|
||||||
|
pos
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
% draw a block with the right math-mode tex label on top of it
|
||||||
|
def drawblock(expr topleftpoint, bottomrightpoint, l)=
|
||||||
|
save b,pos;
|
||||||
|
path b;
|
||||||
|
b:=block(topleftpoint,bottomrightpoint);
|
||||||
|
pair pos;
|
||||||
|
pos := blockLabelPosition(b);
|
||||||
|
draw b withcolor base01;
|
||||||
|
label.top(TEX("$"&l&"$"),pos);
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
% -- Generic private functions
|
||||||
|
|
||||||
|
% return the edge between points A and B.
|
||||||
|
% out angle from A is inan
|
||||||
|
% in angle to B is outan
|
||||||
|
% nodesize is the size of the node
|
||||||
|
vardef edgeFull(expr posA,posB,inan,outan) =
|
||||||
|
save sub,s;
|
||||||
|
path sub,s;
|
||||||
|
s := posA {dir inan} .. {dir outan} posB ;
|
||||||
|
sub := shorten(s,nodespace);
|
||||||
|
sub
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
% return a picture of the label l for edge e
|
||||||
|
vardef edgeLabel(expr e,l) =
|
||||||
|
save ret,mid,an,lab,height,width;
|
||||||
|
picture ret;
|
||||||
|
pair mid;
|
||||||
|
mid := midpoint(e);
|
||||||
|
numeric an;
|
||||||
|
an := angle (direction 1/2length(e) of e);
|
||||||
|
picture lab;
|
||||||
|
pair height,width;
|
||||||
|
lab:=thelabel(TEX("$"&l&"$"),origin);
|
||||||
|
height:=(0,ypart (ulcorner lab - llcorner lab));
|
||||||
|
width:=(xpart (urcorner lab - ulcorner lab),0);
|
||||||
|
if (an>-35) and (an<35):
|
||||||
|
ret:=lab shifted height rotated an shifted mid;
|
||||||
|
elseif (an>145) or (an<-145):
|
||||||
|
ret:=lab shifted height rotated (an+180) shifted mid;
|
||||||
|
elseif (an>75) and (an<120):
|
||||||
|
ret:=lab shifted mid shifted -width;
|
||||||
|
elseif (an>-120) and (an<-75):
|
||||||
|
ret:=lab shifted mid shifted width;
|
||||||
|
else:
|
||||||
|
ret:=lab shifted mid shifted height;
|
||||||
|
fi;
|
||||||
|
ret
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
% --- LABELED GRAPHS ---
|
||||||
|
% return the edge between points A and B.
|
||||||
|
% out angle from A is an + angle from A to B
|
||||||
|
vardef edgeAngle(expr posA,posB,an) =
|
||||||
|
save res,d;
|
||||||
|
path res;
|
||||||
|
numeric d;
|
||||||
|
d := angle(posB-posA);
|
||||||
|
res := edgeFull(posA,posB,d+an,d-an);
|
||||||
|
res
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
%% %%
|
||||||
|
%% LOOPS %%
|
||||||
|
%% %%
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
vardef dist(expr a,b)=
|
||||||
|
save width,height,res;
|
||||||
|
numeric width,height,res;
|
||||||
|
width:=xpart b - xpart a;
|
||||||
|
height:=ypart b - ypart a;
|
||||||
|
res:=sqrt(width*width + height*height);
|
||||||
|
enddef;
|
||||||
|
% return a loop
|
||||||
|
vardef loopFull(expr a,b,an) =
|
||||||
|
save ba,ea;
|
||||||
|
save circ,p,s;
|
||||||
|
pair ba,ea;
|
||||||
|
path circ,p,s;
|
||||||
|
p:=a{1,1}..b..{1,-1}cycle;
|
||||||
|
circ:= fullcircle scaled nodespace shifted a;
|
||||||
|
ba = circ intersectionpoint (subpath (0,1) of p);
|
||||||
|
ea = circ intersectionpoint (subpath (1,2) of p);
|
||||||
|
s:= ba{1,1}..b..{1,-1}ea;
|
||||||
|
s shifted -a rotated an shifted a
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
vardef loopPoint(expr a,b) =
|
||||||
|
loopFull(a,b,0)
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
vardef loopAngle(expr a,an) =
|
||||||
|
loopFull(a,a shifted (0,nodesize),an)
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
vardef loop(expr a) =
|
||||||
|
loopFull(a,a shifted (0,nodesize),0)
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
% return the direct edge between A and B
|
||||||
|
vardef edge(expr posA,posB) =
|
||||||
|
save an;
|
||||||
|
save sub;
|
||||||
|
numeric an;
|
||||||
|
path sub;
|
||||||
|
if (posA = posB):
|
||||||
|
sub := loop(posA);
|
||||||
|
else:
|
||||||
|
an := angle(posB-posA);
|
||||||
|
sub := edgeFull(posA,posB,an,an);
|
||||||
|
fi
|
||||||
|
sub
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
def drawLoopPoint(expr a,b,l) =
|
||||||
|
begingroup;
|
||||||
|
save s;
|
||||||
|
path s;
|
||||||
|
s:=loopPoint(a,b);
|
||||||
|
drawarrow s;
|
||||||
|
label.top(TEX("$"&l&"$"),midpoint(s));
|
||||||
|
endgroup;
|
||||||
|
enddef;
|
||||||
|
def drawLoop(expr a,l) =
|
||||||
|
begingroup;
|
||||||
|
save s;
|
||||||
|
path s;
|
||||||
|
s:=loop(a);
|
||||||
|
drawarrow s;
|
||||||
|
label.top(TEX("$"&l&"$"),midpoint(s));
|
||||||
|
endgroup;
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
def drawstate(expr pos) =
|
||||||
|
draw pos withpen pencircle scaled 4bp;
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
% draw some state with some label insize
|
||||||
|
def drawState(expr pos,l) =
|
||||||
|
begingroup;
|
||||||
|
save lab,reslab;
|
||||||
|
save height,width;
|
||||||
|
save size;
|
||||||
|
% Draw the circle
|
||||||
|
draw fullcircle scaled nodesize shifted pos;
|
||||||
|
|
||||||
|
% Draw the label with the right size
|
||||||
|
picture lab,reslab;
|
||||||
|
numeric height,width;
|
||||||
|
numeric size;
|
||||||
|
lab=thelabel(TEX("$"&l&"$"),origin);
|
||||||
|
height:=ypart (ulcorner lab - llcorner lab);
|
||||||
|
width :=xpart (urcorner lab - ulcorner lab);
|
||||||
|
size := sqrt(height*height + width*width);
|
||||||
|
if size>.9nodesize:
|
||||||
|
reslab:=lab scaled (.9nodesize/size) shifted pos;
|
||||||
|
else:
|
||||||
|
reslab:=lab shifted pos;
|
||||||
|
fi
|
||||||
|
% help for debug to draw boundaries
|
||||||
|
% draw ulcorner reslab -- urcorner reslab -- lrcorner reslab -- llcorner reslab -- cycle;
|
||||||
|
draw reslab;
|
||||||
|
endgroup;
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
% draw an edge
|
||||||
|
def drawEdgeFull(expr posA,posB,l,inan,outan) =
|
||||||
|
begingroup;
|
||||||
|
save sub;
|
||||||
|
path sub;
|
||||||
|
sub := edgeFull(posA,posB,inan,outan);
|
||||||
|
drawarrow sub;
|
||||||
|
draw edgeLabel(sub,l);
|
||||||
|
endgroup;
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
def drawEdgeAngle(expr posA,posB,l,inan) =
|
||||||
|
begingroup;
|
||||||
|
save sub;
|
||||||
|
path sub;
|
||||||
|
sub := edgeAngle(posA,posB,inan);
|
||||||
|
drawarrow sub;
|
||||||
|
draw edgeLabel(sub,l);
|
||||||
|
endgroup;
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
def drawEdge(expr posA,posB,l) =
|
||||||
|
begingroup;
|
||||||
|
save sub;
|
||||||
|
path sub;
|
||||||
|
sub := edge(posA,posB);
|
||||||
|
drawarrow sub;
|
||||||
|
draw edgeLabel(sub,l);
|
||||||
|
endgroup;
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
vardef box(expr posA) =
|
||||||
|
save b,size;
|
||||||
|
path b;
|
||||||
|
numeric size;
|
||||||
|
size:=2nodesize;
|
||||||
|
b := unitsquare scaled size shifted posA shifted (-.5size,-.5size);
|
||||||
|
b
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
def drawbox(expr posA,l) =
|
||||||
|
begingroup;
|
||||||
|
save b,pos;
|
||||||
|
path b;
|
||||||
|
pair pos;
|
||||||
|
b:=box(posA);
|
||||||
|
draw b;
|
||||||
|
pos=point 3 of b;
|
||||||
|
label.lrt(TEX("$"&l&"$"),pos);
|
||||||
|
endgroup;
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
prologues:=3;
|
||||||
|
|
||||||
|
verbatimtex
|
||||||
|
%&latex
|
||||||
|
\documentclass{minimal}
|
||||||
|
\begin{document}
|
||||||
|
etex
|
||||||
|
|
||||||
|
% TEX macro is short enough to be copied
|
||||||
|
string preverbatimtex_, postverbatimtex_;
|
||||||
|
|
||||||
|
vardef TEXPRE text s = preverbatimtex_ := s; enddef;
|
||||||
|
|
||||||
|
vardef TEXPOST text s = postverbatimtex_ := s; enddef;
|
||||||
|
|
||||||
|
vardef TEX primary s =
|
||||||
|
if known preverbatimtex_:
|
||||||
|
write "verbatimtex "&preverbatimtex_&" etex" to "mptextmp.mp";
|
||||||
|
fi
|
||||||
|
write "btex "&s&" etex" to "mptextmp.mp";
|
||||||
|
if known postverbatimtex_:
|
||||||
|
write "verbatimtex "&postverbatimtex_&" etex" to "mptextmp.mp";
|
||||||
|
fi
|
||||||
|
write EOF to "mptextmp.mp";
|
||||||
|
scantokens "input mptextmp"
|
||||||
|
enddef;
|
||||||
|
|
||||||
|
TEXPRE("\documentclass{minimal}\begin{document}");
|
||||||
|
TEXPOST("\end{document}");
|
Loading…
Reference in a new issue