diff --git a/crates/texrra-tex-core/src/math.rs b/crates/texrra-tex-core/src/math.rs index 88f67e1..26eee9b 100755 --- a/crates/texrra-tex-core/src/math.rs +++ b/crates/texrra-tex-core/src/math.rs @@ -624,6 +624,22 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) { | "csc" | "exp" | "det" | "dim" | "ker" | "hom" | "arg" | "deg" | "gcd" => { (MathAtom::Text(command.clone()), next) } + "mathcal" | "mathbb" | "mathbf" | "mathit" | "mathsf" | "mathtt" | "mathfrak" + | "mathnormal" => { + let mut after = next; + if chars.get(after) == Some(&'{') { + after += 1; + } + let start = after; + while after < chars.len() && chars[after] != '}' { + after += 1; + } + let text: String = chars[start..after].iter().collect(); + if after < chars.len() { + after += 1; + } + (MathAtom::Text(text), after) + } "text" | "mathrm" => { let mut after = next; if chars.get(after) == Some(&'{') { @@ -730,6 +746,14 @@ mod tests { assert!(indexed.height > plain.height); } + #[test] + fn mathcal_keeps_character_widths() { + let font = Cmr10Metrics::default(); + let calligraphic = layout_math(&parse_math("\\mathcal{N}"), &font); + let upright = layout_math(&parse_math("\\mathrm{N}"), &font); + assert_eq!(calligraphic.width, upright.width); + assert_eq!(calligraphic.height, upright.height); + } #[test] fn sum_places_scripts_above_and_below() { let font = Cmr10Metrics::default(); diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index 14f69b8..8f19393 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -124,6 +124,9 @@ a single cost function. - `MathAtom::Binomial { numerator, denominator }` parses `\binom{n}{k}` / `\dbinom` / `\tbinom`; layout stacks the arguments with a 4pt delimiter allowance. +- `\mathcal`, `\mathbb`, `\mathbf`, `\mathit`, `\mathsf`, `\mathtt`, + `\mathfrak`, `\mathnormal` parse their argument as upright `Text` for metrics; + visual alphabet selection waits for the NFSS math font layer. - Named operators (`\max`, `\min`, `\sin`, `\log`, `\det`, ...) parse as upright `Text` atoms. - `MathAtom::Underline { base }` parses `\underline{...}` and adds 2pt depth