ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <pragma@wxs.nl>
Subject: Re: alignment of marginal material
Date: Mon, 23 Feb 2004 10:14:38 +0100	[thread overview]
Message-ID: <6.0.1.1.2.20040223101342.01dc1640@server-1> (raw)
In-Reply-To: <62D6C135-6577-11D8-A7EB-000A956A3A8A@kcl.ac.uk>

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 
>like the centre of the picture to be aligned vertically with the centre of 
>the paragraph in which I call the macro. The following works in simple cases:
>
>\def\hazard#1{%                         The argument is the text of the 
>paragraph
>         \setbox0=\vbox{#1}%             I do this to work out the height 
> of the paragraph
>         \inleft [low] {%
>                 \framed%
>                         [height=\ht0,%  This makes the height of the 
> frame equal to the height of the paragraph
>                         top=\vss,%
>                         bottom=\vss,%   These two lines centre the 
> picture in the frame
>                         frame=off]%
>                         {\externalfigure [sharp turn sign]}%
>                 }%
>         #1}%                                            It goes wrong if 
> you replace #1 with \box0
>
>If I type something like
>
>\hazard{…paragraph text…}
>
>this produces what I want. But it breaks down with mathematics.
>
>\hazard{%
>         \startformula
>                 …mathematics…
>         \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 
of it

\newcounter\CurrentFigPar

\def\StartFigPar#1%
   {\doglobal\increment\CurrentFigPar
    \placefigure
      [leftmargin,line,none]{}
      {\setbox\scratchbox\hbox{#1}%
       \ifnum\MPp{figpar:b:\CurrentFigPar}=\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=1cm]} \input tufte \StopFigPar

\input tufte

\stoptext 

      reply	other threads:[~2004-02-23  9:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-22 20:40 Jonathan Nicholl
2004-02-23  9:14 ` Hans Hagen [this message]

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=6.0.1.1.2.20040223101342.01dc1640@server-1 \
    --to=pragma@wxs.nl \
    --cc=ntg-context@ntg.nl \
    /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).