From c3c19cc91738ae68bbec33b23834a54df23c0e53 Mon Sep 17 00:00:00 2001 From: Simon Koch-Sultan <126534658+scks1@users.noreply.github.com> Date: Mon, 16 Nov 2026 11:54:29 -0500 Subject: [PATCH] craft-latex: a starred line break shows no star `\\*` is a line break that also forbids a page break after it. The lexer read `\\` as the control symbol and left the `*` as text, so `a\\*b` showed `a`, a line break, then `*b`, `\\*[3pt]` showed `*[3pt]`, and in a tabular the next row's first cell started with `*`. The lexer now takes the star with `\\`, so the parser and the tabular reader see the line break they already handle, with its optional spacing argument. --- crates/latex/src/lex.rs | 8 ++++++++ crates/latex/src/tests.rs | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/crates/latex/src/lex.rs b/crates/latex/src/lex.rs index 711adb551..f68721a52 100644 --- a/crates/latex/src/lex.rs +++ b/crates/latex/src/lex.rs @@ -136,6 +136,14 @@ impl Lexer<'_> { let m = self.until("\\]"); self.out.push(Tok::Math(m, true)); } + '\\' => { + // `\\*` breaks the line as `\\` does; the star only forbids a page + // break there. + if self.peek() == Some('*') { + self.bump(); + } + self.out.push(Tok::Cmd(sym.to_string())); + } _ => self.out.push(Tok::Cmd(sym.to_string())), } continue; diff --git a/crates/latex/src/tests.rs b/crates/latex/src/tests.rs index ccf349c80..2946367d9 100644 --- a/crates/latex/src/tests.rs +++ b/crates/latex/src/tests.rs @@ -437,3 +437,17 @@ fn a_tabular_row_keeps_the_cells_a_table_row_holds() { assert_eq!(t.rows.first().map(Vec::len), Some(craft_wordmodel::table::MAX_COLS)); assert_eq!(t.rows.get(1).map(Vec::len), Some(2)); } + +#[test] +fn a_starred_line_break_shows_no_star() { + // `\\*` (a line break with no page break after it) left its `*` in the text. + for src in ["a\\\\*b", "a\\\\*[3pt]b", "a\\\\b"] { + let p = paras(&format!("\\begin{{document}}{src}\\end{{document}}")); + assert_eq!(p.len(), 1, "{src}"); + assert_eq!(p[0].text().replace(['\n', '\u{B}'], "|"), "a|b", "{src}"); + } + let flow = parse("\\begin{document}\\begin{tabular}{ll}a & b \\\\* c & d\\end{tabular}\\end{document}"); + let Some(FBlock::Table(t)) = flow.blocks.first() else { panic!("{:?}", flow.blocks) }; + assert_eq!(t.rows.len(), 2, "{t:?}"); + assert_eq!(t.rows[1].iter().map(|c| c.text().trim().to_string()).collect::>(), ["c", "d"]); +}