[metapost] Different colours in a label

Tommy Ekola tek at kth.se
Mon Nov 12 20:01:49 CET 2007


> I want to typeset a label like that :
>
> E=Q(i)
>
> where E is in blue and i is in red.

A not-so-elegant solution is to let metapost color the label. In the code
below I define a picture for each part of the label that should have the
same color (blocking other parts of the label with \phantom) and then draw
each part of the label using different colors.

beginfig(1);
  picture p, q, r;
  p := thelabel(btex $E\phantom{{}=Q(i)}$ etex, (0,0));
  q := thelabel(btex $\phantom{E}=Q(\phantom{i})$ etex, (0,0));
  r := thelabel(btex $\phantom{E=Q(}i\phantom{)}$ etex, (0,0));
  draw p withcolor blue;
  draw q withcolor black;
  draw r withcolor red;
endfig;

end.


-Tommy Ekola



More information about the metapost mailing list