Michael Koehmstedt, RenPet | 31 May 2012 22:08

How to do Conditional Formatting?

Hello,

I'd like to know how conditional formatting could be handled in Lout. Here's some Psuedo C code that demonstrates what I'm after:

if ( canFitOnTheCurrentPage( text ) )
     print( text );
else {
     print( "See attached page" );
     newLine( );
     print( slightlyDifferentText );
}

I have an inkling of how I might be able to accomplish this with a cross-reference symbol and a two-pass run but if someone with experience could give me some advice I'd much appreciate it.

Regards,
Michael Koehmstedt


Pierre | 1 Jun 2012 01:16
Picon

Re: How to do Conditional Formatting?

Le Thursday 31 May 2012 à 13:08 -0700, Michael Koehmstedt, RenPet a
écrit :
> Hello,
> 
> I'd like to know how conditional formatting could be handled in Lout.
> Here's some Psuedo C code that demonstrates what I'm after:
> 
> if ( canFitOnTheCurrentPage( text ) )
>      print( text );
> else {
>      print( "See attached page" );
>      newLine( );
>      print( slightlyDifferentText );
> }
> 
> I have an inkling of how I might be able to accomplish this with a
> cross-reference symbol and a two-pass run but if someone with
> experience could give me some advice I'd much appreciate it.

Knowing what you are really trying to achieve (instead of "Psuedo C
code") would help. -btw my C is probably a bit out of date but *erm
cough cough cough*.
Maybe an example in Lout and why it doesn't work for you?
Off the top of my head a lot of "place"-type options have a "try"
variant, that and a "container" should do the trick. I'm unclear on the
"slightlyDifferentText" part though. 
Again, what are you really trying to do?

Regards,
Pierre

Michael Koehmstedt, RenPet | 1 Jun 2012 02:13

Re: How to do Conditional Formatting?

I do not have an example in Lout because, well, frankly, I have no real idea how to accomplish what I want :)

As an English explanation, what I'd like to do is as follows:

1) Determine whether there is room remaining on the current page to display a Table
2) If there is room, display table
3) If there is no room, display the text "See attached page"
3a) Print the table on the following page with some slight modifications

Regards,
Michael

On Thu, May 31, 2012 at 4:16 PM, Pierre <pierre.lesimple <at> mail.mcgill.ca> wrote:
Le Thursday 31 May 2012 à 13:08 -0700, Michael Koehmstedt, RenPet a
écrit :
> Hello,
>
> I'd like to know how conditional formatting could be handled in Lout.
> Here's some Psuedo C code that demonstrates what I'm after:
>
> if ( canFitOnTheCurrentPage( text ) )
>      print( text );
> else {
>      print( "See attached page" );
>      newLine( );
>      print( slightlyDifferentText );
> }
>
> I have an inkling of how I might be able to accomplish this with a
> cross-reference symbol and a two-pass run but if someone with
> experience could give me some advice I'd much appreciate it.

Knowing what you are really trying to achieve (instead of "Psuedo C
code") would help. -btw my C is probably a bit out of date but *erm
cough cough cough*.
Maybe an example in Lout and why it doesn't work for you?
Off the top of my head a lot of "place"-type options have a "try"
variant, that and a "container" should do the trick. I'm unclear on the
"slightlyDifferentText" part though.
Again, what are you really trying to do?


Regards,
Pierre




Michael Koehmstedt, RenPet | 1 Jun 2012 02:14

Re: How to do Conditional Formatting?

And my table is enclosed within a <at> OneRow object, so either the whole thing fits or it doesn't.

On Thu, May 31, 2012 at 5:13 PM, Michael Koehmstedt, RenPet <mike <at> renpetllc.com> wrote:
I do not have an example in Lout because, well, frankly, I have no real idea how to accomplish what I want :)

As an English explanation, what I'd like to do is as follows:

1) Determine whether there is room remaining on the current page to display a Table
2) If there is room, display table
3) If there is no room, display the text "See attached page"
3a) Print the table on the following page with some slight modifications

Regards,
Michael


On Thu, May 31, 2012 at 4:16 PM, Pierre <pierre.lesimple <at> mail.mcgill.ca> wrote:
Le Thursday 31 May 2012 à 13:08 -0700, Michael Koehmstedt, RenPet a
écrit :
> Hello,
>
> I'd like to know how conditional formatting could be handled in Lout.
> Here's some Psuedo C code that demonstrates what I'm after:
>
> if ( canFitOnTheCurrentPage( text ) )
>      print( text );
> else {
>      print( "See attached page" );
>      newLine( );
>      print( slightlyDifferentText );
> }
>
> I have an inkling of how I might be able to accomplish this with a
> cross-reference symbol and a two-pass run but if someone with
> experience could give me some advice I'd much appreciate it.

