ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* slithering captions
@ 2006-04-17  3:47 Sanjoy Mahajan
  2006-04-17  8:48 ` Hans Hagen
  0 siblings, 1 reply; 5+ messages in thread
From: Sanjoy Mahajan @ 2006-04-17  3:47 UTC (permalink / raw)


One weekend years ago I studied tex's insertions and learnt enough to
write (i.e. hack) macros to produce a layout that I'm trying to
reproduce using ConTeXt.  I've figured parts of it out, no doubt the
easier parts.

The layout has a 4in text column and a 2.3in right margin for figures
and captions.  Experiments with setuplayout got those blocks working.
But figures are to be placed according to their width.  Three natural
widths appear in the layout:

1. margin (2.3in)
2. text (4in)
3. text + margin (+ gutter) = 6.5in

You can see the results of the plain-TeX implementation in the book
chapters at <http://www.inference.phy.cam.ac.uk/sanjoy/mit/>.  A figure
is then placed in one of three ways:

1. width <= margin: margin float, with caption below it.  One example is
   p.8 of chapter 1.

2. width <= text: float to top of page, with caption in the right
   margin.  One example is p.7 of chapter 1.

3. width <= text + margin + gutter: float to top of page, bleeding into
   the margin, with caption below it in the margin.  One example is
   p. 11 of chapter 1.

So the first step in doing the placement automatically is to get the
width of the figure.  Assuming that I've done

  \useexternalfigure[fig_a][f-1.pdf]

is there an easy way to get fig_a's dimensions?  After using the figure,
e.g. with

  \placefigure[margin][]{some caption}{\externalfigure[fig_a]}

then \wd\floatbox has the dimension I need.  Will another macro fill in
\floatbox without doing the work of using the figure? I tried
\dogetfiguresizetex but probably with wrong arguments.  Another option
was

  \newdimen\a \newdimen\b \newdimen\c \newdimen\d 
  \dogetPDFmediabox{f-1.pdf}{\a}{\b}{\c}{\d}

and then \c has the width, but without any scaling and only for pdf
figures.

Once I have the width, I can define \autofig and use it like so:

\autofig{L}{caption}

and \autofig will look up the width of the figure labeled L and do
roughly:

\placefigure[margin][]{caption}{\externalfigure[L]}   % margin figures
  OR
{\setupcaptions[location=middle]	% for text figures
\placefigure[top][]{caption}{\externalfigure[L]}
}
  OR
{\setupcaptions[width=2.3in,align=right]  % for even wider figures
\placefigure[top][]{caption}{\externalfigure[L]}
}

The next problem after finding the figure width is to find the right
alternative to location=middle (which puts the caption to the left,
whereas I wanted it in the margin and to the right).

And, but this is trying to do too much at once, the next problem is that
margin caption below the widest figures (case 3 above) shouldn't overlap
other floats in the margin and also shouldn't count toward the figure's
height in the text block.  But maybe that's done automatically -- I'll
make some experiments.

Any hints greatly appreciated, and, once I get it working, I'll wikify
the layout if there's interest.

-Sanjoy

`A society of sheep must in time beget a government of wolves.'
   - Bertrand de Jouvenal

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: slithering captions
  2006-04-17  3:47 slithering captions Sanjoy Mahajan
@ 2006-04-17  8:48 ` Hans Hagen
  2006-05-22  0:37   ` Sanjoy Mahajan
  0 siblings, 1 reply; 5+ messages in thread
From: Hans Hagen @ 2006-04-17  8:48 UTC (permalink / raw)


Sanjoy Mahajan wrote:
> So the first step in doing the placement automatically is to get the
> width of the figure.  Assuming that I've done
>
>   \useexternalfigure[fig_a][f-1.pdf]
>
> is there an easy way to get fig_a's dimensions?  After using the figure,
> e.g. with
>
>   \placefigure[margin][]{some caption}{\externalfigure[fig_a]}
>   
\getfiguredimensions[...] % same args as \externalfigure

after that you have

\figureheight
\figurewidth

> And, but this is trying to do too much at once, the next problem is that
> margin caption below the widest figures (case 3 above) shouldn't overlap
> other floats in the margin and also shouldn't count toward the figure's
> height in the text block.  But maybe that's done automatically -- I'll
> make some experiments.
>   
limit the caption widths -> maxwidth

