Put the page number in the header for headings style
\pagestyle{headings} and {myheadings} were ignored, leaving the number in the
footer. The parser now records the headings styles; the running-head pass paints
a right-aligned 9pt page number at the head baseline on pages after the first
(LaTeX's plain first page), and the footer number is skipped for those styles.
Section titles in the header are still not modelled.
A two-page preview test checks "2" sits above the body on page 2, right-aligned
past x=400, with no warnings.
This commit is contained in:
1 parent
9f642a2bbd
commit
22d5332658
4 files changed
+63
-9
No files matched your search
+57
-3
@@ -216,6 +216,8 @@ struct PageGeometry {
|
||||
suppress_first_page_number: bool,
|
||||
/// `\pagestyle{fancy}` turns on the fancyhdr fields below.
|
||||
fancy_pagestyle: bool,
|
||||
/// `\pagestyle{headings}` / `{myheadings}` puts the number in the head.
|
||||
headings_pagestyle: bool,
|
||||
/// `\thispagestyle{empty}` suppresses the running head on the first page.
|
||||
suppress_first_page_header: bool,
|
||||
header_left: Option<String>,
|
||||
@@ -3570,6 +3572,11 @@ fn strip_page_geometry(
|
||||
if rest.trim_start().starts_with("{empty}") {
|
||||
geometry.suppress_page_numbers = true;
|
||||
}
|
||||
if rest.trim_start().starts_with("{headings}")
|
||||
|| rest.trim_start().starts_with("{myheadings}")
|
||||
{
|
||||
geometry.headings_pagestyle = true;
|
||||
}
|
||||
} else if let Some(rest) = trimmed.strip_prefix("\\thispagestyle") {
|
||||
if rest.trim_start().starts_with("{empty}") {
|
||||
geometry.suppress_first_page_number = true;
|
||||
@@ -7227,7 +7234,7 @@ pub fn pdf_bytes_with_images(
|
||||
list
|
||||
})
|
||||
.collect();
|
||||
if !geometry.suppress_page_numbers {
|
||||
if !geometry.suppress_page_numbers && !geometry.headings_pagestyle {
|
||||
let style = geometry.page_numbering.as_deref().unwrap_or("arabic");
|
||||
stamp_page_numbers(
|
||||
&mut pages,
|
||||
@@ -13088,7 +13095,29 @@ fn stamp_running_heads(
|
||||
text_width: i64,
|
||||
paper_height: i64,
|
||||
) {
|
||||
if !geometry.fancy_pagestyle || geometry.suppress_page_numbers {
|
||||
if (!geometry.fancy_pagestyle && !geometry.headings_pagestyle) || geometry.suppress_page_numbers
|
||||
{
|
||||
return;
|
||||
}
|
||||
if geometry.headings_pagestyle && !geometry.fancy_pagestyle {
|
||||
let head_sep = geometry.head_sep.unwrap_or(25 * SCALE);
|
||||
let baseline = -head_sep;
|
||||
let style = geometry.page_numbering.as_deref().unwrap_or("arabic");
|
||||
for (index, list) in lists.iter_mut().enumerate() {
|
||||
if index == 0 {
|
||||
// LaTeX's headings style uses plain on the first page.
|
||||
continue;
|
||||
}
|
||||
let number = page_number_text(index, style, geometry.page_start);
|
||||
let width = text_width_roman(&number);
|
||||
list.push(DisplayItem::Text {
|
||||
x: (text_width - width).max(0),
|
||||
y: baseline,
|
||||
size: 9 * SCALE,
|
||||
text: number,
|
||||
font: FontFace::Roman,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
let head_sep = geometry.head_sep.unwrap_or(25 * SCALE);
|
||||
@@ -13501,7 +13530,7 @@ fn render_json(
|
||||
list.items.extend(frames);
|
||||
}
|
||||
}
|
||||
if !geometry.suppress_page_numbers {
|
||||
if !geometry.suppress_page_numbers && !geometry.headings_pagestyle {
|
||||
let style = geometry.page_numbering.as_deref().unwrap_or("arabic");
|
||||
stamp_page_numbers(
|
||||
&mut lists,
|
||||
@@ -16693,6 +16722,31 @@ A definition.
|
||||
assert!(!svg.contains("numberwithin"), "{svg}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn headings_pagestyle_puts_the_number_in_the_header() {
|
||||
let source = "\\documentclass{article}\n\\pagestyle{headings}\n\\begin{document}\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 number = texts
|
||||
.iter()
|
||||
.find(|(text, _, _)| text == "2")
|
||||
.expect("header page number");
|
||||
let body = texts
|
||||
.iter()
|
||||
.find(|(text, _, _)| text == "S")
|
||||
.expect("body letter");
|
||||
assert!(number.2 < body.2, "number should sit above the body");
|
||||
assert!(number.1 > 400.0, "number should be right-aligned");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bibitem_optional_labels_replace_the_number() {
|
||||
let source = "\\documentclass{article}\n\\begin{document}\n\nSee \\cite{a} and \\cite{b}.\n\n\\begin{thebibliography}{9}\n\\bibitem[Author(2020)]{a} Alpha entry.\n\\bibitem{b} Beta entry.\n\\end{thebibliography}\n\n\\end{document}\n";
|
||||
|
||||
Reference in new issue
Block a user