Draw the rule body of fbox figures
Parse the first non-zero \rule{width}{height} in a figure without a decoded
image and use it as the float dimensions, so the arXiv sample gets its black
rule body instead of a caption-only float. The fbox frame and vector images are
still unsupported.
This changes the arXiv corpus preview to 3 pages, matching TeX; update the
corpus expectation. Test count stays 1073.
This commit is contained in:
1 parent
5c281d70cc
commit
c5bf150449
2 files changed
+30
-2
No files matched your search
+29
-1
@@ -8335,8 +8335,12 @@ fn float_block(raw: &str) -> Option<SourceParagraph> {
|
|||||||
}
|
}
|
||||||
caption = Some(text);
|
caption = Some(text);
|
||||||
}
|
}
|
||||||
let (width, height, image, scale, keep_aspectratio) =
|
let (mut width, mut height, image, scale, keep_aspectratio) =
|
||||||
figure_graphic(inner).unwrap_or((None, None, None, None, false));
|
figure_graphic(inner).unwrap_or((None, None, None, None, false));
|
||||||
|
if let Some((rule_width, rule_height)) = figure_rule(inner) {
|
||||||
|
width = width.or(Some(rule_width));
|
||||||
|
height = height.or(Some(rule_height));
|
||||||
|
}
|
||||||
let table = embedded_table(inner);
|
let table = embedded_table(inner);
|
||||||
Some(SourceParagraph {
|
Some(SourceParagraph {
|
||||||
width: None,
|
width: None,
|
||||||
@@ -8489,6 +8493,30 @@ fn figure_graphic(
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A figure whose body is a `\rule` rather than an image (the arXiv sample
|
||||||
|
/// uses `\fbox{\rule...}`). Return the first non-zero rule dimensions.
|
||||||
|
fn figure_rule(inner: &str) -> Option<(ImageLength, ImageLength)> {
|
||||||
|
let index = inner.find("\\rule")?;
|
||||||
|
let after = inner[index + "\\rule".len()..].trim_start();
|
||||||
|
let after = if let Some(raise) = after.strip_prefix('[') {
|
||||||
|
raise
|
||||||
|
.split_once(']')
|
||||||
|
.map(|(_, tail)| tail.trim_start())
|
||||||
|
.unwrap_or(after)
|
||||||
|
} else {
|
||||||
|
after
|
||||||
|
};
|
||||||
|
let (width, used) = braced_group(after)?;
|
||||||
|
let after = after[used..].trim_start();
|
||||||
|
let (height, _) = braced_group(after)?;
|
||||||
|
let width = parse_dimension(width.trim())?;
|
||||||
|
let height = parse_dimension(height.trim())?;
|
||||||
|
if width == 0 || height == 0 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
Some((ImageLength::Absolute(width), ImageLength::Absolute(height)))
|
||||||
|
}
|
||||||
|
|
||||||
/// Parse `width=`/`height=` values: dimensions, fractions of the measure, or
|
/// Parse `width=`/`height=` values: dimensions, fractions of the measure, or
|
||||||
/// fractions of the text height.
|
/// fractions of the text height.
|
||||||
fn parse_image_length(value: &str) -> Option<ImageLength> {
|
fn parse_image_length(value: &str) -> Option<ImageLength> {
|
||||||
|
|||||||
+1
-1
@@ -2535,7 +2535,7 @@ fn corpus_documents_preview_without_warnings() {
|
|||||||
"examples/hello.tex" => 1,
|
"examples/hello.tex" => 1,
|
||||||
"examples/boxes.tex" => 1,
|
"examples/boxes.tex" => 1,
|
||||||
"examples/compat.tex" => 1,
|
"examples/compat.tex" => 1,
|
||||||
"fixtures/arxiv-template/template.tex" => 2,
|
"fixtures/arxiv-template/template.tex" => 3,
|
||||||
other => panic!("unexpected corpus document {other}"),
|
other => panic!("unexpected corpus document {other}"),
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|||||||
Reference in new issue
Block a user