summaryrefslogtreecommitdiff
path: root/crates/typst-utils/src
diff options
context:
space:
mode:
authorMalo <57839069+MDLC01@users.noreply.github.com>2025-01-31 11:05:03 +0100
committerGitHub <noreply@github.com>2025-01-31 10:05:03 +0000
commitf239b0a6a1e68a016cacf19eeef2df52e4affeb9 (patch)
tree101b8aeba40b8c9925d273894cfc27de2a4b5756 /crates/typst-utils/src
parent46727878da083eb8186373434997f5f7403cbb66 (diff)
Change the default math class of U+22A5 ⊥ UP TACK to Normal (#5714)
Diffstat (limited to 'crates/typst-utils/src')
-rw-r--r--crates/typst-utils/src/lib.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/crates/typst-utils/src/lib.rs b/crates/typst-utils/src/lib.rs
index b59fe2f7..34d6a943 100644
--- a/crates/typst-utils/src/lib.rs
+++ b/crates/typst-utils/src/lib.rs
@@ -31,6 +31,7 @@ use std::ops::{Add, Deref, Div, Mul, Neg, Sub};
use std::sync::Arc;
use siphasher::sip128::{Hasher128, SipHasher13};
+use unicode_math_class::MathClass;
/// Turn a closure into a struct implementing [`Debug`].
pub fn debug<F>(f: F) -> impl Debug
@@ -337,3 +338,28 @@ pub trait Numeric:
/// Whether `self` consists only of finite parts.
fn is_finite(self) -> bool;
}
+
+/// Returns the default math class of a character in Typst, if it has one.
+///
+/// This is determined by the Unicode math class, with some manual overrides.
+pub fn default_math_class(c: char) -> Option<MathClass> {
+ match c {
+ // Better spacing.
+ // https://github.com/typst/typst/commit/2e039cb052fcb768027053cbf02ce396f6d7a6be
+ ':' => Some(MathClass::Relation),
+
+ // Better spacing when used alongside + PLUS SIGN.
+ // https://github.com/typst/typst/pull/1726
+ '⋯' | '⋱' | '⋰' | '⋮' => Some(MathClass::Normal),
+
+ // Better spacing.
+ // https://github.com/typst/typst/pull/1855
+ '.' | '/' => Some(MathClass::Normal),
+
+ // ⊥ UP TACK should not be a relation, contrary to ⟂ PERPENDICULAR.
+ // https://github.com/typst/typst/pull/5714
+ '\u{22A5}' => Some(MathClass::Normal),
+
+ c => unicode_math_class::class(c),
+ }
+}