I have a metapost diagram using colour that when displayed in normal latex (with a white background) works well. Now, I want to add the same diagram to a presentation done in Beamer (Warsaw theme) which has a blue background. The diagram does not look good at all — colour clash, too dark compared to the blue…
I have done this:
background:=white;
unfill (0,0)--(20u,0)--(20u,10u)--(0,10u)--cycle;
Which has the effect of drawing a white rectangle that then contains the diagram but it feel like a dirty hack.
How can I change the background of the diagram more elegantly?
Best Answer
Here's a receipe for drawing an image whose dimensions aren't known in advance on a background that scales to the image's final bounding box:
Here's an example followed by some random notes:
Saving an image in a picture variable can either be done by storing
currentpicture
in a picture variable or via theimage
command (see the MetaPost manual for more information). If thecurrentpicture
method is used, like in the example, make sure to clearcurrentpicture
before drawing the background. Otherwise the image is output twice, the first copy being hidden behind the background, bloating the output file.The
bbox
command returns a rectangular path corresponding to the bounding box of the picture argument plus a small amount determined by the internal variablebboxmargin
(2bp by default).Internal variables can be modified locally to the current group using the
interim
statement. That is, if you wrap an assignment to an internal variable inbegingroup ... endgroup;
the variable's value is restored after the group. Note,beginfig()
just starts a group that ends at the correspondingendfig
.