Merge newline matrix-cap fix into prerequisite (#3297, #3328)

Keep the complete reviewed matrix bound together so main never receives the known newline-row bypass. This merge tree is identical to the validated #3328 head 83670dfe3a.
This commit is contained in:
FredApps committed 2026-11-08 12:33:22 +01:00
commit a2509bdf8b
1 file changed
+19 -2
+19 -2
View File
@@ -235,7 +235,7 @@ const MACRO_DEFINERS: &[&str] =
/// One open `\begin…\end` environment, counted from the source text.
struct Grid {
/// Rows ended so far (by `\\` or `\cr`).
/// Rows ended so far (by `\\`, `\cr` or `\newline`).
rows: usize,
/// Cells in the current row.
cells: usize,
@@ -315,7 +315,8 @@ fn check_caps(latex: &str) -> Result<(), MathError> {
}
None
}
"cr" => {
// RaTeX reads `\newline` as `\\`, so it ends a row like `\cr` does.
"cr" | "newline" => {
if let Some(g) = grids.last_mut() {
g.end_row();
}
@@ -801,4 +802,20 @@ mod tests {
let l = layout("").unwrap();
assert!(l.items.is_empty());
}
#[test]
fn newline_rows_count_toward_the_matrix_cap() {
// RaTeX reads `\newline` as `\\`, so it ends a row like `\cr` does.
for brk in ["\\newline ", "\\cr ", "\\\\"] {
let src = format!("\\begin{{matrix}}{}{}\\end{{matrix}}", format!("a{brk}").repeat(250), "a&".repeat(700) + "a");
assert!(src.len() < MAX_SOURCE_BYTES);
let e = check_caps(&src).unwrap_err();
assert!(e.message.contains("matrix cells"), "{brk}: {e}");
let s = src.clone();
let (l, o) = within(10, move || (layout(&s).unwrap_err(), to_omml(&s, 11.0, None).unwrap_err()));
assert!(l.message.contains("matrix cells") && o.message.contains("matrix cells"), "{brk}");
}
assert!(check_caps("\\begin{matrix}a&b\\newline c&d\\end{matrix}").is_ok());
assert!(layout("\\begin{matrix}a&b\\newline c&d\\end{matrix}").is_ok());
}
}