From bd66907040189215b9b98598826dd0d7e8fbcaa4 Mon Sep 17 00:00:00 2001 From: Andrew Voynov Date: Sun, 8 Jun 2025 00:28:33 +0300 Subject: [PATCH] Add docs for `std` module --- crates/typst-library/src/lib.rs | 2 +- docs/reference/groups.yml | 36 +++++++++++++++++++++++++++++++++ docs/src/lib.rs | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/crates/typst-library/src/lib.rs b/crates/typst-library/src/lib.rs index c39024f71..fa7977888 100644 --- a/crates/typst-library/src/lib.rs +++ b/crates/typst-library/src/lib.rs @@ -148,7 +148,7 @@ pub struct Library { /// The default style properties (for page size, font selection, and /// everything else configurable via set and show rules). pub styles: Styles, - /// The standard library as a value. Used to provide the `std` variable. + /// The standard library as a value. Used to provide the `std` module. pub std: Binding, /// In-development features that were enabled. pub features: Features, diff --git a/docs/reference/groups.yml b/docs/reference/groups.yml index 8fea3a1f2..625ac6f2f 100644 --- a/docs/reference/groups.yml +++ b/docs/reference/groups.yml @@ -130,6 +130,42 @@ In addition to the functions listed below, the `calc` module also defines the constants `pi`, `tau`, `e`, and `inf`. +- name: std + title: Standard library + category: foundations + path: ["std"] + details: | + # Collection of globally accessible items under `std` variable. + # Collection of globally accessible items under `std.` prefix. + # Module consisting of globally accessible items. + # The standard library as a value. + An alias for globally accessible items comprsing the standard library. + + This is useful whenever you override a name from the global scope, e.g., + the [`text`] element. To access the element simply write `std.text`. + Since `std` is not a keyword, you can override it if necessary. + # Note that element items from `std` variable work exactly the same way, + Note that element items from `std` module work exactly like normal ones, + meaning they can be used as constructors, in set rules, etc. + + # Example + ```example + #let par = [My special paragraph.] + #let special(text) = { + set std.text(style: "italic", weight: "bold") + set std.par.line(numbering: "1") + parbreak() + text + parbreak() + } + + #lorem(10) + #special[ + #par + ] + #lorem(10) + ``` + - name: sys title: System category: foundations diff --git a/docs/src/lib.rs b/docs/src/lib.rs index 091bb1b24..57e0cb876 100644 --- a/docs/src/lib.rs +++ b/docs/src/lib.rs @@ -37,7 +37,7 @@ static GROUPS: LazyLock> = LazyLock::new(|| { let mut groups: Vec = yaml::from_str(load!("reference/groups.yml")).unwrap(); for group in &mut groups { - if group.filter.is_empty() { + if group.filter.is_empty() && group.name != "std" { group.filter = group .module() .scope()