summaryrefslogtreecommitdiff
path: root/library/src/math
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-04-26 13:46:42 +0200
committerLaurenz <laurmaedje@gmail.com>2023-04-26 15:37:21 +0200
commit3680c854a21db665d64cdb8f31aa0f9a1af16ceb (patch)
tree39dfa33059293251f1e2890f9b3d0e3dc178ed03 /library/src/math
parent59957746e91c1322a8ca6d228bcaa0f31941ee1b (diff)
Touch up docs
Diffstat (limited to 'library/src/math')
-rw-r--r--library/src/math/attach.rs44
-rw-r--r--library/src/math/cancel.rs34
2 files changed, 52 insertions, 26 deletions
diff --git a/library/src/math/attach.rs b/library/src/math/attach.rs
index 34c24e17..e7cffdd3 100644
--- a/library/src/math/attach.rs
+++ b/library/src/math/attach.rs
@@ -2,16 +2,23 @@ use super::*;
/// A base with optional attachments.
///
-/// ## Syntax
-/// This function also has dedicated syntax for attachments after the base: Use the
-/// underscore (`_`) to indicate a subscript i.e. bottom attachment and the hat (`^`)
-/// to indicate a superscript i.e. top attachment.
-///
/// ## Example
/// ```example
+/// // With syntax.
/// $ sum_(i=0)^n a_i = 2^(1+i) $
+///
+/// // With function call.
+/// $ attach(
+/// Pi, t: alpha, b: beta,
+/// tl: 1, tr: 2, bl: 3, br: 4,
+/// ) $
/// ```
///
+/// ## Syntax
+/// This function also has dedicated syntax for attachments after the base: Use
+/// the underscore (`_`) to indicate a subscript i.e. bottom attachment and the
+/// hat (`^`) to indicate a superscript i.e. top attachment.
+///
/// Display: Attachment
/// Category: math
#[element(LayoutMath)]
@@ -21,41 +28,42 @@ pub struct AttachElem {
pub base: Content,
/// The top attachment, smartly positioned at top-right or above the base.
- /// Use limits() or scripts() on the base to override the smart positioning.
+ ///
+ /// You can wrap the base in `{limits()}` or `{scripts()}` to override the
+ /// smart positioning.
pub t: Option<Content>,
- /// The bottom attachment, smartly positioned at the bottom-right or below the base.
- /// Use limits() or scripts() on the base to override the smart positioning.
+ /// The bottom attachment, smartly positioned at the bottom-right or below
+ /// the base. You can wrap the base in `{limits()}` or `{scripts()}` to
+ /// override the smart positioning.
pub b: Option<Content>,
- /// The top-left attachment before the base.
+ /// The top-left attachment (before the base).
pub tl: Option<Content>,
- /// The bottom-left attachment before base.
+ /// The bottom-left attachment (before base).
pub bl: Option<Content>,
- /// The top-right attachment after the base.
+ /// The top-right attachment (after the base).
pub tr: Option<Content>,
- /// The bottom-right attachment after the base.
+ /// The bottom-right attachment (after the base).
pub br: Option<Content>,
}
-type GetAttachmentContent =
- fn(&AttachElem, styles: ::typst::model::StyleChain) -> Option<Content>;
-
impl LayoutMath for AttachElem {
#[tracing::instrument(skip(ctx))]
fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()> {
- let base = ctx.layout_fragment(&self.base())?;
-
- let getarg = |ctx: &mut MathContext, getter: GetAttachmentContent| {
+ type GetAttachment = fn(&AttachElem, styles: StyleChain) -> Option<Content>;
+ let getarg = |ctx: &mut MathContext, getter: GetAttachment| {
getter(self, ctx.styles())
.map(|elem| ctx.layout_fragment(&elem))
.transpose()
.unwrap()
};
+ let base = ctx.layout_fragment(&self.base())?;
+
ctx.style(ctx.style.for_superscript());
let arg_tl = getarg(ctx, Self::tl);
let arg_tr = getarg(ctx, Self::tr);
diff --git a/library/src/math/cancel.rs b/library/src/math/cancel.rs
index 0ea7b1d2..edc2ba1e 100644
--- a/library/src/math/cancel.rs
+++ b/library/src/math/cancel.rs
@@ -2,10 +2,14 @@ use super::*;
/// Displays a diagonal line over a part of an equation.
///
+/// This is commonly used to show the eliminiation of a term.
+///
/// ## Example
/// ```example
+/// >>> #set page(width: 140pt)
/// Here, we can simplify:
-/// $ (a dot.c b dot.c cancel(x)) / cancel(x) $
+/// $ (a dot b dot cancel(x)) /
+/// cancel(x) $
/// ```
///
/// Display: Cancel
@@ -23,18 +27,22 @@ pub struct CancelElem {
/// Defaults to `{100% + 3pt}`.
///
/// ```example
- /// $ a + cancel(x, length: #200%) - b - cancel(x, length: #200%) $
+ /// >>> #set page(width: 140pt)
+ /// $ a + cancel(x, length: #200%)
+ /// - cancel(x, length: #200%) $
/// ```
#[default(Rel::new(Ratio::one(), Abs::pt(3.0).into()))]
pub length: Rel<Length>,
- /// If the cancel line should be inverted (heading northwest instead of
- /// northeast).
+ /// If the cancel line should be inverted (pointing to the top left instead
+ /// of top right).
///
/// Defaults to `{false}`.
///
/// ```example
- /// $ (a cancel((b + c), inverted: #true)) / cancel(b + c, inverted: #true) $
+ /// >>> #set page(width: 140pt)
+ /// $ (a cancel((b + c), inverted: #true)) /
+ /// cancel(b + c, inverted: #true) $
/// ```
#[default(false)]
pub inverted: bool,
@@ -45,7 +53,8 @@ pub struct CancelElem {
/// Defaults to `{false}`.
///
/// ```example
- /// $ cancel(x, cross: #true) $
+ /// >>> #set page(width: 140pt)
+ /// $ cancel(Pi, cross: #true) $
/// ```
#[default(false)]
pub cross: bool,
@@ -54,7 +63,8 @@ pub struct CancelElem {
/// [line's documentation]($func/line.angle) for more details.
///
/// ```example
- /// $ cancel(x, rotation: #30deg) $
+ /// >>> #set page(width: 140pt)
+ /// $ cancel(Pi, rotation: #30deg) $
/// ```
#[default(Angle::zero())]
pub rotation: Angle,
@@ -63,7 +73,15 @@ pub struct CancelElem {
/// [line's documentation]($func/line.stroke) for more details.
///
/// ```example
- /// $ cancel(x, stroke: #{red + 1.5pt}) $
+ /// >>> #set page(width: 140pt)
+ /// $ cancel(
+ /// sum x,
+ /// stroke: #(
+ /// paint: red,
+ /// thickness: 1.5pt,
+ /// dash: "dashed",
+ /// ),
+ /// ) $
/// ```
#[resolve]
#[fold]