summaryrefslogtreecommitdiff
path: root/info/drawing-with-metapost/src/xypic-example.mp
blob: 074014c82c94591c5be6134097fe0a6a132f0d8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
\documentclass{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);

    picture U, XY, X, Y, Z;
    z1 = -z2 = (-61, 42);

    U  = thelabel("$U$", z1);
    XY = thelabel("$X\times_ZY$", origin);
    X  = thelabel("$X$", (x2, 0));
    Y  = thelabel("$Y$", (0, y2));
    Z =  thelabel("$Z$", z2);

    forsuffixes @=U, XY, X, Y, Z: draw @; endfor

    ahangle := 20;
    vardef connect@#(expr s, a, b) = 
        curved_connect@#(s, a, b, center b - center a)
    enddef;

    vardef curved_connect@#(expr s, a, b, d) = 
        save line, mark; 
        
        path line; 
        line = center a {d} .. center b;
        interim bboxmargin := 4;
        drawarrow line cutbefore bbox a cutafter bbox b;

        picture mark;
        mark = thelabel@#("$\scriptstyle " & s & "$", point 1/2 of line);
        interim bboxmargin := 1;
        unfill bbox mark; draw mark;
    enddef;

    connect.bot("p", XY, X);
    connect.rt ("q", XY, Y);
    connect.top("g", Y, Z);
    connect.lft("f", X, Z);

    curved_connect.urt("x", U, X, right);
    curved_connect.llft("y", U, Y, dir -80);

    drawoptions(dashed withdots scaled 1/2);
    connect("(x,y)", U, XY);
    drawoptions();


endfig;
\end{mplibcode}
\end{document}