[cl-typesetting-devel] Page n of m?

Marc Battyani marc.battyani at fractalconcept.com
Sun Oct 3 16:16:50 UTC 2004


Bob Hutchison wrote:
> On Oct 1, 2004, at 9:44 AM, Marc Battyani wrote:
>
> > I'm not sure this will be used every day but who knows? ;-)
>
> I might have come up with an everyday use, unless you can think of a
> better way to do this.
>
> Say you wanted to put in the header of your document the range of
> paragraphs or sections appearing on the page. For now, lets count
> paragraphs rather than sections. I was able to use contextual variables
> to get the last paragraph appearing on the page and show it in the
> header without any difficulties. This doesn't appear to be the case for
> the first paragraph though.
>
> To get the first paragraph appearing on the page, it seems to me
> anyway, that you need to have a variable that is set by the first
> paragraph appearing on the page, not set by any other paragraph, and
> then used and reset by the header (the first paragraph knows it is
> first because the variable is reset). I tried this with contextual
> variables, but the logic to set/reset is executed too early -- during
> the generation phase -- while the logic to use the value is too late --
> during the draw phase.
>
> So, enter contextual actions. I defined a variable
> first-paragraph-number-on-page in a let that wrapped all the code to
> generate the document (it could have been a special variable, of
> course, but this was easy in my example). I defined a header-action
> function:
>
> (header-action ()
>    (setf first-paragraph-number-on-page 0))
>
> in a labels scope. Then in another function defined in the same labels
> scope added this line to the code that generates the header:
>
> (tt::add-contextual-action #'header-action)
>
> In that same labels scope is a function that generates each paragraph,
> into which I added the following code.
>
> (tt::set-contextual-variable :current-paragraph-number (1+ i))
> (tt::add-contextual-action (lambda ()
>                               (when (zerop
> first-paragraph-number-on-page)
>                                 (setf first-paragraph-number-on-page (1+
> i)))))
>
> The contextual action for the paragraph had to be a lambda to capture
> the local variable 'i' that contains the paragraph number.
>
> Anyway. Unless you have a better idea, this might be your every-day use
> :-) In fact, it might be every-day enough to introduce some kind of
> abstraction like a 'deferred-contextual-variable'.

Seems a good usage of contextual actions for me.
But I don't see what would be a deferred-contextual-variable (ie deferred
until what ?)
Maybe a set-if-nil or something like that could be enough to do this.

> BTW, I don't think these posts are making their way onto the mailing
> list. There are no list related headers in the messages on this thread.

The thread is visible in the archive, so it's probably good.
You mean you don't receive messages from the list, only the direct messages?

Marc





More information about the cl-typesetting-devel mailing list