Use short headings in running heads
A section's optional [short] title already replaced the long title in the table
of contents, but the running heads kept the long title. When recording heading
units, the document now prefers heading_short (with its number) and falls back
to the rendered heading text, so headings/myheadings and the fancy \rightmark
fallback show the short form.
A headings-style test with \section[Short]{A long title} checks the header says
"1 SHORT" and not the long title.
This commit is contained in:
1 parent
0e386f8fdc
commit
3df130a6b3
4 files changed
+37
-7
No files matched your search
+31
-1
@@ -13300,9 +13300,17 @@ fn build_document_with_labels(
|
||||
if paragraph.heading_level.is_some()
|
||||
&& let Some(unit) = unit_for_paragraph.get(index)
|
||||
{
|
||||
let title = if let Some(short) = paragraph.heading_short.as_deref() {
|
||||
match paragraph.heading_number.as_deref() {
|
||||
Some(number) => format!("{number} {short}"),
|
||||
None => short.to_string(),
|
||||
}
|
||||
} else {
|
||||
paragraph.text.clone()
|
||||
};
|
||||
document
|
||||
.headings
|
||||
.push((*unit as u64, scrub_title_metadata(¶graph.text)));
|
||||
.push((*unit as u64, scrub_title_metadata(&title)));
|
||||
}
|
||||
}
|
||||
if footnote_count > 0 {
|
||||
@@ -17116,6 +17124,28 @@ A definition.
|
||||
assert!(text.contains("D"), "{text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn heading_headers_use_the_short_title() {
|
||||
let source = "\\documentclass{article}\n\\pagestyle{headings}\n\\begin{document}\n\n\\section[Short]{A long title}\n\nFirst.\n\n\\newpage\n\nSecond.\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 texts = svg_texts(&json);
|
||||
assert!(
|
||||
texts.iter().any(|(text, _, _)| text == "1 SHORT"),
|
||||
"{texts:?}"
|
||||
);
|
||||
assert!(
|
||||
!texts.iter().any(|(text, _, _)| text == "1 A LONG TITLE"),
|
||||
"{texts:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn myheadings_use_only_explicit_marks() {
|
||||
let source = "\\documentclass{article}\n\\pagestyle{myheadings}\n\\markright{Custom mark}\n\\begin{document}\n\n\\section{Introduction}\n\nFirst.\n\n\\newpage\n\nSecond.\n\n\\end{document}\n";
|
||||
|
||||
Reference in new issue
Block a user