diff --git a/src/route_d.rs b/src/route_d.rs index 2bb378a..22ef0e8 100755 --- a/src/route_d.rs +++ b/src/route_d.rs @@ -8335,8 +8335,12 @@ fn float_block(raw: &str) -> Option { } 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)); + 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); Some(SourceParagraph { 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 /// fractions of the text height. fn parse_image_length(value: &str) -> Option { diff --git a/tests/server.rs b/tests/server.rs index 26aaac1..c81c323 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -2535,7 +2535,7 @@ fn corpus_documents_preview_without_warnings() { "examples/hello.tex" => 1, "examples/boxes.tex" => 1, "examples/compat.tex" => 1, - "fixtures/arxiv-template/template.tex" => 2, + "fixtures/arxiv-template/template.tex" => 3, other => panic!("unexpected corpus document {other}"), }; assert_eq!(