summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbluebear94 <uruwi@protonmail.com>2023-07-06 03:37:19 -0400
committerGitHub <noreply@github.com>2023-07-06 09:37:19 +0200
commita4756d8576199eaee7cc82ed2a15689d94617798 (patch)
tree4714641a592d29f74e341ec9214e49e20419aa40
parent5bdad06d9202ab2af728778ab84acc385c439c64 (diff)
Add support for weak elements in math (#1633)
-rw-r--r--crates/typst-library/src/math/mod.rs5
-rw-r--r--crates/typst-library/src/math/op.rs2
-rw-r--r--tests/ref/math/frac.pngbin24117 -> 28719 bytes
-rw-r--r--tests/typ/math/frac.typ5
4 files changed, 11 insertions, 1 deletions
diff --git a/crates/typst-library/src/math/mod.rs b/crates/typst-library/src/math/mod.rs
index 0429265f..f1676b91 100644
--- a/crates/typst-library/src/math/mod.rs
+++ b/crates/typst-library/src/math/mod.rs
@@ -47,6 +47,7 @@ use crate::meta::{
Count, Counter, CounterUpdate, LocalName, Numbering, Outlinable, Refable,
};
use crate::prelude::*;
+use crate::shared::BehavedBuilder;
use crate::text::{
families, variant, FontFamily, FontList, LinebreakElem, SpaceElem, TextElem, TextSize,
};
@@ -414,7 +415,11 @@ impl LayoutMath for Content {
}
if let Some(children) = self.to_sequence() {
+ let mut bb = BehavedBuilder::new();
for child in children {
+ bb.push(child.clone(), StyleChain::default());
+ }
+ for (child, _) in bb.finish().0.iter() {
child.layout_math(ctx)?;
}
return Ok(());
diff --git a/crates/typst-library/src/math/op.rs b/crates/typst-library/src/math/op.rs
index 8ad74c49..d2c62452 100644
--- a/crates/typst-library/src/math/op.rs
+++ b/crates/typst-library/src/math/op.rs
@@ -60,7 +60,7 @@ macro_rules! ops {
);)*
let dif = |d| {
- HElem::new(THIN.into()).pack()
+ HElem::new(THIN.into()).with_weak(true).pack()
+ MathStyleElem::new(TextElem::packed(d)).with_italic(Some(false)).pack()
};
math.define("dif", dif('d'));
diff --git a/tests/ref/math/frac.png b/tests/ref/math/frac.png
index 80327578..adb9ad0c 100644
--- a/tests/ref/math/frac.png
+++ b/tests/ref/math/frac.png
Binary files differ
diff --git a/tests/typ/math/frac.typ b/tests/typ/math/frac.typ
index dc120ec3..f3c31070 100644
--- a/tests/typ/math/frac.typ
+++ b/tests/typ/math/frac.typ
@@ -21,6 +21,11 @@ $ binom(circle, square) $
$ binom(x^2) $
---
+// Test dif.
+$ (dif y)/(dif x), dif/x, x/dif, dif/dif \
+ frac(dif y, dif x), frac(dif, x), frac(x, dif), frac(dif, dif) $
+
+---
// Test associativity.
$ 1/2/3 = (1/2)/3 = 1/(2/3) $