Knowing what you are really trying to achieve (instead of "Psuedo C
code") would help. -btw my C is probably a bit out of date but *erm
cough cough cough*.
Maybe an example in Lout and why it doesn't work for you?
Off the top of my head a lot of "place"-type options have a "try"
variant, that and a "container" should do the trick. I'm unclear on the
"slightlyDifferentText" part though.
Again, what are you really trying to do?


Regards,
Pierre





Ludovic Courtès | 1 Jun 2012 15:58
Picon

Re: How to do Conditional Formatting?

Hi,

"Michael Koehmstedt, RenPet" <mike <at> renpetllc.com> skribis:

> if ( canFitOnTheCurrentPage( text ) )
>      print( text );
> else {
>      print( "See attached page" );
>      newLine( );
>      print( slightlyDifferentText );
> }

I don’t think this can be achieved in pure Lout.

There’s the  <at> CNP symbol, which does a “conditional page break”:

    macro  <at> CNP	{ // 3.2v  <at> High //0io //{}		}

But it’s not as sophisticated as what you’re looking for.

Thanks,
Ludo’.

Jeff Kingston | 2 Jun 2012 00:15
Picon
Picon

Re: How to do Conditional Formatting?

Certainly there is nothing packaged up and ready to go.

It's possible, using a  <at> Case which compares the current
page number with the page number that the thing is on, and
returns "See attached page" if they differ.  That could be
packaged up so you could call

    tag.of.floating.thing  <at> IfOnDifferentPage { See attached text }

which would be fairly convenient, or perhaps

    tag.of.floating.thing  <at> OnThisPage
       yes {  <at> Null }
       no { See attached text }

Convergence might be a problem, I can see it flipping back and
forth between its two results on alternating runs sometimes.

Writing and testing  <at> OnThisPage would be a small, fun exercise.
If no-one else wants to do it, and Michael really really needs
it, then I will do it.

I haven't considered the difference between

   print( text );

and

   print( slightlyDifferentText );

You could probably do that in much the same way.

Jeff

On Fri, Jun 01, 2012 at 03:58:46PM +0200, Ludovic Court?s wrote:
> Hi,
> 
> "Michael Koehmstedt, RenPet" <mike <at> renpetllc.com> skribis:
> 
> > if ( canFitOnTheCurrentPage( text ) )
> >      print( text );
> > else {
> >      print( "See attached page" );
> >      newLine( );
> >      print( slightlyDifferentText );
> > }
> 
> I don???t think this can be achieved in pure Lout.
> 
> There???s the  <at> CNP symbol, which does a ???conditional page break???:
> 
>     macro  <at> CNP	{ // 3.2v  <at> High //0io //{}		}
> 
> But it???s not as sophisticated as what you???re looking for.
> 
> Thanks,
> Ludo???.

Michael Koehmstedt, RenPet | 2 Jun 2012 00:56

Re: How to do Conditional Formatting?

So here's the actual use that I plan to put this to so that we don't have to talk so vaguely about "slightly different text" and "floating things" :)

I'm using Lout to produce legal documents, for leasing. At the end of the first page there is a signature list. The signature list is a two-column table, the column on the left is for Lessor signatures, and the column on the right is for the Lessee's signature. The number of Lessors is variable, it can be one or it might be 15. Now, if the entire table can fit on the front page, I want to print it as-is. However, if it does not, I want to put "See attached page" in the left column but the right column still has the Lessee's signature line. Now, since the Lessee's signature is on the first page, the attached page would just be for the Lessor's signatures. That's why the table is "slightly different", it basically only has one column instead of two, and is formatted a bit differently.


Now for convenience sake, we'll call the original two-column table "Table1", the two-column table that has "See attached page" is "Table2", and the modified one column table on the attached page is "Table3".

Jeffrey, your suggestions are basically along the line of how I considered implementing this, but there's one part I can't figure out. Here's some pseudo-C code for what I'm imagining:

startPage = getCurrentPage( );
print( Table1 );
endPage = getCurrentPage( );

if ( startPage != endPage ) {
    unprint( Table1 );
    print( Table2 ); // Lessee's signature and "see attached page"
    print( Table3); // Lessor signatures only
}

The big question is, if I have to print Table1 to figure out what page it ends up on, how can I "unprint" it and print the alternate Table instead?


On Fri, Jun 1, 2012 at 3:15 PM, Jeff Kingston <jeff <at> it.usyd.edu.au> wrote:
Certainly there is nothing packaged up and ready to go.

It's possible, using a <at> Case which compares the current
page number with the page number that the thing is on, and
returns "See attached page" if they differ.  That could be
packaged up so you could call

   tag.of.floating.thing <at> IfOnDifferentPage { See attached text }

which would be fairly convenient, or perhaps

   tag.of.floating.thing <at> OnThisPage
      yes { <at> Null }
      no { See attached text }


Convergence might be a problem, I can see it flipping back and
forth between its two results on alternating runs sometimes.

Writing and testing <at> OnThisPage would be a small, fun exercise.
If no-one else wants to do it, and Michael really really needs
it, then I will do it.

I haven't considered the difference between

  print( text );

and

  print( slightlyDifferentText );

You could probably do that in much the same way.

Jeff

On Fri, Jun 01, 2012 at 03:58:46PM +0200, Ludovic Court?s wrote:
> Hi,
>
> "Michael Koehmstedt, RenPet" <mike <at> renpetllc.com> skribis:
>
> > if ( canFitOnTheCurrentPage( text ) )
> >      print( text );
> > else {
> >      print( "See attached page" );
> >      newLine( );
> >      print( slightlyDifferentText );
> > }
>
> I don???t think this can be achieved in pure Lout.
>
> There???s the <at> CNP symbol, which does a ???conditional page break???:
>
>     macro <at> CNP        { // 3.2v <at> High //0io //{}              }
>
> But it???s not as sophisticated as what you???re looking for.
>
> Thanks,
> Ludo???.


Jeff Kingston | 2 Jun 2012 07:10
Picon
Picon

Re: How to do Conditional Formatting?

> *The big question is, if I have to print Table1 to figure out what page it
> ends up on, how can I "unprint" it and print the alternate Table instead?*

By running Lout twice on the same document.

Jeff

Michael Koehmstedt, RenPet | 7 Jun 2012 01:12

Re: How to do Conditional Formatting?

Well, I think I must admit defeat at this point. My conceptual understanding of Lout is just too limited to figure out how to do this even after hours of trying. I'm not even sure what kind of questions to ask really...Jeff, you thought it would be a fun exercise to come up with this, so I think this might be a good opportunity :) Otherwise, I am going to need some more explicit guidance on how this might be done.

What I'm looking for is to be able to invoke something like:

object.tag <at> CanFitOnCurrentPage optional.object.tag

where if object.tag can fit on the current page it prints that, and if it can't fit on the current page it prints the optional.object.tag (with an empty object being the default).

Much appreciated,
Michael

On Fri, Jun 1, 2012 at 10:10 PM, Jeff Kingston <jeff <at> it.usyd.edu.au> wrote:
> *The big question is, if I have to print Table1 to figure out what page it
> ends up on, how can I "unprint" it and print the alternate Table instead?*

By running Lout twice on the same document.

Jeff


Pierre | 7 Jun 2012 04:35
Picon
Favicon

Re: How to do Conditional Formatting?

I must be missing something again, but "running Lout twice on the same document." in that context sounds conceptually easy enough, if not automated.

There must be some misunderstanding.



On 2012-06-06 19:12, Michael Koehmstedt, RenPet wrote:
Well, I think I must admit defeat at this point. My conceptual understanding of Lout is just too limited to figure out how to do this even after hours of trying. I'm not even sure what kind of questions to ask really...Jeff, you thought it would be a fun exercise to come up with this, so I think this might be a good opportunity :) Otherwise, I am going to need some more explicit guidance on how this might be done.

What I'm looking for is to be able to invoke something like:

object.tag <at> CanFitOnCurrentPage optional.object.tag

where if object.tag can fit on the current page it prints that, and if it can't fit on the current page it prints the optional.object.tag (with an empty object being the default).

Much appreciated,
Michael

On Fri, Jun 1, 2012 at 10:10 PM, Jeff Kingston <jeff <at> it.usyd.edu.au> wrote:
> *The big question is, if I have to print Table1 to figure out what page it
> ends up on, how can I "unprint" it and print the alternate Table instead?*

By running Lout twice on the same document.

Jeff



Michael Koehmstedt, RenPet | 8 Jun 2012 00:44

Re: How to do Conditional Formatting?

I'm at a loss at how I can write a <at> Case statement that will print the table on the first-run, gather the page numbers, and on the 2nd run test whether it fit on the current page. I have grown up using programming languages where everything is done in one pass, so that is where the conceptual problem is coming from.



On Wed, Jun 6, 2012 at 7:35 PM, Pierre <pierre.lesimple <at> mcgill.ca> wrote:
I must be missing something again, but "running Lout twice on the same document." in that context sounds conceptually easy enough, if not automated.

There must be some misunderstanding.




On 2012-06-06 19:12, Michael Koehmstedt, RenPet wrote:
Well, I think I must admit defeat at this point. My conceptual understanding of Lout is just too limited to figure out how to do this even after hours of trying. I'm not even sure what kind of questions to ask really...Jeff, you thought it would be a fun exercise to come up with this, so I think this might be a good opportunity :) Otherwise, I am going to need some more explicit guidance on how this might be done.

What I'm looking for is to be able to invoke something like:

object.tag <at> CanFitOnCurrentPage optional.object.tag

where if object.tag can fit on the current page it prints that, and if it can't fit on the current page it prints the optional.object.tag (with an empty object being the default).

Much appreciated,
Michael

On Fri, Jun 1, 2012 at 10:10 PM, Jeff Kingston <jeff <at> it.usyd.edu.au> wrote:
> *The big question is, if I have to print Table1 to figure out what page it
> ends up on, how can I "unprint" it and print the alternate Table instead?*

By running Lout twice on the same document.

Jeff




Valeriy E. Ushakov | 8 Jun 2012 05:41
Picon

Re: How to do Conditional Formatting?

On Thu, Jun 07, 2012 at 15:44:53 -0700, Michael Koehmstedt, RenPet wrote:

> I'm at a loss at how I can write a  <at> Case statement that will print the
> table on the first-run, gather the page numbers, and on the 2nd run test
> whether it fit on the current page. I have grown up using programming
> languages where everything is done in one pass, so that is where the
> conceptual problem is coming from.

Don't think in terms of if-then-else.  Print *both* objects, but make
the "See next page" one empty if the main object fits.

  print(table on next page ? "See next page" : "");
  print(table);

On the first run "if (table on next page)" is false since lout doesn't
know page number of the table yet, so the first object is empty.

The second object is printed and either does or doesn't fit the page.

On the second run "table on next page" is checked.

If on the first run the table did fit, the code doesn't print anything
(again) and the real table is again printed (and fits).  The process
converged.

If on the first run the table didn't fit, you know now, so the code
prints "See...".  It then prints the table that still doesn't fit and
goes to the next page.  The process converged.

In theory you can get a process like that, that flip-flops between two
states and never converges, or converges to a wrong state.  In your
case you should be careful to only print "See..." when you know the
table is on the next page.   Potential race would be like this:

1) a table that would just barely fit
2) you print "See..." on the first run
3) with that "See..." in place the table no longer fits

