Patrick Gundlach wrote:
Hello *,


inspired by Gerben's question, I did some experimenting with \framed.

I'd like to get A[text]B, where text is some long thing in a framed
box like \framed[width=5cm] {\input tufte \par}.

There are three different ways of aligning the three objects:


(A and B on the same baseline as the first row)

A We  thrive  in  information- B
-------------------------------
  thick worlds because of  our
  marvelous and  everyday  ca-


(A and B in the middle of the box, not necessarily on the same baseline as a line in the box)

criminate, distinguish, screen, A pigeonhole, pick over, sort, B
integrate, blend, inspect,



(A and B on the same baseline as the last row)

  from the chaff and seperate
A the sheeps from the  goats. B
--------------------------------



I was unable to get any of these alignments.

one way is to put things in a box and do some measuring and such; however, then you need to know a bit about the position of the baseline (measurethe middle box, and use a dummy framed around A and B with that height set etc)


the other way is to use the following extensions (i made the dislocator installable so that you can hook in your own code if needed)


\unprotect

\def\stoplocalframed
  {\dontshowcomposition
   \@@stopframedorientation
   \ifboxhasformat
     \ifx\localwidth\v!fit
       \ifreshapeframebox\doreshapeframedbox\fi
       \boxhaswidthfalse
     \else\ifx\localwidth\v!fixed
       \boxhaswidthfalse
     \else
       \resetshapeframebox
     \fi\fi
   \else
     \resetshapeframebox
   \fi
   \ifboxhaswidth
     \wd\framebox\!!widtha
   \fi
   \ifboxhasheight
     \ht\framebox\!!heighta
   \fi
   \doifvalue{\@@framed\c!empty}\v!yes
     {\setbox\scratchbox\null
      \wd\scratchbox\wd\framebox
      \ht\scratchbox\ht\framebox
      \dp\scratchbox\dp\framebox
      \setbox\framebox\box\scratchbox}%
   \stopregistercolor
   \docolorframebox
   \ifboxhasoffset
     \dooffsetframebox
   \fi
   \ifboxisoverlaid \else
     \dolocateframebox
   \fi
   \ifx\postprocessframebox\relax \else
     \let\next\postprocessframebox
     \let\postprocessframebox\relax % prevent nesting
     \next\framebox
   \fi
   \edef\overlaylinecolor{\framedparameter\c!framecolor}%
   \edef\overlaylinewidth{\the\ruledlinewidth}% \@@...
   \ifboxhasframe % real or invisible frame
     \doframedbox
   \fi
   \doifvaluesomething{\@@framed\c!background}\dobackedbox
   \handleframedlocator\@@locallocation
   \box\framebox
   \egroup
   \egroup}

\def\installframedlocator#1#2%
  {\setvalue{\??ol:\c!location:#1}{#2}}

\def\handleframedlocator#1%
  {\getvalue{\??ol:\c!location:#1}}

\def\doprelocframedbox#1%
  {\scratchdimen#1\relax
   \advance\scratchdimen \ruledlinewidth
   \ifboxhasoffset
     \advance\scratchdimen \framedparameter\c!offset
   \fi
   \scratchskip\ht\framebox
   \advance\scratchskip-\scratchdimen}

\installframedlocator \v!hanging % best with strut=no
  {\dp\framebox\ht\framebox
   \ht\framebox\zeropoint}

\installframedlocator \v!depth
  {\scratchdimen\ht\framebox
   \advance\scratchdimen -\strutdp
   \ht\framebox\scratchdimen
   \dp\framebox\strutdp
   \box\framebox}

\installframedlocator \v!height
  {\scratchdimen\ht\framebox
   \advance\scratchdimen -\strutht
   \ht\framebox\strutht
   \dp\framebox\scratchdimen
   \box\framebox}

\installframedlocator \v!high
  {\doprelocframedbox\strutht
   \setbox\framebox\hbox{\lower\scratchskip\box\framebox}%
   \ht\framebox\strutht
   \dp\framebox\strutdp
   \hbox{\box\framebox}}

\installframedlocator \v!line
  {\setbox\framebox\hbox{\lower.5\ht\framebox\box\framebox}%
   \ht\framebox.5\lineheight
   \dp\framebox.5\lineheight
   \hbox{\box\framebox}}

\installframedlocator \v!low
  {\doprelocframedbox\strutdp
   \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}%
   \ht\framebox\strutht
   \dp\framebox\strutdp
   \box\framebox}

\installframedlocator \v!top
  {\doprelocframedbox\strutht
   \setbox\framebox\hbox{\lower\scratchskip\box\framebox}%
   \ht\framebox\scratchdimen
   \dp\framebox\scratchskip
   \hbox{\box\framebox}}

\installframedlocator \v!middle
  {\scratchdimen.5\ht\framebox
   \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}%
   \ht\framebox\scratchdimen
   \dp\framebox\scratchdimen
   \hbox{\box\framebox}}

\installframedlocator \v!lohi
  {\handleframedlocator\v!middle}

\installframedlocator \v!bottom
  {\doprelocframedbox\strutdp
   \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}%
   \ht\framebox\scratchskip
   \dp\framebox\scratchdimen
   \hbox{\box\framebox}}

\starttext

\ruledhbox
  {A
   \framed[width=2cm,align=middle,location=hanging]{location\\equals\\hanging}
   \framed[width=2cm,align=middle,location=depth]  {location\\equals\\depth}
   \framed[width=2cm,align=middle,location=height] {location\\equals\\height}
   B}

\vskip2cm

\ruledhbox
  {A
   \framed[width=2cm,align=middle,location=low]    {location\\equals\\low}
   \framed[width=2cm,align=middle,location=line]   {location\\equals\\line}
   \framed[width=2cm,align=middle,location=high]   {location\\equals\\high}
   B}

\vskip2cm

\ruledhbox
 {A
  \framed[width=2cm,align=middle,location=top]    {location\\equals\\top}
  \framed[width=2cm,align=middle,location=bottom] {location\\equals\\bottom}
  \framed[width=2cm,align=middle,location=lohi]   {location\\equals\\lohi}
  \framed[width=2cm,align=middle,location=middle] {location\\equals\\middle}
  B}

\stoptext

(hanging, depth and low were already present)

check for compatibility -)

Hans

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

Reply via email to