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? Best wishes, Jonathan ----------------------- Jonathan Nicholl Department of Philosophy King's College London
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
participants (2)
-
Hans Hagen
-
Jonathan Nicholl