Add Fraktur letters, infix fractions and middle delimiters

- bundle eufm10 (TFM + Type1), add the MathFraktur face and map \mathfrak
  onto it, including PDF embedding and width lookup;
- parse TeX's infix fractions (\over, \atop, \choose, \brace,
  \brack, \overwithdelims, \atopwithdelims): the rest of the current
  row becomes the denominator, ar records whether a rule is drawn, and the
  painter no longer emits parentheses (a \frac painter bug) and only draws
  the bar for \over forms;
- add MathAtom::Middle, size top-level middle delimiters with the enclosing
  \left/\right group through the CMEX size classes, and paint
  SizedDelimiter at its selected size instead of the base glyph;
- skip the parser's '\u{0}' math spaces before \big, \middle,
  \left and the withdelims delimiters, so \big ( parses like \big(.

560 workspace tests (381 route-D unit).
This commit is contained in:
texrra committed 2026-10-24 12:28:33 +08:00
1 parent cb40cc4634
commit 8c42f2de2f
10 files changed
+499 -72

No files matched your search

+50 -28
View File
@@ -27,6 +27,8 @@ pub enum FontFace {
MathExtension,
/// Computer Modern blackboard bold (`msbm10`).
MathBlackboard,
/// Euler Fraktur (`eufm10`).
MathFraktur,
}
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -700,6 +702,7 @@ impl Page {
math::MathAlphabet::Mono => FontFace::Mono,
math::MathAlphabet::Calligraphic => FontFace::MathSymbol,
math::MathAlphabet::Blackboard => FontFace::MathBlackboard,
math::MathAlphabet::Fraktur => FontFace::MathFraktur,
};
let mut cursor = x;
for character in text.chars() {
@@ -774,41 +777,37 @@ impl Page {
MathAtom::Fraction {
numerator,
denominator,
bar,
} => {
let num = math::layout_math(numerator, font);
let den = math::layout_math(denominator, font);
let width = num.width.max(den.width);
let bracket = (size as f64 * 1.2) as i64;
let inner_x = x + (width - num.width) / 2 + 2 * 65_536;
Self::paint_math(numerator, font, inner_x, baseline - 8 * 65_536, size, list);
let clearance = 2 * 65_536;
let rule_width = num.width.max(den.width) + clearance;
let bar_y = baseline - clearance;
if *bar {
list.push(DisplayItem::Rule {
x,
y: bar_y,
width: rule_width,
height: 26_214,
});
}
Self::paint_math(
denominator,
numerator,
font,
x + (width - den.width) / 2 + 2 * 65_536,
baseline + 12 * 65_536,
x + (rule_width - num.width) / 2,
bar_y - clearance - num.depth,
size,
list,
);
Self::paint_math(
denominator,
font,
x + (rule_width - den.width) / 2,
bar_y + clearance + den.height,
size,
list,
);
list.push(DisplayItem::Text {
font: FontFace::Roman,
x,
y: baseline,
size: bracket,
text: "(".to_string(),
});
list.push(DisplayItem::Text {
font: FontFace::Roman,
x: x + width + 4 * 65_536,
y: baseline,
size: bracket,
text: ")".to_string(),
});
list.push(DisplayItem::Rule {
x,
y: baseline - 2 * 65_536,
width,
height: 26_214,
});
}
MathAtom::Sqrt { radicand, degree } => {
let box_ = math::layout_math(radicand, font);
@@ -1095,7 +1094,30 @@ impl Page {
}
}
}
MathAtom::SizedDelimiter { delimiter, .. } => {
MathAtom::SizedDelimiter {
delimiter,
size: step,
} => {
let base_extent = font.height(*delimiter) + font.depth(*delimiter);
let extent = crate::cmr10::cmex_delimiter(*delimiter, *step)
.map(|(_, height, depth)| height + depth);
let (glyph_size, shift) = match extent {
Some(extent) if base_extent > 0 && extent > base_extent => {
let scale = extent as f64 / base_extent as f64;
let glyph_size = (size as f64 * scale) as i64;
(glyph_size, ((glyph_size - size) as f64 * 0.35) as i64)
}
_ => (size, 0),
};
list.push(DisplayItem::Text {
font: FontFace::Roman,
x,
y: baseline + shift,
size: glyph_size,
text: delimiter.to_string(),
});
}
MathAtom::Middle(delimiter) => {
list.push(DisplayItem::Text {
font: FontFace::Roman,
x,