# How to scale MetaPost drawings with consistent line width and label text size in ConTeXt?

I am using MetaPost to create some simple drawings in a ConTeXt document. In this example, I have a row of 14 boxes:

\startMPcode
draw (0,0)--(100,0)--(100,100)--(0,100)--(0,0);
draw (100,0)--(200,0)--(200,100)--(100,100)--(100,0);
draw (200,0)--(300,0)--(300,100)--(200,100)--(200,0);
draw (300,0)--(400,0)--(400,100)--(300,100)--(300,0);
draw (400,0)--(500,0)--(500,100)--(400,100)--(400,0);
draw (500,0)--(600,0)--(600,100)--(500,100)--(500,0);
draw (600,0)--(700,0)--(700,100)--(600,100)--(600,0);
draw (700,0)--(800,0)--(800,100)--(700,100)--(700,0);
draw (800,0)--(900,0)--(900,100)--(800,100)--(800,0);
draw (900,0)--(1000,0)--(1000,100)--(900,100)--(900,0);
draw (1000,0)--(1100,0)--(1100,100)--(1000,100)--(1000,0);
draw (1100,0)--(1200,0)--(1200,100)--(1100,100)--(1100,0);
draw (1200,0)--(1300,0)--(1300,100)--(1200,100)--(1200,0);
draw (1300,0)--(1400,0)--(1400,100)--(1300,100)--(1300,0);
\stopMPcode


To fit this object to match the available text width, I have placed \scale[width=\textwidth]{} around the code.

This causes two problems:

(1) Other MetaPost drawings also scaled down end up with different border widths. For instance, if I place one giant box on the page, scaled to the text width, using this code, I end up with very thick borders:

\scale[width=\textwidth]{
\startMPcode
draw (0,0)--(100,0)--(100,100)--(0,100)--(0,0);
\stopMPcode
}


I need consistent border widths across all drawings.

(2) Any label text added inside the boxes ends up being scaled (e.g. really tiny), but I need the fonts inside the drawings to be the same size as the fonts in the document.

What is the proper way to place MetaPost drawings in my document such that all MetaPost drawings have a consistent line width and fonts retain the same sizes they have when appearing in the rest of the document?

• I am not sure that there are any features in Context that let you do this. It is probably simpler just to make your drawing the right size in the first place. The units you are using are PostScript points (72 = 1in, 28.35 = 1cm). – Thruston Apr 27 at 18:46

The correct way to do this is scaling the units. This is very easy in this case because you exactly know the bounds of your picture beforehand.

\showframe
\starttext
\startMPcode
pickup pencircle scaled .5bp ; % defaultpen
numeric u ; u := (\the\textwidth - .5bp)/1400 ;
for i = 0 upto 13:
label(decimal i, ((i + .5) * 100u, 50u)) ;
draw unitsquare scaled (100u) xshifted (i*100u) ;
endfor ;
\stopMPcode
\stoptext