From 6675ab639aecb5e729f7be21ba72c049aa9d7917 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Sat, 21 Nov 2026 05:38:05 +0800 Subject: [PATCH] Redirect native TeX diagnostics to real output streams --- .../src/execution/diagnostics.rs | 36 +- .../texrra-tex-core/src/execution/engine.rs | 1 + .../src/execution/engine/boxes.rs | 16 +- .../src/execution/engine/diagnostics.rs | 440 +++++++++++++++++- .../src/execution/engine/restores.rs | 1 + .../src/execution/format_image.rs | 6 +- crates/texrra-tex-core/src/execution/mod.rs | 6 + .../src/execution/parameters.rs | 3 + crates/texrra-tex-core/src/execution/state.rs | 6 + docs/P2_M1_PROGRESS.md | 20 + tests/native_generated_files.rs | 26 ++ 11 files changed, 540 insertions(+), 21 deletions(-) diff --git a/crates/texrra-tex-core/src/execution/diagnostics.rs b/crates/texrra-tex-core/src/execution/diagnostics.rs index 2db964d..16a0c79 100644 --- a/crates/texrra-tex-core/src/execution/diagnostics.rs +++ b/crates/texrra-tex-core/src/execution/diagnostics.rs @@ -95,7 +95,7 @@ fn leader_node(leader: &LeaderGlue) -> DiagnosticNode { pattern: Box::new(pattern), } } -fn vertical_nodes(nodes: &[NativeVerticalNode]) -> Vec { +pub(super) fn vertical_nodes(nodes: &[NativeVerticalNode]) -> Vec { nodes .iter() .map(|n| match n { @@ -258,6 +258,7 @@ struct Printer<'a> { depth: i32, limit: usize, overflow: bool, + wrap: bool, reads: BTreeSet, } impl Printer<'_> { @@ -272,7 +273,7 @@ impl Printer<'_> { } else { self.tally += 1; self.column += 1; - if self.column == 79 { + if self.wrap && self.column == 79 { self.out.push('\n'); self.column = 0; } @@ -750,6 +751,7 @@ pub(super) fn show_box( breadth: i32, depth: i32, limit: usize, + wrap: bool, ) -> Result<(String, BTreeSet), String> { let mut p = Printer { state, @@ -760,6 +762,7 @@ pub(super) fn show_box( depth, limit, overflow: false, + wrap, reads: BTreeSet::new(), }; p.literal(&format!("> \\box{index}=")); @@ -797,6 +800,7 @@ pub(super) fn shipout_box( depth, limit, overflow: false, + wrap: true, reads: BTreeSet::new(), }; if depth < 0 { @@ -811,3 +815,31 @@ pub(super) fn shipout_box( } Ok((p.out, p.reads)) } + + +pub(super) fn show_nodes( + state: &State, + nodes: &[DiagnosticNode], + breadth: i32, + depth: i32, + limit: usize, + wrap: bool, +) -> Result<(String, BTreeSet), String> { + let mut printer = Printer { + state, + out: String::new(), + column: 0, + tally: 0, + breadth: if breadth <= 0 { 5 } else { breadth as usize }, + depth, + limit, + overflow: false, + wrap, + reads: BTreeSet::new(), + }; + printer.nodes(nodes, "")?; + if printer.overflow { + return Err("native list diagnostic output capacity exceeded".into()); + } + Ok((printer.out, printer.reads)) +} diff --git a/crates/texrra-tex-core/src/execution/engine.rs b/crates/texrra-tex-core/src/execution/engine.rs index ed8a6a2..00e53b5 100644 --- a/crates/texrra-tex-core/src/execution/engine.rs +++ b/crates/texrra-tex-core/src/execution/engine.rs @@ -3659,6 +3659,7 @@ impl Executor { } Aftergroup => self.schedule_after_group(files)?, Showbox => self.show_box(files)?, + Showlists | Showgroups | Showifs => self.show_activity(primitive, files)?, Show | Showthe => self.show( primitive == Showthe, token.invocation.unwrap_or(token.span), diff --git a/crates/texrra-tex-core/src/execution/engine/boxes.rs b/crates/texrra-tex-core/src/execution/engine/boxes.rs index f470218..25ed522 100644 --- a/crates/texrra-tex-core/src/execution/engine/boxes.rs +++ b/crates/texrra-tex-core/src/execution/engine/boxes.rs @@ -12,16 +12,16 @@ pub(super) enum Destination { } #[derive(Clone)] pub(super) struct BoxFrame { - kind: BoxKind, - spec: PackSpec, + pub(super) kind: BoxKind, + pub(super) spec: PackSpec, group: GroupKind, - depth: usize, - destination: Destination, - paragraph: Option, - vertical: VerticalBuilder, - span: Span, + pub(super) depth: usize, + pub(super) destination: Destination, + pub(super) paragraph: Option, + pub(super) vertical: VerticalBuilder, + pub(super) span: Span, discretionary: Option, - math: Vec, + pub(super) math: Vec, // An inner $...$ belongs to this box, even inside an outer display. display: Option, } diff --git a/crates/texrra-tex-core/src/execution/engine/diagnostics.rs b/crates/texrra-tex-core/src/execution/engine/diagnostics.rs index 1c69ae1..e3b634f 100644 --- a/crates/texrra-tex-core/src/execution/engine/diagnostics.rs +++ b/crates/texrra-tex-core/src/execution/engine/diagnostics.rs @@ -1,3 +1,4 @@ +use super::super::diagnostics::{DiagnosticNode, show_nodes, text_nodes, vertical_nodes}; use super::*; impl Executor { pub(super) fn trace_conditional( @@ -211,6 +212,9 @@ impl Executor { context } pub(super) fn print_show_parts(&self, parts: &[&str]) -> Result { + self.format_show_parts(parts, true) + } + fn format_show_parts(&self, parts: &[&str], wrap: bool) -> Result { let mut out = String::new(); let mut column = 0; let mut raw = |c: char| -> Result<(), Error> { @@ -222,7 +226,7 @@ impl Executor { column = 0; } else { column += 1; - if column == 79 { + if wrap && column == 79 { out.push('\n'); column = 0; } @@ -245,13 +249,44 @@ impl Executor { } Ok(out) } + fn open_show_stream(&mut self) -> Option { + let stream = self.read_parameter(Parameter::Showstream).width(); + if (0..16).contains(&stream) { + let stream = stream as u8; + self.reads.insert(Dependency::OutputStream(stream)); + if self.io.outputs.contains(&stream) { + return Some(stream); + } + } + None + } + + fn write_show( + &mut self, + files: &mut impl SourceProvider, + stream: u8, + text: String, + span: Span, + ) -> Result<(), Error> { + self.diagnostic_bytes = self.diagnostic_bytes.saturating_add(text.len()); + if self.diagnostic_bytes > self.limits.tokens { + return self.fail("native diagnostic output limit exceeded"); + } + files + .write_out(stream, &text) + .map_err(|error| self.error(error, span))?; + self.events + .push(Event::ShowRedirected { stream, text, span }); + Ok(()) + } + pub(super) fn show( &mut self, the: bool, span: Span, files: &mut impl SourceProvider, ) -> Result<(), Error> { - let text = if the { + let (mut head, mut tail) = if the { let text = match self.the_value(files)? { TheValue::Text(text) => text, TheValue::Tokens(tokens) => { @@ -266,7 +301,7 @@ impl Executor { text } }; - self.print_show_parts(&[&format!("> {text}.")])? + (format!("> {text}"), None) } else { let t = self.required_raw(files)?.token; let macro_meaning = matches!(self.meaning(&t), Meaning::Macro(_)); @@ -278,14 +313,26 @@ impl Executor { let meaning = self.meaning_string(&t)?; if macro_meaning { let split = meaning.find("macro:").unwrap() + "macro:".len(); - self.print_show_parts(&[ - &format!("> {name}{}", &meaning[..split]), - &format!("{}.", &meaning[split..]), - ])? + ( + format!("> {name}{}", &meaning[..split]), + Some(meaning[split..].to_owned()), + ) } else { - self.print_show_parts(&[&format!("> {name}{meaning}.")])? + (format!("> {name}{meaning}"), None) } }; + let stream = self.open_show_stream(); + if stream.is_none() { + tail.as_mut().unwrap_or(&mut head).push('.'); + } + self.reads.insert(Dependency::NewLineChar); + let text = match &tail { + Some(tail) => self.format_show_parts(&[&head, tail], stream.is_none())?, + None => self.format_show_parts(&[&head], stream.is_none())?, + }; + if let Some(stream) = stream { + return self.write_show(files, stream, format!("\n{text}\n"), span); + } if text.len() > self.limits.tokens { return self.fail("native diagnostic output limit exceeded"); } @@ -321,6 +368,7 @@ impl Executor { let span = self.current; self.finish_text(true)?; let index = self.register_index(files)?; + let stream = self.open_show_stream(); self.reads.insert(Dependency::BoxRegister(index)); self.reads.insert(Dependency::FontResources); self.reads.insert(Dependency::EscapeChar); @@ -339,9 +387,18 @@ impl Executor { breadth, depth, self.limits.tokens, + stream.is_none(), ) .map_err(|e| self.error(e, span))?; self.reads.extend(reads); + if let Some(stream) = stream { + let extra = if self.state.box_register(index).is_some() { + "\n" + } else { + "" + }; + return self.write_show(files, stream, format!("\n{text}{extra}\n! OK\n"), span); + } let context = self.diagnostic_context(); self.reserve_diagnostic( text.len() + context.text.len() + 2 * "! OK (see the transcript file).\n".len(), @@ -375,6 +432,373 @@ impl Executor { .map_err(|e| self.error(e, span))?; Ok(()) } + + pub(super) fn show_activity( + &mut self, + command: Primitive, + files: &mut impl SourceProvider, + ) -> Result<(), Error> { + let span = self.current; + if command == Primitive::Showlists { + self.finish_text(true)?; + } + let stream = self.open_show_stream(); + let wrap = stream.is_none(); + let body = match command { + Primitive::Showlists => { + let breadth = self.read_parameter(Parameter::Showboxbreadth).width(); + let depth = self.read_parameter(Parameter::Showboxdepth).width(); + let (body, dependencies) = self + .activity_lists(breadth, depth, wrap) + .map_err(|message| self.error(message, span))?; + self.reads.extend(dependencies); + body + } + Primitive::Showgroups => { + let lines = self.activity_groups(); + self.format_show_parts(&lines.iter().map(String::as_str).collect::>(), wrap)? + } + Primitive::Showifs => { + let lines = self.activity_conditionals(); + self.format_show_parts(&lines.iter().map(String::as_str).collect::>(), wrap)? + } + _ => unreachable!(), + }; + if let Some(stream) = stream { + return self.write_show(files, stream, format!("\n\n\n{body}\n\n\n! OK\n"), span); + } + let context = self.diagnostic_context(); + let online = self.read_parameter(Parameter::Tracingonline).width() > 0; + let destination = if online { + WriteDestination::TerminalAndLog + } else { + WriteDestination::Log + }; + let text = format!("\n{body}\n\n"); + let log_output = format!("{}\n{}\n", self.external_print("! OK."), context.text); + let ok = if online { + "! OK." + } else { + "! OK (see the transcript file)." + }; + let output = format!("{}\n{}", self.external_print(ok), context.text); + self.reserve_diagnostic(text.len() + log_output.len(), &context)?; + files + .observe_diagnostic(destination, &text) + .map_err(|error| self.error(error, span))?; + files + .observe_diagnostic_pair(&log_output, &output) + .map_err(|error| self.error(error, span))?; + self.events.push(Event::Show(ShowReport { + output, + log_output, + the: false, + text, + context, + span, + })); + Ok(()) + } + + fn activity_conditionals(&mut self) -> Vec { + self.reads.insert(Dependency::ConditionalState); + if self.conditionals.is_empty() { + return vec!["### no active conditionals".into()]; + } + let frames = self.conditionals.clone(); + frames + .iter() + .enumerate() + .rev() + .map(|(index, frame)| { + let mut description = self.trace_primitive_name(frame.primitive, frame.inverted); + if frame.limit == ConditionalLimit::Fi { + description.push_str(&self.trace_primitive_name(Primitive::Else, false)); + } + if let Some((source, line)) = frame.origin.filter(|(_, line)| *line != 0) { + self.reads.insert(Dependency::InputPosition(source)); + description.push_str(&format!(" entered on line {line}")); + } + format!("### level {}: {description}", index + 1) + }) + .collect() + } + + fn activity_groups(&mut self) -> Vec { + use super::super::boxes::PackSpec; + self.reads.insert(Dependency::GroupState); + self.reads.insert(Dependency::EscapeChar); + let escape = u8::try_from(self.state.escapechar) + .ok() + .map(|value| char::from(value).to_string()) + .unwrap_or_default(); + let mut lines = Vec::new(); + for (index, (kind, origin)) in self.state.open_groups().enumerate().rev() { + let level = index + 1; + let mut text = format!( + "### {} group (level {level})", + super::scheduling::group_name(kind) + ); + if let Some((source, line)) = origin.filter(|(_, line)| *line != 0) { + self.reads.insert(Dependency::InputPosition(source)); + text.push_str(&format!(" entered at line {line}")); + } + let detail = if let Some(frame) = + self.box_frames.iter().find(|frame| frame.depth == level) + { + let name = match frame.kind { + BoxKind::Horizontal => "hbox", + BoxKind::Vtop => "vtop", + _ if kind == GroupKind::Vcenter => "vcenter", + _ => "vbox", + }; + let placement = match frame.destination { + boxes::Destination::Append => String::new(), + boxes::Destination::Shipout => format!("{escape}shipout"), + boxes::Destination::Register(number, global) => { + let prefix = if global { + format!("{escape}global") + } else { + String::new() + }; + format!("{prefix}{escape}setbox{number}=") + } + boxes::Destination::Shift(amount) => { + let command = match (frame.paragraph.is_some(), amount.is_negative()) { + (false, false) => "moveright", + (false, true) => "moveleft", + (true, false) => "lower", + (true, true) => "raise", + }; + format!( + "{escape}{command}{}pt", + registers::print_scaled_wide(i64::from(amount).abs()) + ) + } + boxes::Destination::Leaders(mode) => { + let command = match mode { + LeaderMode::Aligned => "leaders", + LeaderMode::Centered => "cleaders", + LeaderMode::Expanded => "xleaders", + }; + format!("{escape}{command}") + } + boxes::Destination::Adjustment { .. } => format!("{escape}vadjust"), + boxes::Destination::Insertion { class } => format!("{escape}insert{class}"), + }; + let size = match frame.spec { + PackSpec::To(value) if value != 0 => { + format!(" to{}pt", registers::print_scaled(value)) + } + PackSpec::Spread(value) if value != 0 => { + format!(" spread{}pt", registers::print_scaled(value)) + } + _ => String::new(), + }; + if matches!( + frame.destination, + boxes::Destination::Adjustment { .. } | boxes::Destination::Insertion { .. } + ) { + format!("{placement}{{") + } else { + format!("{placement}{escape}{name}{size}{{") + } + } else { + match kind { + GroupKind::Simple | GroupKind::MathGroup => "{".into(), + GroupKind::SemiSimple => format!("{escape}begingroup"), + GroupKind::Output => format!("{escape}output"), + GroupKind::NoAlign => format!("{escape}noalign{{"), + GroupKind::MathLeft => format!("{escape}left"), + GroupKind::MathShift if self.display.is_some() => "$$".into(), + GroupKind::MathShift => "$".into(), + GroupKind::MathChoice => format!("{escape}mathchoice{{"), + GroupKind::Discretionary => format!("{escape}discretionary{{"), + GroupKind::Align => "align entry".into(), + _ => String::new(), + } + }; + if !detail.is_empty() { + text.push_str(&format!(" ({detail})")); + } + lines.push(text); + } + lines.push("### bottom level".into()); + lines + } + + fn activity_lists( + &self, + breadth: i32, + depth: i32, + wrap: bool, + ) -> Result<(String, BTreeSet), String> { + if !self.math.is_empty() + || self.box_frames.iter().any(|frame| !frame.math.is_empty()) + || !self.alignments.is_empty() + || self.output_frame.is_some() + { + return Err( + "native showlists requires math, alignment or output nest diagnostics".into(), + ); + } + let mut frames = Vec::new(); + let mut enclosing_span = None; + for frame in &self.box_frames { + frames.push((frame.paragraph.as_ref(), &frame.vertical, enclosing_span)); + enclosing_span = Some(frame.span); + } + frames.push((self.paragraph.as_ref(), &self.vertical, enclosing_span)); + let mut text = String::new(); + let mut reads = BTreeSet::from([ + Dependency::ParagraphMode, + Dependency::VerticalState, + Dependency::PageState, + Dependency::FontResources, + Dependency::EscapeChar, + Dependency::NewLineChar, + ]); + let mut line = |span: Span| { + reads.insert(Dependency::InputPosition(span.source)); + let prefix = self + .sources + .get(span.source) + .and_then(|source| source.data.get(..span.start)) + .unwrap_or_default(); + let eols = prefix + .iter() + .enumerate() + .filter(|&(index, byte)| { + *byte == b'\r' || (*byte == b'\n' && (index == 0 || prefix[index - 1] != b'\r')) + }) + .count(); + eols + 1 + }; + let mut levels = Vec::new(); + for (paragraph, vertical, span) in frames.into_iter().rev() { + levels.push(( + paragraph.map(|p| (p, line(p.span))), + vertical, + span.map(&mut line), + )); + } + let mut render = |text: &mut String, nodes: &[DiagnosticNode]| -> Result<(), String> { + let (part, used) = + show_nodes(&self.state, nodes, breadth, depth, self.limits.tokens, wrap)?; + if text.len().saturating_add(part.len()) > self.limits.tokens { + return Err("native list diagnostic output limit exceeded".into()); + } + text.push_str(&part); + reads.extend(used); + Ok(()) + }; + for (paragraph, vertical, enter) in levels { + if !text.is_empty() { + text.push('\n'); + } + if let Some((paragraph, line)) = paragraph { + let mode = if paragraph.restricted { + "restricted horizontal" + } else { + "horizontal" + }; + text.push_str(&format!("### {mode} mode entered at line {line}")); + let language = paragraph.initial_language; + if !paragraph.restricted + && (language.language != 0 || language.left_min != 2 || language.right_min != 3) + { + text.push_str(&format!( + " (language{}:hyphenmin{},{})", + language.language, language.left_min, language.right_min + )); + } + render(&mut text, &text_nodes(¶graph.nodes))?; + text.push_str(&format!("\n\nspacefactor {}", paragraph.space_factor)); + if !paragraph.restricted && paragraph.current_language.language != 0 { + text.push_str(&format!( + ", current language {}", + paragraph.current_language.language + )); + } + if paragraph.restricted { + continue; + } + text.push('\n'); + } + let mode = if enter.is_some() { + "internal vertical" + } else { + "vertical" + }; + text.push_str(&format!( + "### {mode} mode entered at line {}", + enter.unwrap_or(0) + )); + if enter.is_none() + && let Some(page) = &self.native_page + { + if !page.nodes.is_empty() { + text.push_str("\n### current page:"); + render(&mut text, &vertical_nodes(&page.nodes))?; + if page.started { + let [goal, total, plus, fil, fill, filll, shrink, _] = page.dimensions; + text.push_str(&format!( + "\n\n total height {}", + registers::print_scaled_wide(total) + )); + for (value, unit) in + [(plus, ""), (fil, "fil"), (fill, "fill"), (filll, "filll")] + { + if value != 0 { + text.push_str(&format!( + " plus {}{unit}", + registers::print_scaled_wide(value) + )); + } + } + if shrink != 0 { + text.push_str(&format!( + " minus {}", + registers::print_scaled_wide(shrink) + )); + } + text.push_str(&format!( + "\n goal height {}", + registers::print_scaled_wide(goal) + )); + } + text.push('\n'); + } + if !page.contributions.is_empty() { + text.push_str("\n### recent contributions:"); + let pending: Vec<_> = page.contributions.iter().cloned().collect(); + render(&mut text, &vertical_nodes(&pending))?; + } + } + if enter.is_none() && !vertical.nodes.is_empty() && self.native_page.is_some() { + text.push_str("\n### recent contributions:"); + } + render(&mut text, &vertical_nodes(&vertical.nodes))?; + text.push_str("\n\nprevdepth "); + if vertical.prev_depth <= -1000 * 65536 { + text.push_str("ignored"); + } else { + text.push_str(®isters::print_scaled(vertical.prev_depth)); + } + if vertical.previous_lines != 0 { + let suffix = if vertical.previous_lines == 1 { + "" + } else { + "s" + }; + text.push_str(&format!( + ", prevgraf {} line{suffix}", + vertical.previous_lines + )); + } + } + Ok((text, reads)) + } } impl Executor { diff --git a/crates/texrra-tex-core/src/execution/engine/restores.rs b/crates/texrra-tex-core/src/execution/engine/restores.rs index 43c03a1..e47403f 100644 --- a/crates/texrra-tex-core/src/execution/engine/restores.rs +++ b/crates/texrra-tex-core/src/execution/engine/restores.rs @@ -211,6 +211,7 @@ impl Executor { 1, 0, self.limits.tokens, + true, ) .map_err(|error| self.error(error, self.current))?; self.reads.extend(reads); diff --git a/crates/texrra-tex-core/src/execution/format_image.rs b/crates/texrra-tex-core/src/execution/format_image.rs index 8c4f8bd..99a0194 100644 --- a/crates/texrra-tex-core/src/execution/format_image.rs +++ b/crates/texrra-tex-core/src/execution/format_image.rs @@ -8,9 +8,9 @@ use std::{ sync::{Arc, Mutex, OnceLock, Weak}, }; -const SCHEMA: u32 = 47; -const COMPATIBLE_SCHEMAS: [u32; 16] = [ - 27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 44, 45, 46, SCHEMA, +const SCHEMA: u32 = 48; +const COMPATIBLE_SCHEMAS: [u32; 17] = [ + 27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 44, 45, 46, 47, SCHEMA, ]; const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION")); diff --git a/crates/texrra-tex-core/src/execution/mod.rs b/crates/texrra-tex-core/src/execution/mod.rs index f117469..96fbf0b 100644 --- a/crates/texrra-tex-core/src/execution/mod.rs +++ b/crates/texrra-tex-core/src/execution/mod.rs @@ -413,6 +413,7 @@ pub enum Dependency { EscapeChar, InteractionMode, GroupState, + ConditionalState, AssignmentState, TokenParameter(TokenParameter), GlobalDefs, @@ -485,6 +486,11 @@ pub enum Event { MissingGlyph(MissingGlyph), ShowBox(ShowBoxReport), Show(ShowReport), + ShowRedirected { + stream: u8, + text: String, + span: Span, + }, BuiltParagraph(Box), BuiltMath(Box), BuiltDisplay(Box), diff --git a/crates/texrra-tex-core/src/execution/parameters.rs b/crates/texrra-tex-core/src/execution/parameters.rs index 3b578c8..518921e 100644 --- a/crates/texrra-tex-core/src/execution/parameters.rs +++ b/crates/texrra-tex-core/src/execution/parameters.rs @@ -44,6 +44,7 @@ pub enum Parameter { Defaultskewchar, Tracinglostchars, Tracingonline, + Showstream, Displaywidowpenalty, Predisplaypenalty, Postdisplaypenalty, @@ -162,6 +163,7 @@ impl Parameter { Self::Defaultskewchar, Self::Tracinglostchars, Self::Tracingonline, + Self::Showstream, Self::Displaywidowpenalty, Self::Predisplaypenalty, Self::Postdisplaypenalty, @@ -306,6 +308,7 @@ impl Parameter { Self::Tolerance => 10000, Self::Hangafter => 1, Self::Maxdeadcycles => 25, + Self::Showstream => -1, _ => 0, }) } diff --git a/crates/texrra-tex-core/src/execution/state.rs b/crates/texrra-tex-core/src/execution/state.rs index e5a7c43..70ba236 100644 --- a/crates/texrra-tex-core/src/execution/state.rs +++ b/crates/texrra-tex-core/src/execution/state.rs @@ -235,6 +235,9 @@ pub enum Primitive { Showbox, Show, Showthe, + Showlists, + Showgroups, + Showifs, Vbox, Vtop, Vcenter, @@ -770,6 +773,7 @@ impl Default for State { ("showbox", Showbox), ("show", Show), ("showthe", Showthe), + ("showlists", Showlists), ("delcode", Delcode), ("sfcode", Sfcode), ("lccode", Lccode), @@ -1343,6 +1347,8 @@ impl State { ("eTeXversion", Etexversion), ("eTeXrevision", Etexrevision), ("currentgrouplevel", Currentgrouplevel), + ("showgroups", Showgroups), + ("showifs", Showifs), ("currentgrouptype", Currentgrouptype), ("lastnodetype", Lastnodetype), ("pagediscards", Pagediscards), diff --git a/docs/P2_M1_PROGRESS.md b/docs/P2_M1_PROGRESS.md index 74e0480..b82ae06 100644 --- a/docs/P2_M1_PROGRESS.md +++ b/docs/P2_M1_PROGRESS.md @@ -1451,6 +1451,26 @@ XYZ、Fit 与 FitH/FitV 系列在本阶段覆盖,矩形视图见后续实现 - `checkpoint/receipt.json` 为 `9f43c57a440c25faf39f8faa2a1298e45f1e057f481ae818b81a38c60a224e27`。 - `related-tests.log` 为 `d9bb129201a3f82b4ce125bc31d69a5a9d0b30d69868022ccac05790bf852e45`。 +### TeX 诊断写入实际流 + +连接了 `\showstream`、`\show`、`\showthe`、`\showbox`、`\showlists`、 +`\showgroups` 和 `\showifs`。诊断读取当时的参数与流状态,通过原生文件 +写出路径写入实际打开的流。关闭后恢复常规日志及交互诊断。新增格式 +schema48,继续接受 schema47。活动列表使用真正的盒、段落、页面和 +贡献列表。活动数学、对齐、输出例程中的列表与页面插入类摘要仍待覆盖。 + +三份 pdfTeX INITEX 文件逐字节一致,覆盖开闭流、长行、8 位字符、真实 +分组和条件、空盒和负深度。另有实际横盒、纵盒与已构建页面的流输出 +逐字节相同,SHA-256 为 +47d243eaf8759f9b9e466f22c439ceb50276554ead5f67f231a72688899affe3。 +14项定向回归通过。检查点续编复用924步,重放前缀的第一次写入。修改 +第二次写入的值后,两份输出文件、PDF、SVG 和来源映射与独立全量一致。 +回执位于 target/p2-show-stream-native。 + +pdfTeX 兼容 profile 仍为1.40.22。下一项按原始 TFM 与虚拟字体位移补齐 +`\letterspacefont`,再用未修改的 LaTeX 后端核对版本分支。 +[TeX Live showstream.ch](https://github.com/TeX-Live/texlive-source/blob/trunk/texk/web2c/showstream.ch) + ### PDF 字面中的矩阵与来源映射 来源映射与 PDF 写入共用设备原点的取整。实际字面中的 `q`、`Q` 和 diff --git a/tests/native_generated_files.rs b/tests/native_generated_files.rs index ae30353..61a7a02 100644 --- a/tests/native_generated_files.rs +++ b/tests/native_generated_files.rs @@ -236,3 +236,29 @@ fn error_recovery_preserves_real_side_effect_ownership_and_recompiles() { ); fs::remove_dir_all(root).unwrap(); } + +#[test] +fn redirected_show_uses_the_open_stream_without_setting_the_cli_error_status() { + let root = directory(); + let oracle = directory(); + let entry = "show-stream.tex"; + let input = r"\catcode123=1\catcode125=2 +\immediate\openout5=report.dat +{\showstream=5\def\shown{ABC}\show\shown\showthe\count0\showlists} +\immediate\closeout5 +\end"; + fs::write(root.join(entry), input).unwrap(); + fs::write(oracle.join(entry), input).unwrap(); + let expected = reference(&oracle, entry); + let actual = native(&root, entry); + assert!(expected.status.success()); + assert!(actual.status.success(), "{actual:?}"); + assert_eq!( + fs::read(root.join("report.dat")).unwrap(), + fs::read(oracle.join("report.dat")).unwrap() + ); + let log = fs::read_to_string(root.join("job.log")).unwrap(); + assert!(!log.contains("> \\shown")); + fs::remove_dir_all(root).unwrap(); + fs::remove_dir_all(oracle).unwrap(); +}