Carry output-routine marks onto the following page

This commit is contained in:
gloamxun committed 2026-10-24 00:37:46 +08:00
1 parent d4906a3cc5
commit 91171f2a90
4 files changed
+56 -9

No files matched your search

+14 -4
View File
@@ -12,7 +12,7 @@
use std::fmt;
/// Page registers visible to the output routine.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct OutputContext {
/// TeX `\pagegoal`: the goal the current page was built for.
pub page_goal: i64,
@@ -59,6 +59,8 @@ pub struct OutputContext {
pub insertion_dimens: [i64; 256],
/// TeX `\skip<n>` for insertion class `n`.
pub insertion_skips: [i64; 256],
/// `\mark{...}` texts written by the routine; they reach later pages.
pub output_marks: Vec<String>,
}
impl Default for OutputContext {
@@ -87,6 +89,7 @@ impl Default for OutputContext {
insertion_counts: [1000; 256],
insertion_dimens: [0; 256],
insertion_skips: [0; 256],
output_marks: Vec::new(),
}
}
}
@@ -152,6 +155,7 @@ enum Op {
Shipout,
Relax,
Message(String),
Mark(String),
IfDim {
left: Dimension,
relation: Relation,
@@ -516,10 +520,11 @@ fn parse_sequence(tokens: &[Token], index: &mut usize, stop: &[&str]) -> Result<
*index += 1;
ops.push(Op::Relax);
}
"message" => {
"message" | "mark" => {
let op_name = name.to_owned();
*index += 1;
if !matches!(tokens.get(*index), Some(Token::Open)) {
return Err("\\message expects a braced argument".to_owned());
return Err(format!("\\{op_name} expects a braced argument"));
}
*index += 1;
let mut text = String::new();
@@ -535,7 +540,11 @@ fn parse_sequence(tokens: &[Token], index: &mut usize, stop: &[&str]) -> Result<
}
}
}
ops.push(Op::Message(text));
ops.push(if op_name == "mark" {
Op::Mark(text)
} else {
Op::Message(text)
});
}
"advance" | "multiply" | "divide" => {
*index += 1;
@@ -872,6 +881,7 @@ fn execute(ops: &[Op], context: &mut OutputContext, shipped: &mut usize) -> Resu
match op {
Op::Shipout => *shipped += 1,
Op::Relax | Op::Message(_) => {}
Op::Mark(text) => context.output_marks.push(text.clone()),
Op::IfDim {
left,
relation,