diff --git a/src/render.rs b/src/render.rs index 37a775a..1a2a039 100644 --- a/src/render.rs +++ b/src/render.rs @@ -141,6 +141,17 @@ fn render_added_or_deleted(block: &Block, tag: DiffTag, out: &mut String) { ) .unwrap(); } + // A deleted equation must not take a number, or every later number + // shifts by one. The set rule is scoped to the wrapper. + Block::Equation { content, .. } if tag == DiffTag::Deleted => { + write!( + out, + "#{}[#set math.equation(numbering: none)\n{}]", + func, + escape_content(content, escape_refs) + ) + .unwrap(); + } // Raw blocks and equations are content-mode; they can be wrapped. Block::RawBlock { content } | Block::Equation { content, .. } => { write!(out, "#{}[{}]", func, escape_content(content, escape_refs)).unwrap(); diff --git a/tests/integration.rs b/tests/integration.rs index dacad43..c74501b 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -209,3 +209,13 @@ fn test_indented_line_comment_does_not_split_paragraph() { // A whitespace-only line would be treated as a paragraph break by Typst. assert!(!output.contains("\n \n")); } + +#[test] +fn test_deleted_equation_takes_no_number() { + let old = "#set math.equation(numbering: \"(1)\")\n\n$ y $\n\n$ z $ \n\nSee @eq-z.\n"; + let new = "#set math.equation(numbering: \"(1)\")\n\n$ z $ \n\nSee @eq-z.\n"; + let output = run_diff(old, new); + + // Numbered, the deleted equation would push `@eq-z` from (1) to (2). + assert!(output.contains("#diff-deleted[#set math.equation(numbering: none)\n$ y $]")); +}