Fall back to the current heading for fancy marks
Running heads expanded \leftmark/\rightmark only from explicit
\markboth/\markright, so a fancy header using \rightmark stayed empty when the
document never set a mark. Document now exposes the per-page heading list from
the previous increment, and running_head_text falls back to the current numbered
heading (uppercased) when no explicit left/right mark is configured.
A two-page test with \rhead{\rightmark} and a section checks "1 INTRODUCTION"
appears in the header with no warnings.
This commit is contained in:
1 parent
9da0f136a4
commit
1e4eb2d5ab
4 files changed
+41
-9
No files matched your search
+33
-2
@@ -13184,7 +13184,8 @@ fn stamp_running_heads(
|
||||
let Some(field) = field else {
|
||||
continue;
|
||||
};
|
||||
let text = running_head_text(field, geometry, &number);
|
||||
let page_heading = headings.get(index).and_then(|heading| heading.as_deref());
|
||||
let text = running_head_text(field, geometry, &number, page_heading);
|
||||
if text.is_empty() {
|
||||
continue;
|
||||
}
|
||||
@@ -13213,7 +13214,12 @@ fn stamp_running_heads(
|
||||
}
|
||||
}
|
||||
|
||||
fn running_head_text(field: &str, geometry: &PageGeometry, page_number: &str) -> String {
|
||||
fn running_head_text(
|
||||
field: &str,
|
||||
geometry: &PageGeometry,
|
||||
page_number: &str,
|
||||
page_heading: Option<&str>,
|
||||
) -> String {
|
||||
// Remove size/shape declarations before expanding macros: the class
|
||||
// redefines \footnotesize in terms of itself, and expanding it would
|
||||
// repeat \@setfontsize internals on every pass.
|
||||
@@ -13245,9 +13251,13 @@ fn running_head_text(field: &str, geometry: &PageGeometry, page_number: &str) ->
|
||||
text = text.replace("\\thepage", page_number);
|
||||
if let Some(left) = &geometry.running_left {
|
||||
text = text.replace("\\leftmark", left);
|
||||
} else if let Some(title) = page_heading {
|
||||
text = text.replace("\\leftmark", &title.to_uppercase());
|
||||
}
|
||||
if let Some(right) = &geometry.running_right {
|
||||
text = text.replace("\\rightmark", right);
|
||||
} else if let Some(title) = page_heading {
|
||||
text = text.replace("\\rightmark", &title.to_uppercase());
|
||||
}
|
||||
if let Some(title) = geometry.title.as_deref() {
|
||||
text = text.replace("\\@title", title);
|
||||
@@ -16787,6 +16797,27 @@ A definition.
|
||||
assert!(!text.contains("??"), "{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";
|
||||
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"]
|
||||
);
|
||||
assert_eq!(value["pageCount"].as_u64(), Some(2));
|
||||
let texts = svg_texts(&json);
|
||||
let header = texts
|
||||
.iter()
|
||||
.find(|(text, _, _)| text == "1 INTRODUCTION")
|
||||
.expect("right header");
|
||||
assert!(header.1 > 200.0, "header should be right-aligned");
|
||||
assert!(header.2 < 0.0, "header should sit above the body");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn headings_pagestyle_puts_the_number_in_the_header() {
|
||||
let source = "\\documentclass{article}\n\\pagestyle{headings}\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