typst/tests/suite/math/stretch.typ
mkorje 3506ef446d
Allow a function as an argument to size in stretch and lr
Previously there was always a short fall when scaling delimiters, even if
the user requested a specific size. This is no longer the case; the short
fall is only present in the default for `lr` (`x => x - 0.1em`), and is
the reason for the updated tests - the size of the delimiters is now
actually what was specified in the size argument. This also makes the
default for `lr` much clearer to the user.

A slight hack was used by exploiting the `name` property in the `func`
attribute macro so that the default value in the docs for `lr.size` would
clearly show what the default function was (instead of just its name
`default_lr_size` which is meaningless and inaccessible to the user).
2025-04-25 22:14:57 +10:00

100 lines
2.9 KiB
Typst

// Test math stretch.
--- math-stretch-basic ---
// Test basic stretch.
$ P -> Q stretch(->, size: #200%) R \
R stretch(->) S stretch(->, size: #50%)^"epimorphism" T $
--- math-stretch-complex ---
// Test complex stretch.
$ H stretch(=)^"define" U + p V \
x stretch(harpoons.ltrb, size: #3em) y
stretch(\[, size: #150%) z \
f : X stretch(arrow.hook, size: #150%)_"injective" Y \
V stretch(->, size: #(100% + 1.5em))^("surjection") ZZ $
--- math-stretch-horizontal-attach ---
// Test horizontal stretch interactions with attachments.
#set page(width: auto)
$stretch(stretch(=, size: #4em))_A$
$stretch(arrow.hook, size: #5em)^"injective map"$
$stretch(arrow.hook, size: #200%)^"injective map"$
$ P = Q
stretch(=)^(k = 0)_(forall i) R
stretch(=, size: #150%)^(k = 0)_(forall i) S
stretch(=, size: #2mm)^(k = 0)_(forall i) T \
U stretch(equiv)^(forall i)_"Chern-Weil" V
stretch(equiv, size: #(120% + 2mm))^(forall i)_"Chern-Weil" W $
--- math-stretch-vertical-attach ---
// Test vertical stretch interactions with attachments.
$arrow.t$
$stretch(arrow.t)^"map"$
$stretch(arrow.t, size: #2em)^"map"$
$stretch(arrow.t, size: #200%)^"map"$
--- math-stretch-vertical-scripts ---
// Test vertical stretch interactions with script attachments.
#let big = $stretch(|, size: #4em)$
$ big_0^1 stretch(|, size: #1.5em)_0^1
stretch(big, size: #1em)_0^1 |_0^1 $
--- math-stretch-horizontal ---
// Test stretching along horizontal axis.
#let ext(sym) = math.stretch(sym, size: 2em)
$ ext(arrow.r) quad ext(arrow.l.double.bar) \
ext(harpoon.rb) quad ext(harpoons.ltrb) \
ext(paren.t) quad ext(shell.b) \
ext(eq) quad ext(equiv) $
--- math-stretch-vertical ---
// Test stretching along vertical axis.
#let ext(sym) = math.stretch(sym, size: 2em)
$ ext(bar.v) quad ext(bar.v.double) quad
ext(angle.l) quad ext(angle.r) quad
ext(paren.l) quad ext(paren.r) \
ext(bracket.l.double) quad ext(bracket.r.double) quad
ext(brace.l) quad ext(brace.r) quad
ext(bracket.l) quad ext(bracket.r) $
--- math-stretch-shorthand ---
// Test stretch when base is given with shorthand.
$stretch(||, size: #2em)$
$stretch(\(, size: #2em)$
$stretch(, size: #2em)$
$stretch(|, size: #2em)$
$stretch(->, size: #2em)$
$stretch(, size: #2em)$
--- math-stretch-nested ---
// Test nested stretch calls.
$ stretch(=, size: #2em) \
stretch(stretch(=, size: #4em), size: #50%) $
#let base = math.stretch($=$, size: 4em)
$ stretch(base, size: #50%) $
#let base = $stretch(=, size: #4em) $
$ stretch(base, size: #50%) $
--- math-stretch-attach-nested-equation ---
// Test stretching with attachments when nested in an equation.
#let body = $stretch(=)$
$ body^"text" $
#{
let body = $stretch(=)$
for i in range(24) {
body = $body$
}
$body^"long text"$
}
--- math-stretch-function ---
// Test using a function as an argument to size.
$stretch(<-, size: #(x => x - 0.5em))_"function"$
#set math.stretch(size: x => x + 0.5em)
$stretch(|) |$