BlyxDocumentation
Browse chapters
Documentation / Workflow recipes

Lapwing · Paginate a report with indivisible paragraphs

Preflight fixed-line document pagination with indivisible paragraphs.

Paginate a report with indivisible paragraphs

A report can fit in aggregate yet overflow when a paragraph must stay together. Pack the measured paragraphs into the usable page area. The first two paragraphs fill a ten-line page. Three lines move to the second page and leave seven available there.

Run the framework with your own input

Install Blyx 0.2.1 and a Rust toolchain with a host linker, then run the versioned project. Each positional argument is a number or a comma-separated numerical vector. The CLI accepts up to 16 entries per vector. The imported module accepts longer inputs.

git clone --depth 1 --branch v0.1.0 https://github.com/Rahulchaube1/blyx-lapwing.git
cd blyx-lapwing
blyxc native-run project.blyx -- "4,6,3" 120 10 10 10

API and return values

Returns [pages, lines used on final page, unused line slots, printable lines per page]. Blocks are positive paragraph line counts. The host measures text and renders the resulting pages. Invalid input returns an empty vector.

ArgumentAccepted input
blocksVector of: nonnegative exact integer
paperpositive finite number
topnonnegative finite number
bottomnonnegative finite number
linepositive finite number

Use the libraries independently

The framework vendors the same library source published in these two repositories. Each module has its own package page, input contract and regression suite.

Try the program

Output Ready
Expected output
2
3
7
10
Open in the full playground →

Practice

Change blocks = [], paper = 40.0, top = 0.0, bottom = 0.0. Predict the result, then run the program.

Hint

Returns [pages, lines used on final page, unused line slots, printable lines per page]. Blocks are positive paragraph line counts. The host measures text and renders the resulting pages.

Worked solution

The result vector is [0, 0, 0, 4]. Compare its fields with the return layout in the API section.

Find

    let blocks = [4, 6, 3];

Replace with

    let blocks = [];

Find

    let paper = 120.0;

Replace with

    let paper = 40.0;

Find

    let top = 10.0;

Replace with

    let top = 0.0;

Find

    let bottom = 10.0;

Replace with

    let bottom = 0.0;

Output after the change

0
0
0
4