Honour explicit par paragraph breaks
An explicit \par inside a block stayed in the paragraph text and could leak as an unsupported command. The final body pass now turns a standalone \par token (not a \par... command prefix) into a blank line, so the block splitter starts a new paragraph at that point. A unit test feeds "First line.\par Second line." through geometry_and_body and checks it splits into two paragraphs.
This commit is contained in:
1 parent
1227d82f02
commit
dc9428e87e
4 files changed
+40
-6
No files matched your search
@@ -6446,6 +6446,7 @@ fn geometry_and_body_with_images(
|
||||
let today = today_string();
|
||||
body = expand_today(&body, &today);
|
||||
body = expand_lipsum(&body);
|
||||
body = expand_par_breaks(&body);
|
||||
// Class \maketitle definitions (arXiv, sn-jnl) issue \thispagestyle{empty}.
|
||||
if geometry.fancy_pagestyle && geometry.title.is_some() {
|
||||
geometry.suppress_first_page_header = true;
|
||||
@@ -6454,6 +6455,29 @@ fn geometry_and_body_with_images(
|
||||
(body, geometry)
|
||||
}
|
||||
|
||||
/// Turn an explicit `\par` token into a paragraph break.
|
||||
fn expand_par_breaks(body: &str) -> String {
|
||||
let mut output = String::with_capacity(body.len());
|
||||
let mut rest = body;
|
||||
while let Some(index) = rest.find("\\par") {
|
||||
let after = &rest[index + "\\par".len()..];
|
||||
let boundary = after
|
||||
.chars()
|
||||
.next()
|
||||
.is_none_or(|character| !character.is_ascii_alphabetic() && character != '@');
|
||||
output.push_str(&rest[..index]);
|
||||
if boundary {
|
||||
output.push_str("\n\n");
|
||||
rest = after;
|
||||
} else {
|
||||
output.push_str("\\par");
|
||||
rest = after;
|
||||
}
|
||||
}
|
||||
output.push_str(rest);
|
||||
output
|
||||
}
|
||||
|
||||
/// Remove a `thebibliography` environment from the body and return its
|
||||
/// `\bibitem{key}` entries in order.
|
||||
/// Start a new block when a display environment follows text on the same
|
||||
@@ -16890,6 +16914,16 @@ A definition.
|
||||
assert!(!text.contains("??"), "{text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_par_breaks_paragraphs() {
|
||||
let (body, geometry) = geometry_and_body("First line.\\par Second line.");
|
||||
let blocks = paragraphs(&body).expect("blocks");
|
||||
assert_eq!(blocks.len(), 2);
|
||||
assert_eq!(blocks[0].text.trim(), "First line.");
|
||||
assert_eq!(blocks[1].text.trim(), "Second line.");
|
||||
let _ = geometry;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inline_marks_set_the_running_head() {
|
||||
let source = "\\documentclass{article}\n\\pagestyle{fancy}\n\\fancyhf{}\n\\fancyhead[R]{\\rightmark}\n\\begin{document}\n\nBody \\markright{Short title} text.\n\n\\end{document}\n";
|
||||
|
||||
Reference in new issue
Block a user