Tuesday, August 11, 2009

Drawing Internal Diagrams

We introduced the internal diagram, but if one wants to draw such internal diagrams in LaTeX...well, LaTeX isn't known for its powerful drawing capabilities, so it seems like we are out of luck. Right? Wrong.

We can use other software (e.g. Metapost or Asymptote) to draw them. Metapost is old-school, based off of Knuth's Metafont...except Metapost produces .eps files. Asymptote is more "new-school", modeling itself off of C++. If one is new to all of this, asymptote may be easier to learn (it wasn't for me, I prefer metapost for 2d drawing). For example, in asymptote the following code generates the diagram:

pair midpoint(pair XXX, pair YYY)
{
 real a,b;
 a = (XXX.x + YYY.x)/2;
 b = (XXX.y + YYY.y)/2;
 return (a,b);
}
//real u = 14.1732284; // the number of "size points" in 0.5 centimeters 
dotfactor=8; // changes the size of a dot
real u = 14; // (u=72)==(u=1 inch);
pair z[]; // all the points we are working with
pair c1; // select points we are making red
pair c2;

///////////////////////////////////////////////////////////////////
// this draws one "factor" of $!$P$!$
///////////////////////////////////////////////////////////////////
dot((0*u,0*u));
dot((0*u,1*u));
dot((0*u,-1*u));
draw((-1*u,0*u)..(0*u,2*u)..(1*u,0*u)..(0*u,-2*u)..cycle);
label("$!$C_{1}$!$",(0*u,-2*u),S);
c1 = (0*u,0*u);

///////////////////////////////////////////////////////////////////
// this draws the other "factor" of $!$P$!$
///////////////////////////////////////////////////////////////////
dot((13*u,0*u));
dot((14*u,0*u));
c2 = (13*u,0*u);
draw((12*u,0)..(13.5*u,1*u)..(15*u,0)..(13.5*u,-1*u)..cycle);
label("$!$C_{2}$!$",(13.5*u,-1*u),S);

///////////////////////////////////////////////////////////////////
// this draws $!$P$!$
///////////////////////////////////////////////////////////////////
label("$!$P$!$",(7*u,0),S);

///////////////////////////////////////////////////////////////////
// this draws $!$D$!$
///////////////////////////////////////////////////////////////////
label("$!$\mathbf{1}$!$",(7*u,5*u),N);
// draws $!$\<f, g\>$!$
draw((7*u,5*u)--(7*u,0*u),linetype("8 8"),EndArrow);
label("$!$\langle f,g\rangle$!$",(7*u,2.5*u),E);

///////////////////////////////////////////////////////////////////
// draw the morphisms f and g
///////////////////////////////////////////////////////////////////
z[0] =(6.5*u,5.25*u);
z[1] = c1;
//z[1] = (0*u,2*u);
draw (z[0]--z[1], EndArrow);
label("$!$f$!$", midpoint(z[0],z[1]),NW);
z[2] = (7.5*u,5.25*u);
z[3] = c2;
//z[3] = (13.5*u,1*u);
draw (z[2]--z[3], EndArrow);
label("$!$g$!$", midpoint(z[2],z[3]),NE);

///////////////////////////////////////////////////////////////////
// draw projections
///////////////////////////////////////////////////////////////////
z[4] =(6.5*u,-0.5*u);
z[5] = c1;
//z[5] =(1*u,0);
draw (z[4]--z[5], EndArrow);
label("$!$\pi_{1}$!$", midpoint(z[4],z[5]),S);
z[6] =(7.5*u,-0.5*u);
z[7] = c2;
//z[7] =(12*u,0);
draw (z[6]--z[7], EndArrow);
label("$!$\pi_{2}$!$", midpoint(z[6],z[7]),S);

/////////////////////////////////////////////////////////////////////
// Redraw the red circles
/////////////////////////////////////////////////////////////////////
dot(c2,red);
dot(c1,red);

We can translate this into a png that we can use on our blog by running on the command line (in the Ubuntu distro of Linux at least) convert -density 150 img.eps -flatten img.png which converts the file img.eps to png, the "-flatten" option makes the background white as opposed to translucent, the "-density 150" makes the png image have certain geometry (otherwise our picture ends up too small). Once we've done this, we can use our png image on our blog...huzzah!

So why did I use Asymptote for this image? Because Metapost is kind of "fudgy" with its labels, it uses TeX to translate the labels when we are "compiling" the TeX code. We can force Metapost to use Postscript fonts by making the first line of our Metapost file: prologues:=1;. It usually isn't too good in comparison to Asymptote's output, which is why I use it for blogging purposes.

No comments:

Post a Comment