best use closed floats and set their characteristics (see details.pdf)

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
-----------------------------------------------------------------

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: slithering captions
  2006-04-17  8:48 ` Hans Hagen
@ 2006-05-22  0:37   ` Sanjoy Mahajan
  2006-05-22  7:38     ` Hans Hagen
  0 siblings, 1 reply; 5+ messages in thread
From: Sanjoy Mahajan @ 2006-05-22  0:37 UTC (permalink / raw)


From: Hans Hagen <pragma@wxs.nl>, Mon, 17 Apr 2006 10:48:29 +0200
>> [question about placing figures differently according to their widths]
> best use closed floats and set their characteristics (see details.pdf)

I haven't found closed floats in details.pdf, though it's teaching me
much useful stuff about floats meanwhile.  Are closed floats the ones
attached to text (e.g. \placefigure[inmargin]), rather than ones that
can move up and down?  Though that's the opposite of floating.

Mixing mixing inmargin and margin locations produces lots of collisions,
I've found (an example is below).  If TeX had a decent programming
language, it might be possible to implement lots more float-position
optimizations.  The user could write:

  \placefigure[inmargin][someref]{}{\externalfigure[somefig.pdf]}

  In the diagram \attachto[someref] the long arrows mean blah and the
  short arrows mean blahblah...

Then the optimizer would favor placing each margin figure with its top
aligned to the top of the attachment point, but if it couldn't do that,
it would move them up and down to minimize (say) the sum of the squared
vertical offsets (using a larger penalty if the figure had to be
postponed to the next page, and insert "(p. 27)" where
\attachto[someref] is).  The first pass can do greedy optimization on
the fly, and subsequent runs could analyze the figure locations and
their attachment points to find the best solution for a whole chapter.
But it would be miserable to do all of that in a macro language (which
are ghastly).

Here is the collision example.  As the doctor says when you say "It
hurts when I do X": "So don't do that!"

\starttext
\dorecurse{6}{
We thrive in information-thick worlds because of our
marvelous and everyday capacity to select, edit,
single out, structure, highlight, group, pair, merge,
harmonize, synthesize, focus, organize, condense,
reduce, boil down, choose, categorize, catalog, classify,

\placefigure[inmargin]{A caption goes here}
{\framed[height=1in,width=1.5in]{!}}

list, abstract, scan, look into, idealize, isolate,
discriminate, distinguish, screen, pigeonhole, pick over,
sort, integrate, blend, inspect, filter, lump, skip,
smooth, chunk, average, approximate, cluster, aggregate,

\placefigure[margin]{float}
{\framed[height=1in,width=1.5in]{!}}

outline, summarize, itemize, review, dip into,
flip through, browse, glance into, leaf through, skim,
refine, enumerate, glean, synopsize, winnow the wheat
from the chaff and separate the sheep from the goats.
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: slithering captions
  2006-05-22  0:37   ` Sanjoy Mahajan
@ 2006-05-22  7:38     ` Hans Hagen
  2006-05-22 13:59       ` Sanjoy Mahajan
  0 siblings, 1 reply; 5+ messages in thread
From: Hans Hagen @ 2006-05-22  7:38 UTC (permalink / raw)


Sanjoy Mahajan wrote:
> From: Hans Hagen <pragma@wxs.nl>, Mon, 17 Apr 2006 10:48:29 +0200
>   
>>> [question about placing figures differently according to their widths]
>>>       
>> best use closed floats and set their characteristics (see details.pdf)
>>     
>
> I haven't found closed floats in details.pdf, though it's teaching me
>   
oeps, cloned,

\definefloat[myfigure][figure]
\setupfloat[myfigure][....]
\setupcaption[myfigure][....]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: slithering captions
  2006-05-22  7:38     ` Hans Hagen
@ 2006-05-22 13:59       ` Sanjoy Mahajan
  0 siblings, 0 replies; 5+ messages in thread
From: Sanjoy Mahajan @ 2006-05-22 13:59 UTC (permalink / raw)


> oops, cloned [figures],

Ah, thanks.

For inline figures, 'here' will place it here if possible, otherwise
float to the next page.  Is there an equivalent of 'here' for margin
figures ('marginhere'?)?  

With 'margin', they float completely so are not attached to a
paragraph.  With 'inmargin', they are attached to the paragraph and
can drag the paragraph to the next page, which leaves whitespace at
the bottom of the page.

-Sanjoy

`Never underestimate the evil of which men of power are capable.'
         --Bertrand Russell, _War Crimes in Vietnam_, chapter 1.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-05-22 13:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-17  3:47 slithering captions Sanjoy Mahajan
2006-04-17  8:48 ` Hans Hagen
2006-05-22  0:37   ` Sanjoy Mahajan
2006-05-22  7:38     ` Hans Hagen
2006-05-22 13:59       ` Sanjoy Mahajan

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).