summaryrefslogtreecommitdiff
path: root/crates/typst-library/src
diff options
context:
space:
mode:
authortingerrr <me@tinger.dev>2023-10-17 11:48:46 +0200
committerGitHub <noreply@github.com>2023-10-17 11:48:46 +0200
commit372476323f8d415b92b11b3970b8120838a2ef2d (patch)
tree765806f144e9d99e0794e2a06acc63ddb3f938d2 /crates/typst-library/src
parent80175db3975e52adefd62e2b966764afb8a981ce (diff)
Add `reverse` parameter to `cases` (#2370)
Diffstat (limited to 'crates/typst-library/src')
-rw-r--r--crates/typst-library/src/math/matrix.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/crates/typst-library/src/math/matrix.rs b/crates/typst-library/src/math/matrix.rs
index 1dee5434..91310ed3 100644
--- a/crates/typst-library/src/math/matrix.rs
+++ b/crates/typst-library/src/math/matrix.rs
@@ -270,6 +270,15 @@ pub struct CasesElem {
#[default(Delimiter::Brace)]
pub delim: Delimiter,
+ /// Whether the direction of cases should be reversed.
+ ///
+ /// ```example
+ /// #set math.cases(reverse: true)
+ /// $ cases(1, 2) = x $
+ /// ```
+ #[default(false)]
+ pub reverse: bool,
+
/// The gap between branches.
///
/// ```example
@@ -295,7 +304,14 @@ impl LayoutMath for CasesElem {
FixedAlign::Start,
self.gap(ctx.styles()),
)?;
- layout_delimiters(ctx, frame, Some(delim.open()), None, self.span())
+
+ let (open, close) = if self.reverse(ctx.styles()) {
+ (None, Some(delim.close()))
+ } else {
+ (Some(delim.open()), None)
+ };
+
+ layout_delimiters(ctx, frame, open, close, self.span())
}
}