diff --git a/crates/formats/src/latex.rs b/crates/formats/src/latex.rs index cc2157268..aec04c740 100644 --- a/crates/formats/src/latex.rs +++ b/crates/formats/src/latex.rs @@ -1669,11 +1669,12 @@ fn parse_color(model: Option<&str>, spec: &str) -> Option { /// A TeX length in points (`3cm`, `0.4\linewidth`), if it is one. fn length_pt(s: &str) -> Option { - let s = s.trim(); + let s = s.trim().strip_prefix('+').unwrap_or(s.trim()); let split = s.find(|c: char| !(c.is_ascii_digit() || c == '.' || c == '-')).unwrap_or(s.len()); let (n, unit) = s.split_at(split); let n: f32 = if n.is_empty() { 1.0 } else { n.parse().ok()? }; - let k = match unit.trim() { + let unit = unit.trim().to_ascii_lowercase(); + let k = match unit.as_str() { "pt" => 1.0, "bp" => 72.27 / 72.0, "in" => 72.27, @@ -2804,6 +2805,16 @@ mod tests { assert!(widths.len() <= wordcraft_doc::table::MAX_COLS); } + #[test] + fn latex_length_pt_case_and_plus() { + assert_eq!(length_pt("12pt"), Some(12.0)); + assert_eq!(length_pt("12PT"), Some(12.0)); + assert_eq!(length_pt("+12pt"), Some(12.0)); + assert_eq!(length_pt("1IN"), Some(72.27)); + assert_eq!(length_pt("+2cm"), Some(56.9)); + assert_eq!(length_pt("0.5\\TEXTWIDTH"), Some(LINE_WIDTH * 0.5)); + } + const ARTICLE: &str = r#"\documentclass[11pt]{article} \usepackage[utf8]{inputenc} \usepackage{amsmath} % maths