TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I searched a bit and didn't find something that relates to this.

Suppose I created a closed curve in Metapost with the command p:=z_1..z_2..z_3..cycle. Is it possible to color pieces of this curve using different colors? How can I define a subset of this curve?

I was thinking that maybe there is a parametric representation of p which would enable me to color with another color the part from z_1 to z_2 for example.

It would really help if I could do the above, because I want to attach other figures to the colored portions of the curve.

Thank you.

share|improve this question
up vote 3 down vote accepted

There are many ways to specify parts of a path. One way is to use the cutbefore and cutafter statements as illustrated here:

    % define points
    z_0 := origin;
    z_1 := (0cm, .5cm);
    z_2 := (3cm, 1cm);
    z_3 := (5cm, 3.5cm);
    z_4 := (2cm, 3cm);
    z_5 := (1cm, 2cm);

    % define paths
    path p;
    p := z_1 .. z_2 .. z_3 .. z_4 .. z_5 .. cycle;
    path s;
    s := p cutbefore point 3 of p .. p cutafter point 1 of p;

    % draw lines
    draw p withpen pencircle scaled 8pt withcolor blue;
    draw s withpen pencircle scaled 4pt withcolor yellow;

    % draw the points and labels
    pickup pencircle scaled 8pt;
    for x=0 upto 4:
        draw point x of p;
        label.bot(decimal(x), point x of p);



For more information I would suggest reading the MetaFun manual. MetaFun is an extension to MetaPost. Anyhow, there are many examples included (see chapters one and two) that will also work with plain MetaPost.

share|improve this answer
Thank you very much. – Beni Bogosel Mar 12 '12 at 14:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.