summaryrefslogtreecommitdiff
path: root/library/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-02-02 14:13:56 +0100
committerLaurenz <laurmaedje@gmail.com>2023-02-02 14:13:56 +0100
commit5f5c65927982447133b625edea3f5c9bab4f9e3d (patch)
treeaa5edb320e21466d16a1d15ad320d164f94738db /library/src
parent21dd99926a24d7cc69bf6b032d1107c78a04a5cf (diff)
Math tests
Diffstat (limited to 'library/src')
-rw-r--r--library/src/math/ctx.rs2
-rw-r--r--library/src/math/delimited.rs (renamed from library/src/math/lr.rs)0
-rw-r--r--library/src/math/frac.rs4
-rw-r--r--library/src/math/fragment.rs4
-rw-r--r--library/src/math/matrix.rs2
-rw-r--r--library/src/math/mod.rs10
-rw-r--r--library/src/math/root.rs4
-rw-r--r--library/src/math/row.rs10
-rw-r--r--library/src/math/spacing.rs7
-rw-r--r--library/src/math/style.rs4
-rw-r--r--library/src/math/underover.rs (renamed from library/src/math/stack.rs)0
11 files changed, 25 insertions, 22 deletions
diff --git a/library/src/math/ctx.rs b/library/src/math/ctx.rs
index fafb96f2..d682746e 100644
--- a/library/src/math/ctx.rs
+++ b/library/src/math/ctx.rs
@@ -23,7 +23,7 @@ macro_rules! percent {
}
/// The context for math layout.
-pub(super) struct MathContext<'a, 'b, 'v> {
+pub struct MathContext<'a, 'b, 'v> {
pub vt: &'v mut Vt<'b>,
pub regions: Regions<'a>,
pub font: &'a Font,
diff --git a/library/src/math/lr.rs b/library/src/math/delimited.rs
index cdd5718c..cdd5718c 100644
--- a/library/src/math/lr.rs
+++ b/library/src/math/delimited.rs
diff --git a/library/src/math/frac.rs b/library/src/math/frac.rs
index ebdb5c02..9f7fb9d0 100644
--- a/library/src/math/frac.rs
+++ b/library/src/math/frac.rs
@@ -1,5 +1,7 @@
use super::*;
+const FRAC_AROUND: Em = Em::new(0.1);
+
/// # Fraction
/// A mathematical fraction.
///
@@ -130,7 +132,7 @@ fn layout(
let denom = ctx.layout_frame(denom)?;
ctx.unstyle();
- let around = Em::new(0.1).scaled(ctx);
+ let around = FRAC_AROUND.scaled(ctx);
let num_gap = (shift_up - axis - num.descent()).max(num_min + thickness / 2.0);
let denom_gap = (shift_down + axis - denom.ascent()).max(denom_min + thickness / 2.0);
diff --git a/library/src/math/fragment.rs b/library/src/math/fragment.rs
index fe9642a2..bef3f578 100644
--- a/library/src/math/fragment.rs
+++ b/library/src/math/fragment.rs
@@ -1,7 +1,7 @@
use super::*;
#[derive(Debug, Clone)]
-pub(super) enum MathFragment {
+pub enum MathFragment {
Glyph(GlyphFragment),
Variant(VariantFragment),
Frame(FrameFragment),
@@ -118,7 +118,7 @@ impl From<Frame> for MathFragment {
}
#[derive(Debug, Clone, Copy)]
-pub(super) struct GlyphFragment {
+pub struct GlyphFragment {
pub id: GlyphId,
pub c: char,
pub lang: Lang,
diff --git a/library/src/math/matrix.rs b/library/src/math/matrix.rs
index 527cf315..5f448901 100644
--- a/library/src/math/matrix.rs
+++ b/library/src/math/matrix.rs
@@ -1,7 +1,7 @@
use super::*;
const ROW_GAP: Em = Em::new(0.5);
-const COL_GAP: Em = Em::new(0.75);
+const COL_GAP: Em = Em::new(0.5);
const VERTICAL_PADDING: Ratio = Ratio::new(0.1);
/// # Vector
diff --git a/library/src/math/mod.rs b/library/src/math/mod.rs
index ab1fab13..4e60faca 100644
--- a/library/src/math/mod.rs
+++ b/library/src/math/mod.rs
@@ -5,29 +5,29 @@ mod ctx;
mod accent;
mod align;
mod attach;
+mod delimited;
mod frac;
mod fragment;
-mod lr;
mod matrix;
mod op;
mod root;
mod row;
mod spacing;
-mod stack;
mod stretch;
mod style;
mod symbols;
+mod underover;
pub use self::accent::*;
pub use self::align::*;
pub use self::attach::*;
+pub use self::delimited::*;
pub use self::frac::*;
-pub use self::lr::*;
pub use self::matrix::*;
pub use self::op::*;
pub use self::root::*;
-pub use self::stack::*;
pub use self::style::*;
+pub use self::underover::*;
use ttf_parser::{GlyphId, Rect};
use typst::font::Font;
@@ -230,7 +230,7 @@ impl Layout for FormulaNode {
impl Inline for FormulaNode {}
#[capability]
-trait LayoutMath {
+pub trait LayoutMath {
fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()>;
}
diff --git a/library/src/math/root.rs b/library/src/math/root.rs
index d348ecc1..2d27bb11 100644
--- a/library/src/math/root.rs
+++ b/library/src/math/root.rs
@@ -1,5 +1,7 @@
use super::*;
+const MIN_INDEX_SHIFT: Em = Em::new(0.35);
+
/// # Square Root
/// A square root.
///
@@ -126,7 +128,7 @@ fn layout(
if let Some(index) = &index {
sqrt_offset = kern_before + index.width() + kern_after;
- shift_up.set_max(index.descent() + Em::new(0.35).scaled(ctx));
+ shift_up.set_max(index.descent() + MIN_INDEX_SHIFT.scaled(ctx));
ascent.set_max(shift_up + index.ascent());
}
diff --git a/library/src/math/row.rs b/library/src/math/row.rs
index d971ce22..e66fc18e 100644
--- a/library/src/math/row.rs
+++ b/library/src/math/row.rs
@@ -2,8 +2,10 @@ use crate::layout::AlignNode;
use super::*;
+pub const TIGHT_LEADING: Em = Em::new(0.25);
+
#[derive(Debug, Default, Clone)]
-pub(super) struct MathRow(pub Vec<MathFragment>);
+pub struct MathRow(pub Vec<MathFragment>);
impl MathRow {
pub fn new() -> Self {
@@ -85,8 +87,12 @@ impl MathRow {
) -> Frame {
if self.0.iter().any(|frag| matches!(frag, MathFragment::Linebreak)) {
let fragments = std::mem::take(&mut self.0);
+ let leading = if ctx.style.size >= MathSize::Text {
+ ctx.styles().get(ParNode::LEADING)
+ } else {
+ TIGHT_LEADING.scaled(ctx)
+ };
- let leading = ctx.styles().get(ParNode::LEADING) * ctx.style.size.factor(ctx);
let rows: Vec<_> = fragments
.split(|frag| matches!(frag, MathFragment::Linebreak))
.map(|slice| Self(slice.to_vec()))
diff --git a/library/src/math/spacing.rs b/library/src/math/spacing.rs
index 7083c5e1..fad1c863 100644
--- a/library/src/math/spacing.rs
+++ b/library/src/math/spacing.rs
@@ -24,11 +24,8 @@ pub(super) fn spacing(
) -> Em {
use MathClass::*;
let script = style.size <= MathSize::Script;
- let (Some(l), Some(r)) = (left.class(), right.class()) else {
- return ZERO;
- };
-
- match (l, r) {
+ let class = |frag: &MathFragment| frag.class().unwrap_or(Special);
+ match (class(left), class(right)) {
// No spacing before punctuation; thin spacing after punctuation, unless
// in script size.
(_, Punctuation) => ZERO,
diff --git a/library/src/math/style.rs b/library/src/math/style.rs
index b3f3d8df..da2e2313 100644
--- a/library/src/math/style.rs
+++ b/library/src/math/style.rs
@@ -443,10 +443,6 @@ pub(super) fn styled_char(style: MathStyle, c: char) -> char {
'∂' | 'ϵ' | 'ϑ' | 'ϰ' | 'ϕ' | 'ϱ' | 'ϖ'
));
- if c == '-' {
- return '−';
- }
-
if let Some(c) = latin_exception(c, variant, bold, italic) {
return c;
}
diff --git a/library/src/math/stack.rs b/library/src/math/underover.rs
index 3a47059c..3a47059c 100644
--- a/library/src/math/stack.rs
+++ b/library/src/math/underover.rs