summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordamaxwell <damaxwell@alaska.edu>2023-07-19 23:47:29 -0800
committerGitHub <noreply@github.com>2023-07-20 09:47:29 +0200
commit6a396ae21410af5b265aa3174500146794d2b693 (patch)
tree82e74ca6e616ecdf147ed3e8eded710a3777c659
parent0e04d46e319cc60152952791f22ad9daf8354d11 (diff)
Center large operators on axis (#1735)
-rw-r--r--crates/typst-library/src/math/ctx.rs29
-rw-r--r--tests/ref/math/opticalsize.pngbin11318 -> 11317 bytes
2 files changed, 17 insertions, 12 deletions
diff --git a/crates/typst-library/src/math/ctx.rs b/crates/typst-library/src/math/ctx.rs
index e6a84674..4a0959ab 100644
--- a/crates/typst-library/src/math/ctx.rs
+++ b/crates/typst-library/src/math/ctx.rs
@@ -167,24 +167,29 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> {
{
// A single letter that is available in the math font.
match self.style.size {
- MathSize::Display => {
- let class = self.style.class.as_custom().or(glyph.class);
- if class == Some(MathClass::Large) {
- let height = scaled!(self, display_operator_min_height);
- glyph.stretch_vertical(self, height, Abs::zero()).into()
- } else {
- glyph.into()
- }
- }
MathSize::Script => {
glyph.make_scriptsize(self);
- glyph.into()
}
MathSize::ScriptScript => {
glyph.make_scriptscriptsize(self);
- glyph.into()
}
- _ => glyph.into(),
+ _ => (),
+ }
+
+ let class = self.style.class.as_custom().or(glyph.class);
+ if class == Some(MathClass::Large) {
+ let mut variant = if self.style.size == MathSize::Display {
+ let height = scaled!(self, display_operator_min_height);
+ glyph.stretch_vertical(self, height, Abs::zero())
+ } else {
+ glyph.into_variant()
+ };
+ // TeXbook p 155. Large operators are always vertically centered on the axis.
+ let h = variant.frame.height();
+ variant.frame.set_baseline(h / 2.0 + scaled!(self, axis_height));
+ variant.into()
+ } else {
+ glyph.into()
}
} else if text.chars().all(|c| c.is_ascii_digit()) {
// Numbers aren't that difficult.
diff --git a/tests/ref/math/opticalsize.png b/tests/ref/math/opticalsize.png
index 5c338ab6..905d3389 100644
--- a/tests/ref/math/opticalsize.png
+++ b/tests/ref/math/opticalsize.png
Binary files differ