Map boldsymbol to the bold math alphabet

\boldsymbol and \bm were unknown math commands, so a bold symbol fell back to
the default layout. Both names now select the same bold alphabet as \mathbf;
symbol-heavy arguments still use the regular symbol metrics, which is the
existing alphabet approximation.

A math test compares \boldsymbol{x} with \mathbf{x} for equal width and height.
This commit is contained in:
gloamxun committed 2026-10-27 03:15:16 +08:00
1 parent 3df130a6b3
commit 8307fc8918
3 files changed
+15 -6

No files matched your search

+12 -3
View File
@@ -2469,8 +2469,8 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
| "exp" | "det" | "dim" | "ker" | "hom" | "arg" | "deg" | "gcd" => {
(MathAtom::Text(command.clone()), next)
}
"mathcal" | "mathbb" | "mathbf" | "mathit" | "mathsf" | "mathtt" | "mathfrak"
| "mathnormal" => {
"mathcal" | "mathbb" | "mathbf" | "boldsymbol" | "bm" | "mathit" | "mathsf"
| "mathtt" | "mathfrak" | "mathnormal" => {
let mut after = next;
if chars.get(after) == Some(&'{') {
after += 1;
@@ -2487,7 +2487,7 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
after += 1;
}
let alphabet = match command.as_str() {
"mathbf" => Some(MathAlphabet::Bold),
"mathbf" | "boldsymbol" | "bm" => Some(MathAlphabet::Bold),
"mathit" => Some(MathAlphabet::Italic),
"mathsf" => Some(MathAlphabet::Sans),
"mathtt" => Some(MathAlphabet::Mono),
@@ -3469,6 +3469,15 @@ mod tests {
assert_eq!(plain.width, styled.width);
assert_eq!(plain.height, styled.height);
}
#[test]
fn boldsymbol_maps_to_the_bold_alphabet() {
let font = Cmr10Metrics::default();
let bold = layout_math(&parse_math("\\boldsymbol{x}"), &font);
let mathbf = layout_math(&parse_math("\\mathbf{x}"), &font);
assert_eq!(bold.width, mathbf.width);
assert_eq!(bold.height, mathbf.height);
}
#[test]
fn binom_stacks_two_arguments() {
let font = Cmr10Metrics::default();