Report float and equation pages through pageref
This commit is contained in:
1 parent
aa072f58d8
commit
e039cfb8a9
3 files changed
+42
-3
No files matched your search
@@ -9580,6 +9580,36 @@ fn build_document_with_labels(
|
||||
label_units.insert(label.clone(), *unit);
|
||||
}
|
||||
}
|
||||
let figure_name = geometry.figure_name.as_deref().unwrap_or("Figure");
|
||||
let table_name = geometry.table_name.as_deref().unwrap_or("Table");
|
||||
for (label, number) in &references {
|
||||
if label_units.contains_key(label) {
|
||||
continue;
|
||||
}
|
||||
let figure_caption = format!("{figure_name} {number}:");
|
||||
let table_caption = format!("{table_name} {number}:");
|
||||
if let Some(index) = paragraphs.iter().position(|paragraph| {
|
||||
paragraph
|
||||
.float
|
||||
.as_ref()
|
||||
.and_then(|spec| spec.caption.as_deref())
|
||||
.is_some_and(|caption| {
|
||||
caption.starts_with(&figure_caption) || caption.starts_with(&table_caption)
|
||||
})
|
||||
}) {
|
||||
label_units.insert(label.clone(), unit_for_paragraph[index] as u64);
|
||||
continue;
|
||||
}
|
||||
if let Some(index) = paragraphs.iter().position(|paragraph| {
|
||||
paragraph
|
||||
.equation_number
|
||||
.map(|value| value.to_string())
|
||||
.as_deref()
|
||||
== Some(number.as_str())
|
||||
}) {
|
||||
label_units.insert(label.clone(), unit_for_paragraph[index] as u64);
|
||||
}
|
||||
}
|
||||
for (index, paragraph) in paragraphs.iter().enumerate() {
|
||||
if let (Some(level), Some(_)) = (paragraph.heading_level, paragraph.heading_number.as_ref())
|
||||
{
|
||||
@@ -10802,6 +10832,14 @@ a & b
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pageref_reports_the_page_of_a_float() {
|
||||
let source = "\\pagestyle{empty}\n\n\\begin{figure}[h]\n\\rule{10pt}{10pt}\n\\caption{Cap}\n\\label{fig:a}\n\\end{figure}\n\n\\newpage\n\nSee page \\pageref{fig:a}.";
|
||||
let json = preview_json(source).expect("preview");
|
||||
assert!(!json.contains("??"), "unresolved pageref: {json}");
|
||||
assert!(!json.contains("pageref"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_pagerefs_print_question_marks() {
|
||||
let json =
|
||||
@@ -11161,6 +11199,7 @@ Second page.
|
||||
assert!(json.contains("\"warnings\":[]"), "warnings: {}", json);
|
||||
assert!(json.contains(">O</text>"));
|
||||
assert!(json.contains(">C</text>"));
|
||||
assert!(!json.contains("??"), "unresolved references: {}", json);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user