summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeedehai <18319900+Leedehai@users.noreply.github.com>2023-05-11 11:38:04 -0400
committerGitHub <noreply@github.com>2023-05-11 17:38:04 +0200
commite8de8a49c57671854f657a4eb1e2d86e5b12a281 (patch)
tree6b7104a9d11c6988009ae63232098d2aed4d91ab
parentd1dec299a7a9957bc9797e0afe4c6a6636d4455c (diff)
Adjust attach() per TeXbook Appendix G 18a (#1129)
-rw-r--r--library/src/math/attach.rs26
-rw-r--r--tests/ref/bugs/math-realize.pngbin23272 -> 21147 bytes
-rw-r--r--tests/ref/math/accent.pngbin29997 -> 7994 bytes
-rw-r--r--tests/ref/math/attach.pngbin21307 -> 27297 bytes
-rw-r--r--tests/ref/math/frac.pngbin24948 -> 21679 bytes
-rw-r--r--tests/ref/math/matrix.pngbin10694 -> 10167 bytes
-rw-r--r--tests/ref/math/multiline.pngbin13475 -> 13698 bytes
-rw-r--r--tests/ref/math/numbering.pngbin14239 -> 12028 bytes
-rw-r--r--tests/ref/math/root.pngbin12986 -> 12274 bytes
-rw-r--r--tests/ref/math/spacing.pngbin17743 -> 17745 bytes
-rw-r--r--tests/ref/math/style.pngbin23494 -> 19747 bytes
-rw-r--r--tests/ref/meta/figure.pngbin63931 -> 54464 bytes
-rw-r--r--tests/typ/math/attach.typ10
13 files changed, 34 insertions, 2 deletions
diff --git a/library/src/math/attach.rs b/library/src/math/attach.rs
index e4fad470..f9ac4aa0 100644
--- a/library/src/math/attach.rs
+++ b/library/src/math/attach.rs
@@ -299,6 +299,7 @@ fn compute_shifts_up_and_down(
let mut shift_up = Abs::zero();
let mut shift_down = Abs::zero();
+ let is_char_box = is_character_box(base);
for e in [tl, tr].into_iter().flatten() {
let ascent = match &base {
@@ -308,13 +309,13 @@ fn compute_shifts_up_and_down(
shift_up = shift_up
.max(sup_shift_up)
- .max(ascent - sup_drop_max)
+ .max(if is_char_box { Abs::zero() } else { ascent - sup_drop_max })
.max(sup_bottom_min + e.descent());
}
for e in [bl, br].into_iter().flatten() {
shift_down = shift_down
.max(sub_shift_down)
- .max(base.descent() + sub_drop_min)
+ .max(if is_char_box { Abs::zero() } else { base.descent() + sub_drop_min })
.max(e.ascent() - sub_top_max);
}
@@ -339,6 +340,27 @@ fn compute_shifts_up_and_down(
(shift_up, shift_down)
}
+/// Whether the fragment consists of a single character or atomic piece of text.
+fn is_character_box(fragment: &MathFragment) -> bool {
+ match fragment {
+ MathFragment::Glyph(_) | MathFragment::Variant(_) => {
+ fragment.class() != Some(MathClass::Large)
+ }
+ MathFragment::Frame(fragment) => is_atomic_text_frame(&fragment.frame),
+ _ => false,
+ }
+}
+
+/// Handles e.g. "sin", "log", "exp", "CustomOperator".
+fn is_atomic_text_frame(frame: &Frame) -> bool {
+ // Meta information isn't visible or renderable, so we exclude it.
+ let mut iter = frame
+ .items()
+ .map(|(_, item)| item)
+ .filter(|item| !matches!(item, FrameItem::Meta(_, _)));
+ matches!(iter.next(), Some(FrameItem::Text(_))) && iter.next().is_none()
+}
+
/// Unicode codepoints that should have sub- and superscripts attached as limits.
#[rustfmt::skip]
const LIMITS: &[char] = &[
diff --git a/tests/ref/bugs/math-realize.png b/tests/ref/bugs/math-realize.png
index c4824403..4f5b887e 100644
--- a/tests/ref/bugs/math-realize.png
+++ b/tests/ref/bugs/math-realize.png
Binary files differ
diff --git a/tests/ref/math/accent.png b/tests/ref/math/accent.png
index a324d3f0..11de9e28 100644
--- a/tests/ref/math/accent.png
+++ b/tests/ref/math/accent.png
Binary files differ
diff --git a/tests/ref/math/attach.png b/tests/ref/math/attach.png
index e65a1691..9a32b64c 100644
--- a/tests/ref/math/attach.png
+++ b/tests/ref/math/attach.png
Binary files differ
diff --git a/tests/ref/math/frac.png b/tests/ref/math/frac.png
index 58d8ef89..6f0e8139 100644
--- a/tests/ref/math/frac.png
+++ b/tests/ref/math/frac.png
Binary files differ
diff --git a/tests/ref/math/matrix.png b/tests/ref/math/matrix.png
index f74384a3..9e357146 100644
--- a/tests/ref/math/matrix.png
+++ b/tests/ref/math/matrix.png
Binary files differ
diff --git a/tests/ref/math/multiline.png b/tests/ref/math/multiline.png
index a5e53bc7..ae847434 100644
--- a/tests/ref/math/multiline.png
+++ b/tests/ref/math/multiline.png
Binary files differ
diff --git a/tests/ref/math/numbering.png b/tests/ref/math/numbering.png
index 8ccb3ac6..6256310f 100644
--- a/tests/ref/math/numbering.png
+++ b/tests/ref/math/numbering.png
Binary files differ
diff --git a/tests/ref/math/root.png b/tests/ref/math/root.png
index b7d2807d..8a6a6e13 100644
--- a/tests/ref/math/root.png
+++ b/tests/ref/math/root.png
Binary files differ
diff --git a/tests/ref/math/spacing.png b/tests/ref/math/spacing.png
index 94ca9b98..d15d6607 100644
--- a/tests/ref/math/spacing.png
+++ b/tests/ref/math/spacing.png
Binary files differ
diff --git a/tests/ref/math/style.png b/tests/ref/math/style.png
index 46d72662..f4a42c70 100644
--- a/tests/ref/math/style.png
+++ b/tests/ref/math/style.png
Binary files differ
diff --git a/tests/ref/meta/figure.png b/tests/ref/meta/figure.png
index 35d7b4a0..4969e5a0 100644
--- a/tests/ref/meta/figure.png
+++ b/tests/ref/meta/figure.png
Binary files differ
diff --git a/tests/typ/math/attach.typ b/tests/typ/math/attach.typ
index 070b9eca..1649ae02 100644
--- a/tests/typ/math/attach.typ
+++ b/tests/typ/math/attach.typ
@@ -69,6 +69,16 @@ $ sqrt(a_(1/2)^zeta), sqrt(a_alpha^(1/2)), sqrt(a_(1/2)^(3/4)) \
$ (-1)^n + (1/2 + 3)^(-1/2) $
---
+#set text(size: 8pt)
+
+// Test that the attachments are aligned horizontally.
+$ x_1 p_1 frak(p)_1 2_1 dot_1 lg_1 !_1 \\_1 ]_1 "ip"_1 op("iq")_1 \
+ x^1 b^1 frak(b)^1 2^1 dot^1 lg^1 !^1 \\^1 ]^1 "ib"^1 op("id")^1 \
+ x_1 y_1 "_"_1 x^1 l^1 "`"^1 attach(I,tl:1,bl:1,tr:1,br:1)
+ scripts(sum)_1^1 integral_1^1 |1/2|_1^1 \
+ x^1_1, "("b y")"^1_1 != (b y)^1_1, "[∫]"_1 [integral]_1 $
+
+---
// Test limit.
$ lim_(n->oo \ n "grows") sum_(k=0 \ k in NN)^n k $