ConTeXt meeting and the annotated cow
Hello, last week I learned something about MetaPost at the context meeting. Thanks Taco! First a little background: I write a lot of documentation and sometimes I need to include a picture with annotations. Until now I used a drawing program to add text and arrows. This has one disadvantage, these annotations are not translated. I have to prepare a set of pictures for every language. Well, that changed last week. Here is my first try (actually the 4th iteration): %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \setupexternalfigures[location=default] \starttext \startMPinclusions %draft := 0; draft := 1; color mycolor; if draft = 1 : mycolor := red ; else: mycolor := .4white ; fi ; % Draw a grid to count locations def gridscaled = pair ur; ur = urcorner currentpicture; width := xpart ur; height := ypart ur; xstep := ceiling(width / 10); ystep := ceiling(height / 10); if draft = 1: counter := 1; for i = xstep step xstep until width : draw (i, 0 ) -- (i, height); label.rt(counter, (i , 0.5 cm)); counter := counter + 1 ; endfor; counter := 1; for i = ystep step ystep until height : draw (0, i) -- (width, i); label.top(counter, (0.5 cm, i )); counter := counter + 1 ; endfor; fi; enddef; % Bottom: The annotation is at the bottom of the start point def annotb (expr a, b, c, d) (text t) = label.bot (t, (a * xstep, b * ystep)); drawarrow (a * xstep, b * ystep) -- ( c * xstep, d * ystep) withpen pencircle scaled .8mm withcolor white; drawarrow (a * xstep, b * ystep) -- ( c * xstep, d * ystep) withpen pencircle scaled .5mm withcolor mycolor; enddef ; % Top: The annotation is on top of the start point def annott (expr a, b, c, d) (text t) = label.top (t, (a * xstep, b * ystep)); drawarrow (a * xstep, b * ystep) -- ( c * xstep, d * ystep) withpen pencircle scaled .8mm withcolor white; drawarrow (a * xstep, b * ystep) -- ( c * xstep, d * ystep) withpen pencircle scaled .5mm withcolor mycolor; enddef ; % Right: The annotation is on the right of the start point def annotr (expr a, b, c, d) (text t) = label.rt (t, (a * xstep, b * ystep)); drawarrow (a * xstep, b * ystep) -- ( c * xstep, d * ystep) withpen pencircle scaled .8mm withcolor white; drawarrow (a * xstep, b * ystep) -- ( c * xstep, d * ystep) withpen pencircle scaled .5mm withcolor mycolor; enddef ; % Left: The annotation is on the left of the start point def annotl (expr a, b, c, d) (text t) = label.lft (t, (a * xstep, b * ystep)); drawarrow (a * xstep, b * ystep) -- ( c * xstep, d * ystep) withpen pencircle scaled .8mm withcolor white; drawarrow (a * xstep, b * ystep) -- ( c * xstep, d * ystep) withpen pencircle scaled .5mm withcolor mycolor; enddef ; \stopMPinclusions \startMPpage % Picture draw externalfigure "cow.pdf" xsized 16cm; % Grid gridscaled; % Text annotb (1, 5, .8, 7.3, "Maul"); annotb (6, 2, 7, 3.2, "Euter"); annott (9.2, 9.5, 9.6, 3, "Schwanz"); annotb (3, -.5, 3.1, .9, "Huf"); annotb (3, -.5, 3.9, 1.1, ""); \stopMPpage \startMPpage % Picture draw externalfigure "cow.pdf" xsized 10cm; % Grid gridscaled; % Text annotb (1, 5, .8, 7.3, "Maul"); annotb (6, 2, 7, 3.2, "Euter"); annott (9.2, 9.5, 9.6, 3, "Schwanz"); annotb (3, -.5, 3.1, .9, "Huf"); annotb (3, -.5, 3.9, 1.1, ""); \stopMPpage \stoptext %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% There are still some further ideas and a lot to learn for me: - multi line annotations - a transparent white background - a frame around the text - a link to the section where the part is explained - moving to one command with the orientation as an argument Comments and improvements are welcome. Greetings Axel
On Sun, 18 Sep 2022 10:13:34 +0200
Axel Kielhorn via ntg-context
There are still some further ideas and a lot to learn for me: - multi line annotations - a transparent white background - a frame around the text
Just use "\framed[background=color,backgroundcolor=transparentwhite,align=normal]{text...}" where transparentwhite is your (ConTeXt) defined color. Alan
participants (2)
-
Alan
-
Axel Kielhorn