Expand the abstract environment

This commit is contained in:
gloamxun committed 2026-10-24 20:24:02 +08:00
1 parent 5ff94d8f92
commit b947f476da
4 files changed
+67 -4

No files matched your search

+63
View File
@@ -1061,6 +1061,58 @@ fn take_labels(text: &mut String) -> Vec<String> {
}
fn parse_blocks_raw(raw: &str) -> Vec<SourceParagraph> {
if let Some(body) = raw
.trim()
.strip_prefix("\\begin{abstract}")
.and_then(|rest| rest.strip_suffix("\\end{abstract}"))
{
let heading = SourceParagraph {
text: "Abstract".to_string(),
font: ParagraphFont::Bold,
line_height: 12,
math: false,
left_skip: 0,
centered: true,
right_aligned: false,
space_before: 12 * SCALE,
space_stretch: 0,
space_shrink: 0,
page_break: false,
equation_number: None,
equation_tag: None,
equation_rows: Vec::new(),
align_centered: false,
heading_level: None,
heading_starred: false,
heading_number: None,
font_size: Some((12.0 * SCALE as f64) as i64),
};
let body = SourceParagraph {
text: body.trim().to_string(),
font: ParagraphFont::Roman,
line_height: 12,
math: false,
left_skip: 0,
centered: false,
right_aligned: false,
space_before: 6 * SCALE,
space_stretch: 0,
space_shrink: 0,
page_break: false,
equation_number: None,
equation_tag: None,
equation_rows: Vec::new(),
align_centered: false,
heading_level: None,
heading_starred: false,
heading_number: None,
font_size: Some((9.0 * SCALE as f64) as i64),
};
if body.text.is_empty() {
return vec![heading];
}
return vec![heading, body];
}
for (environment, centered, right_aligned) in [
("center", true, false),
("flushleft", false, false),
@@ -2692,6 +2744,17 @@ mod source_tests {
assert_eq!(blocks[2].heading_number, None);
}
#[test]
fn abstract_environment_expands_into_a_heading_and_body() {
let blocks =
paragraphs("\\begin{abstract}\nShort summary.\n\\end{abstract}").expect("blocks");
assert_eq!(blocks.len(), 2);
assert_eq!(blocks[0].text, "Abstract");
assert!(blocks[0].centered);
assert_eq!(blocks[1].text, "Short summary.");
assert_eq!(blocks[1].font_size, Some((9.0 * SCALE as f64) as i64));
}
#[test]
fn headings_add_vertical_space_and_allow_short_titles() {
let blocks = paragraphs("\\section[Short]{Long title}").expect("blocks");