Parse named math operators as upright text
This commit is contained in:
1 parent
b11fc864f2
commit
639f5e8f8b
2 files changed
+17
No files matched your search
@@ -421,6 +421,10 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
|
|||||||
let delimiter = chars.get(next).copied().unwrap_or('|');
|
let delimiter = chars.get(next).copied().unwrap_or('|');
|
||||||
(MathAtom::Symbol(delimiter), next + 1)
|
(MathAtom::Symbol(delimiter), next + 1)
|
||||||
}
|
}
|
||||||
|
"max" | "min" | "lim" | "log" | "ln" | "sin" | "cos" | "tan" | "cot" | "sec"
|
||||||
|
| "csc" | "exp" | "det" | "dim" | "ker" | "hom" | "arg" | "deg" | "gcd" => {
|
||||||
|
(MathAtom::Text(command.clone()), next)
|
||||||
|
}
|
||||||
"text" | "mathrm" => {
|
"text" | "mathrm" => {
|
||||||
let mut after = next;
|
let mut after = next;
|
||||||
if chars.get(after) == Some(&'{') {
|
if chars.get(after) == Some(&'{') {
|
||||||
@@ -527,6 +531,17 @@ mod tests {
|
|||||||
assert!(indexed.height > plain.height);
|
assert!(indexed.height > plain.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn named_operators_use_upright_text_widths() {
|
||||||
|
let font = Cmr10Metrics::default();
|
||||||
|
let max = layout_math(&parse_math("\\max"), &font);
|
||||||
|
let single = layout_math(&parse_math("m"), &font);
|
||||||
|
assert!(max.width > single.width);
|
||||||
|
assert!(matches!(
|
||||||
|
&parse_math("\\max"),
|
||||||
|
MathAtom::Row(atoms) if matches!(&atoms[0], MathAtom::Text(text) if text == "max")
|
||||||
|
));
|
||||||
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn underline_adds_depth_without_changing_width() {
|
fn underline_adds_depth_without_changing_width() {
|
||||||
let font = Cmr10Metrics::default();
|
let font = Cmr10Metrics::default();
|
||||||
|
|||||||
@@ -110,6 +110,8 @@ a single cost function.
|
|||||||
- `MathAtom::Accent { accent, base }` parses `\hat`, `\widehat`,
|
- `MathAtom::Accent { accent, base }` parses `\hat`, `\widehat`,
|
||||||
`\tilde`, `\widetilde`, `\bar`, `\overline` and `\vec`; it adds
|
`\tilde`, `\widetilde`, `\bar`, `\overline` and `\vec`; it adds
|
||||||
accent height without changing the base width.
|
accent height without changing the base width.
|
||||||
|
- Named operators (`\max`, `\min`, `\sin`, `\log`, `\det`, ...) parse as
|
||||||
|
upright `Text` atoms.
|
||||||
- `MathAtom::Underline { base }` parses `\underline{...}` and adds 2pt depth
|
- `MathAtom::Underline { base }` parses `\underline{...}` and adds 2pt depth
|
||||||
without changing width or height.
|
without changing width or height.
|
||||||
- `MathAtom::Text(String)` parses `\text{...}` and `\mathrm{...}`;
|
- `MathAtom::Text(String)` parses `\text{...}` and `\mathrm{...}`;
|
||||||
|
|||||||
Reference in new issue
Block a user