Files
texrra-engine/crates/texrra-tex-core/examples/incremental_article.rs
T

38 lines
1.1 KiB
Rust
Executable File

//! M0 demo: a three-paragraph article whose middle paragraph is edited.
//!
//! Run with `cargo run -p texrra-tex-core --example incremental_article`.
//! It prints the page count before/after the edit and the pages that the
//! checkpoint replay had to rebuild.
use texrra_tex_core::{Document, Engine, ParagraphStyle, Unit};
fn paragraph(id: u64, marker: &str) -> Unit {
// Roughly one page of 10pt text at a 300pt page goal.
let text = format!("{} {}", marker, "alpha beta gamma delta ".repeat(80));
Unit::paragraph_with_style(id, text, ParagraphStyle::default())
}
fn main() {
let document = Document::new(
300,
vec![
paragraph(1, "ONE"),
paragraph(2, "TWO"),
paragraph(3, "THREE"),
],
);
let mut engine = Engine::layout(&document);
println!(
"initial: pages={} changed={:?}",
engine.pages().len(),
engine.changed_pages()
);
engine.edit(&document, 2, "TWO edited beta gamma delta ".repeat(60));
println!(
"after edit: pages={} changed={:?}",
engine.pages().len(),
engine.changed_pages()
);
}