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

Bob Hutchison hutch at recursive.ca
Sun Oct 3 13:48:25 UTC 2004


On Oct 1, 2004, at 9:44 AM, Marc Battyani wrote:

>> I also see that there are contextual actions. What did you have in 
>> mind
>> for these? What kind of thing can you do here? When are these called?
>> They are triggered by the stroke method, so these are executed at
>> drawing time?
>
> It's to be able to execute arbitrary lisp code when we reach some 
> point on
> the page.
> Like putting a mark or a symbol in the margin for instance.
> 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'.

--

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.


Cheers,
Bob





More information about the cl-typesetting-devel mailing list