[NTG-context] alignment of marginal material
Hans Hagen
ntg-context@ntg.nl
Mon, 23 Feb 2004 10:14:38 +0100
At 21:40 22/02/2004, Jonathan Nicholl wrote:
>I am trying to write a macro which places a picture in the margin. I would=
=20
>like the centre of the picture to be aligned vertically with the centre of=
=20
>the paragraph in which I call the macro. The following works in simple=
cases:
>
>\def\hazard#1{% The argument is the text of the=20
>paragraph
> \setbox0=3D\vbox{#1}% I do this to work out the height=
=20
> of the paragraph
> \inleft [low] {%
> \framed%
> [height=3D\ht0,% This makes the height of the=20
> frame equal to the height of the paragraph
> top=3D\vss,%
> bottom=3D\vss,% These two lines centre the=20
> picture in the frame
> frame=3Doff]%
> {\externalfigure [sharp turn sign]}%
> }%
> #1}% It goes wrong if=
=20
> you replace #1 with \box0
>
>If I type something like
>
>\hazard{=85paragraph text=85}
>
>this produces what I want. But it breaks down with mathematics.
>
>\hazard{%
> \startformula
> =85mathematics=85
> \stopformula
>}
>
>produces the picture aligned with the bottom of the mathematics.
>
>A solution to this problem escapes me. Can anyone suggest an improved=
macro?
Here is my 10 minute solution ... if i'm in the mood i can make an option=20
of it
\newcounter\CurrentFigPar
\def\StartFigPar#1%
{\doglobal\increment\CurrentFigPar
\placefigure
[leftmargin,line,none]{}
{\setbox\scratchbox\hbox{#1}%
=
\ifnum\MPp{figpar:b:\CurrentFigPar}=3D\MPp{figpar:e:\CurrentFigPar}\relax
\scratchdimen\MPy{figpar:b:\CurrentFigPar}%
\advance\scratchdimen-\MPy{figpar:e:\CurrentFigPar}%
\advance\scratchdimen-\ht\scratchbox
\advance\scratchdimen\lineheight
\else
\scratchdimen\zeropoint
\fi
\vbox{\vskip.5\scratchdimen\box\scratchbox}}%
\indent\hpos{figpar:b:\CurrentFigPar}{\strut}\ignorespaces}
\def\StopFigPar
{\removeunwantedspaces\hpos{figpar:e:\CurrentFigPar}{\strut}\endgraf}
\starttext
\input tufte
\StartFigPar{\externalfigure[cow.pdf][width=3D1cm]} \input tufte \StopFigPar
\input tufte
\stoptext=20