mirror of
https://github.com/typst/typst
synced 2025-05-13 12:36:23 +08:00
Math documentation improvements
This commit is contained in:
parent
d9d2c021d6
commit
196d9594fb
@ -29,19 +29,22 @@ const ACCENT_SHORT_FALL: Em = Em::new(0.5);
|
|||||||
/// The accent to apply to the base.
|
/// The accent to apply to the base.
|
||||||
///
|
///
|
||||||
/// Supported accents include:
|
/// Supported accents include:
|
||||||
/// - Grave: `grave`, `` ` ``
|
///
|
||||||
/// - Acute: `acute`, `´`
|
/// | Accent | Name | Codepoint |
|
||||||
/// - Circumflex: `circum`, `^`
|
/// | ------------ | --------------- | --------- |
|
||||||
/// - Tilde: `tilde`, `~`
|
/// | Grave | `grave` | <code>`</code> |
|
||||||
/// - Macron: `macron`, `¯`
|
/// | Acute | `acute` | `´` |
|
||||||
/// - Breve: `breve`, `˘`
|
/// | Circumflex | `circum` | `^` |
|
||||||
/// - Dot: `dot`, `.`
|
/// | Tilde | `tilde` | `~` |
|
||||||
/// - Diaeresis: `diaer` `¨`
|
/// | Macron | `macron` | `¯` |
|
||||||
/// - Circle: `circle`, `∘`
|
/// | Breve | `breve` | `˘` |
|
||||||
/// - Double acute: `acute.double`, `˝`
|
/// | Dot | `dot` | `.` |
|
||||||
/// - Caron: `caron`, `ˇ`
|
/// | Diaeresis | `diaer` | `¨` |
|
||||||
/// - Right arrow: `arrow`, `->`
|
/// | Circle | `circle` | `∘` |
|
||||||
/// - Left arrow: `arrow.l`, `<-`
|
/// | Double acute | `acute.double` | `˝` |
|
||||||
|
/// | Caron | `caron` | `ˇ` |
|
||||||
|
/// | Right arrow | `arrow`, `->` | `→` |
|
||||||
|
/// | Left arrow | `arrow.l`, `<-` | `←` |
|
||||||
///
|
///
|
||||||
/// ## Category
|
/// ## Category
|
||||||
/// math
|
/// math
|
||||||
|
@ -3,7 +3,7 @@ use super::*;
|
|||||||
/// How much less high scaled delimiters can be than what they wrap.
|
/// How much less high scaled delimiters can be than what they wrap.
|
||||||
pub(super) const DELIM_SHORT_FALL: Em = Em::new(0.1);
|
pub(super) const DELIM_SHORT_FALL: Em = Em::new(0.1);
|
||||||
|
|
||||||
/// # Left-Right
|
/// # Left/Right
|
||||||
/// Scales delimiters.
|
/// Scales delimiters.
|
||||||
///
|
///
|
||||||
/// While matched delimiters scale by default, this can be used to scale
|
/// While matched delimiters scale by default, this can be used to scale
|
||||||
|
@ -7,6 +7,8 @@ const VERTICAL_PADDING: Ratio = Ratio::new(0.1);
|
|||||||
/// # Vector
|
/// # Vector
|
||||||
/// A column vector.
|
/// A column vector.
|
||||||
///
|
///
|
||||||
|
/// Content in the vector's elements can be aligned with the `&` symbol.
|
||||||
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
/// ```
|
/// ```
|
||||||
/// $ vec(a, b, c) dot vec(1, 2, 3)
|
/// $ vec(a, b, c) dot vec(1, 2, 3)
|
||||||
@ -51,15 +53,35 @@ impl LayoutMath for VecNode {
|
|||||||
/// # Matrix
|
/// # Matrix
|
||||||
/// A matrix.
|
/// A matrix.
|
||||||
///
|
///
|
||||||
|
/// The elements of a row should be separated by commas, while the rows
|
||||||
|
/// themselves should be separated by semicolons. The semicolon syntax merges
|
||||||
|
/// preceding arguments separated by commas into a array arguments. You
|
||||||
|
/// can also use this special syntax of math function calls to define custom
|
||||||
|
/// functions that take 2D data.
|
||||||
|
///
|
||||||
|
/// Content in cells that are in the same row can be aligned with the `&` symbol.
|
||||||
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
/// ```
|
/// ```
|
||||||
/// $ mat(1, 2; 3, 4) $
|
/// $ mat(
|
||||||
|
/// 1, 2, ..., 10;
|
||||||
|
/// 2, 2, ..., 10;
|
||||||
|
/// dots.v, dots.v, dots.down, dots.v;
|
||||||
|
/// 10, 10, ..., 10;
|
||||||
|
/// ) $
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## Parameters
|
/// ## Parameters
|
||||||
/// - rows: Array (positional, variadic)
|
/// - rows: Array (positional, variadic)
|
||||||
/// An array of arrays with the rows of the matrix.
|
/// An array of arrays with the rows of the matrix.
|
||||||
///
|
///
|
||||||
|
/// # Example
|
||||||
|
/// ```
|
||||||
|
/// #let data = ((1, 2, 3), (4, 5, 6))
|
||||||
|
/// #let matrix = math.mat(..data)
|
||||||
|
/// $ v := matrix $
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
/// ## Category
|
/// ## Category
|
||||||
/// math
|
/// math
|
||||||
#[func]
|
#[func]
|
||||||
@ -115,12 +137,14 @@ impl LayoutMath for MatNode {
|
|||||||
/// # Cases
|
/// # Cases
|
||||||
/// A case distinction.
|
/// A case distinction.
|
||||||
///
|
///
|
||||||
|
/// Content across different branches can be aligned with the `&` symbol.
|
||||||
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
/// ```
|
/// ```
|
||||||
/// $ f(x, y) := cases(
|
/// $ f(x, y) := cases(
|
||||||
/// 1 "if" (x dot y)/2 <= 0,
|
/// 1 "if" (x dot y)/2 <= 0,
|
||||||
/// 2 "if" x in NN,
|
/// 2 "if" x "is even",
|
||||||
/// 3 "if" x "is even",
|
/// 3 "if" x in NN,
|
||||||
/// 4 "else",
|
/// 4 "else",
|
||||||
/// ) $
|
/// ) $
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -11,7 +11,7 @@ use super::*;
|
|||||||
/// - limits: bool (named)
|
/// - limits: bool (named)
|
||||||
/// Whether the operator should force attachments to display as limits.
|
/// Whether the operator should force attachments to display as limits.
|
||||||
///
|
///
|
||||||
/// Defaults to `false`.
|
/// Defaults to `{false}`.
|
||||||
///
|
///
|
||||||
/// ## Category
|
/// ## Category
|
||||||
/// math
|
/// math
|
||||||
|
@ -1,40 +1,5 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/// # Upright
|
|
||||||
/// Upright (non-italic) font style in math.
|
|
||||||
///
|
|
||||||
/// ## Example
|
|
||||||
/// ```
|
|
||||||
/// $ upright(A) != A $
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// ## Parameters
|
|
||||||
/// - body: Content (positional, required)
|
|
||||||
/// The piece of formula to style.
|
|
||||||
///
|
|
||||||
/// ## Category
|
|
||||||
/// math
|
|
||||||
#[func]
|
|
||||||
#[capable(LayoutMath)]
|
|
||||||
#[derive(Debug, Hash)]
|
|
||||||
pub struct UprightNode(pub Content);
|
|
||||||
|
|
||||||
#[node]
|
|
||||||
impl UprightNode {
|
|
||||||
fn construct(_: &Vm, args: &mut Args) -> SourceResult<Content> {
|
|
||||||
Ok(Self(args.expect("body")?).pack())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LayoutMath for UprightNode {
|
|
||||||
fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()> {
|
|
||||||
ctx.style(ctx.style.with_italic(false));
|
|
||||||
self.0.layout_math(ctx)?;
|
|
||||||
ctx.unstyle();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// # Bold
|
/// # Bold
|
||||||
/// Bold font style in math.
|
/// Bold font style in math.
|
||||||
///
|
///
|
||||||
@ -70,10 +35,45 @@ impl LayoutMath for BoldNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Upright
|
||||||
|
/// Upright (non-italic) font style in math.
|
||||||
|
///
|
||||||
|
/// ## Example
|
||||||
|
/// ```
|
||||||
|
/// $ upright(A) != A $
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// ## Parameters
|
||||||
|
/// - body: Content (positional, required)
|
||||||
|
/// The piece of formula to style.
|
||||||
|
///
|
||||||
|
/// ## Category
|
||||||
|
/// math
|
||||||
|
#[func]
|
||||||
|
#[capable(LayoutMath)]
|
||||||
|
#[derive(Debug, Hash)]
|
||||||
|
pub struct UprightNode(pub Content);
|
||||||
|
|
||||||
|
#[node]
|
||||||
|
impl UprightNode {
|
||||||
|
fn construct(_: &Vm, args: &mut Args) -> SourceResult<Content> {
|
||||||
|
Ok(Self(args.expect("body")?).pack())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LayoutMath for UprightNode {
|
||||||
|
fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()> {
|
||||||
|
ctx.style(ctx.style.with_italic(false));
|
||||||
|
self.0.layout_math(ctx)?;
|
||||||
|
ctx.unstyle();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// # Italic
|
/// # Italic
|
||||||
/// Italic font style in math.
|
/// Italic font style in math.
|
||||||
///
|
///
|
||||||
/// This is already the default.
|
/// For roman letters and greek lowercase letters, this is already the default.
|
||||||
///
|
///
|
||||||
/// ## Parameters
|
/// ## Parameters
|
||||||
/// - body: Content (positional, required)
|
/// - body: Content (positional, required)
|
||||||
@ -278,7 +278,7 @@ impl LayoutMath for MonoNode {
|
|||||||
/// Blackboard bold (double-struck) font style in math.
|
/// Blackboard bold (double-struck) font style in math.
|
||||||
///
|
///
|
||||||
/// For uppercase latin letters, blackboard bold is additionally available
|
/// For uppercase latin letters, blackboard bold is additionally available
|
||||||
/// through [symbols](/docs/reference/math/) of the form `NN` and `RR`.
|
/// through [symbols](/docs/reference/math/symbols) of the form `NN` and `RR`.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
/// ```
|
/// ```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user