Close proof bodies with a QED symbol

A proof environment stopped at its last body line, without the boxed QED mark
LaTeX's amsthm draws. Proof bodies now get a trailing "□" (an explicit
\qedhere is consumed first), so the rendered result matches the usual proof
ending.

A preview test wraps "Because it follows." in a proof and checks the text ends
with the symbol and no warnings are reported.
This commit is contained in:
gloamxun committed 2026-10-27 02:48:52 +08:00
1 parent 1e4eb2d5ab
commit 48e86fb214
4 files changed
+35 -6

No files matched your search

+29
View File
@@ -8194,6 +8194,14 @@ fn theorem_block(raw: &str, definitions: &[TheoremDefinition]) -> Option<Vec<Sou
if body.is_empty() {
return None;
}
if name == "proof" {
if let Some(stripped) = body.strip_suffix("\\qedhere") {
body = stripped.trim().to_string();
}
if !body.ends_with('□') {
body.push_str(" □");
}
}
let heading_text = match (name.as_str(), title.as_deref()) {
("proof", Some(title)) => format!("{title}."),
_ => format!("{display}."),
@@ -16797,6 +16805,27 @@ A definition.
assert!(!text.contains("??"), "{text}");
}
#[test]
fn proof_bodies_end_with_a_qed_symbol() {
let source = "\\documentclass{article}\n\\begin{document}\n\n\\begin{proof}\nBecause it follows.\n\\end{proof}\n\n\\end{document}\n";
let json = preview_json(source).expect("preview");
let value: serde_json::Value = serde_json::from_str(&json).expect("JSON");
assert_eq!(
value["warnings"].as_array().map(Vec::len),
Some(0),
"{}",
value["warnings"]
);
let svg = value["pages"][0]["svg"].as_str().expect("svg");
let text: String = svg
.split('>')
.filter_map(|piece| piece.split('<').next())
.collect::<String>()
.split_whitespace()
.collect();
assert!(text.contains("Becauseitfollows.□"), "{text}");
}
#[test]
fn fancy_headers_track_the_current_heading_per_page() {
let source = "\\documentclass{article}\n\\pagestyle{fancy}\n\\fancyhf{}\n\\rhead{\\rightmark}\n\\begin{document}\n\n\\section{Introduction}\n\nFirst.\n\n\\newpage\n\nSecond.\n\n\\end{document}\n";