Parse math alphabet wrappers as text metrics
This commit is contained in:
1 parent
6465915dc1
commit
40af634efd
2 files changed
+27
No files matched your search
@@ -624,6 +624,22 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
|
|||||||
| "csc" | "exp" | "det" | "dim" | "ker" | "hom" | "arg" | "deg" | "gcd" => {
|
| "csc" | "exp" | "det" | "dim" | "ker" | "hom" | "arg" | "deg" | "gcd" => {
|
||||||
(MathAtom::Text(command.clone()), next)
|
(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" => {
|
"text" | "mathrm" => {
|
||||||
let mut after = next;
|
let mut after = next;
|
||||||
if chars.get(after) == Some(&'{') {
|
if chars.get(after) == Some(&'{') {
|
||||||
@@ -730,6 +746,14 @@ mod tests {
|
|||||||
assert!(indexed.height > plain.height);
|
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]
|
#[test]
|
||||||
fn sum_places_scripts_above_and_below() {
|
fn sum_places_scripts_above_and_below() {
|
||||||
let font = Cmr10Metrics::default();
|
let font = Cmr10Metrics::default();
|
||||||
|
|||||||
@@ -124,6 +124,9 @@ a single cost function.
|
|||||||
- `MathAtom::Binomial { numerator, denominator }` parses
|
- `MathAtom::Binomial { numerator, denominator }` parses
|
||||||
`\binom{n}{k}` / `\dbinom` / `\tbinom`; layout stacks the arguments with a
|
`\binom{n}{k}` / `\dbinom` / `\tbinom`; layout stacks the arguments with a
|
||||||
4pt delimiter allowance.
|
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
|
- Named operators (`\max`, `\min`, `\sin`, `\log`, `\det`, ...) parse as
|
||||||
upright `Text` atoms.
|
upright `Text` atoms.
|
||||||
- `MathAtom::Underline { base }` parses `\underline{...}` and adds 2pt depth
|
- `MathAtom::Underline { base }` parses `\underline{...}` and adds 2pt depth
|
||||||
|
|||||||
Reference in new issue
Block a user