ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Axel Kielhorn via ntg-context <ntg-context@ntg.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Cc: Axel Kielhorn <tex@axelkielhorn.de>
Subject: ConTeXt meeting and the annotated cow
Date: Sun, 18 Sep 2022 10:13:34 +0200	[thread overview]
Message-ID: <8FAE9CA0-3254-4E77-9DAA-2BCC0B2F4146@axelkielhorn.de> (raw)

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
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : https://contextgarden.net
___________________________________________________________________________________

             reply	other threads:[~2022-09-18  8:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-18  8:13 Axel Kielhorn via ntg-context [this message]
2022-09-18 19:20 ` Alan via ntg-context

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8FAE9CA0-3254-4E77-9DAA-2BCC0B2F4146@axelkielhorn.de \
    --to=ntg-context@ntg.nl \
    --cc=tex@axelkielhorn.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).