In that case the process will converge to a wrong state: "See..." is
printed and the table is on the next page, even though without
"See..." it would fit.

This can be triggered if you are not careful in step #2 above.  On the
first run lout doesn't know (some) page numbers, so you may end up
comparing "??" with "??" (where "??" is substituted for unresolvable
cross-references) unless you are careful in spelling out that "table
on next page" condition.

> On Wed, Jun 6, 2012 at 7:35 PM, Pierre <pierre.lesimple <at> mcgill.ca> wrote:
> 
> > **
> > I must be missing something again, but "running Lout twice on the same
> > document." in that context sounds conceptually easy enough, if not
> > automated.
> >
> > There must be some misunderstanding.
> >
> >
> >
> >
> > On 2012-06-06 19:12, Michael Koehmstedt, RenPet wrote:
> >
> > Well, I think I must admit defeat at this point. My conceptual
> > understanding of Lout is just too limited to figure out how to do this even
> > after hours of trying. I'm not even sure what kind of questions to ask
> > really...Jeff, you thought it would be a fun exercise to come up with this,
> > so I think this might be a good opportunity :) Otherwise, I am going to
> > need some more explicit guidance on how this might be done.
> >
> > What I'm looking for is to be able to invoke something like:
> >
> > object.tag  <at> CanFitOnCurrentPage optional.object.tag
> >
> > where if object.tag can fit on the current page it prints that, and if it
> > can't fit on the current page it prints the optional.object.tag (with an
> > empty object being the default).
> >
> > Much appreciated,
> > Michael
> >
> > On Fri, Jun 1, 2012 at 10:10 PM, Jeff Kingston <jeff <at> it.usyd.edu.au>wrote:
> >
> >> > *The big question is, if I have to print Table1 to figure out what page
> >> it
> >> > ends up on, how can I "unprint" it and print the alternate Table
> >> instead?*
> >>
> >> By running Lout twice on the same document.
> >>
> >> Jeff
> >>
> >>
> >
> >

-uwe


Gmane