Forum How do I...?

Does anyone have an example of the multi-pass tool working to resolve layout problems after the first pass?

dlpBNA
I am trying to call the PostLayoutFunc when a problem is found, currently to much space left at the bottom of a column due to the footnotes and the widows and orphans rules we have in css.

Used the Prince.trackBoxes to determine if there was to much space and that is working. Can call Prince and tell it to run twice, --max-passes=2 and the problem gets fixed the second pass. If I tell it to run once it does not get fixed of course. In the second passed I reduce the number for widows and orphans.

But what I really want to do is when I run Prince it finds any problems that we have told it to look for then call the PostLayoutFunc with the problem it found and then run the correct code to resolve the problem.

I cannot get this to work. Can something like this work?

New to Prince and to JavaScript so I do not know exactly where the problem is and a working example might help.

Thank You
howcome
Here's a guide to using the boxtracking API, which is the technical foundation for the multi-pass method:

https://css4.pub/2023/boxtracking/

One of the examples changes the color of elements after the first pass, it may be similar to your use case. Looking for widows and orphans should also be possible, but you will need some knowledge of JavaScript.

Edited by howcome

dlpBNA
As I explained above I do know how to get information from box tracking. I was also able to get the example you mentioned above to work which is what I based the code I am working on.

I have attached the report. You can see that the tool gives a warning that there is two much space left in the second column on page 5, 127 point roughly 10 0r 11 lines. The average is around 10 - 15 points, one or two lines. Currently the tool only reports a warning when there is more than 58 points left. This is from box tracking.

What I cannot figure out is how to make that warning call the PostLayoutFunc again and again with different resolutions until the problem is fixed or until the max number is reached.

The example and what I have done so far only gets called twice. If you call it once the color is the current color, in my tool the problem does not get fixed. If you call the example twice the color gets changed, in my tool the space problem gets fixed. But in real life it might not be that easy. I do not want the program to run twice ever time we create a pdf. I only want it called a second time when a space problem is reported and then as many times as needed to fix then problem. We will know all the solutions and how many times it may take so we can set the max. But I would also like to know how many times it runs.
  1. bigtest3.0 kB
howcome
Prince will run the script multiple times as long as:

(a) the script is registered
(b) the DOM was changed in the previous pass
(c) the max limit has not been reached

This guide to aligning baselines in Prince uses the "charms" library which start a script multiple times. E.g. in this example:

https://css4.pub/2022/baseline/#adjusting-height

Edited by howcome