Skip to content

Commit 94c2933

Browse files
laurmaedjeMDLC01Andrew15-5PgBielknuesel
committed
Docs and changelog improvements (#5147)
Co-authored-by: Malo <[email protected]> Co-authored-by: Andrew Voynov <[email protected]> Co-authored-by: PgBiel <[email protected]> Co-authored-by: Jeremie Knuesel <[email protected]> Co-authored-by: +merlan #flirora <[email protected]> Co-authored-by: Anselm Schüler <[email protected]>
1 parent d4c4451 commit 94c2933

File tree

29 files changed

+229
-117
lines changed

29 files changed

+229
-117
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Typst's CLI is available from different sources:
129129
`nix run github:typst/typst -- --version`.
130130

131131
- Docker users can run a prebuilt image with
132-
`docker run -it ghcr.io/typst/typst:latest`.
132+
`docker run ghcr.io/typst/typst:latest --help`.
133133

134134
## Usage
135135
Once you have installed Typst, you can use it like this:

crates/typst-cli/src/args.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ pub struct QueryCommand {
209209
#[clap(long = "format", default_value = "json")]
210210
pub format: SerializationFormat,
211211

212-
/// Whether to pretty-print the serialized output
212+
/// Whether to pretty-print the serialized output.
213+
///
214+
/// Only applies to JSON format.
213215
#[clap(long)]
214216
pub pretty: bool,
215217
}

crates/typst/src/foundations/array.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,8 @@ impl Array {
486486
/// function is a bit involved, so we parse the positional arguments manually).
487487
args: &mut Args,
488488
/// Whether all arrays have to have the same length.
489-
/// For example, `(1, 2).zip((1, 2, 3), exact: true)` produces an error.
489+
/// For example, `{(1, 2).zip((1, 2, 3), exact: true)}` produces an
490+
/// error.
490491
#[named]
491492
#[default(false)]
492493
exact: bool,

crates/typst/src/foundations/calc.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ cast! {
9292
/// Raises a value to some exponent.
9393
///
9494
/// ```example
95-
/// #calc.pow(2, 3)
95+
/// #calc.pow(2, 3) \
9696
/// #calc.pow(decimal("2.5"), 2)
9797
/// ```
9898
#[func(title = "Power")]
@@ -236,7 +236,6 @@ pub fn root(
236236
/// radians.
237237
///
238238
/// ```example
239-
/// #assert(calc.sin(90deg) == calc.sin(-270deg))
240239
/// #calc.sin(1.5) \
241240
/// #calc.sin(90deg)
242241
/// ```
@@ -258,7 +257,6 @@ pub fn sin(
258257
/// radians.
259258
///
260259
/// ```example
261-
/// #calc.cos(90deg) \
262260
/// #calc.cos(1.5) \
263261
/// #calc.cos(90deg)
264262
/// ```
@@ -621,10 +619,10 @@ pub fn lcm(
621619
/// 64-bit signed integer or smaller than the minimum for that type.
622620
///
623621
/// ```example
622+
/// #calc.floor(500.1)
624623
/// #assert(calc.floor(3) == 3)
625624
/// #assert(calc.floor(3.14) == 3)
626625
/// #assert(calc.floor(decimal("-3.14")) == -4)
627-
/// #calc.floor(500.1)
628626
/// ```
629627
#[func]
630628
pub fn floor(
@@ -648,10 +646,10 @@ pub fn floor(
648646
/// 64-bit signed integer or smaller than the minimum for that type.
649647
///
650648
/// ```example
649+
/// #calc.ceil(500.1)
651650
/// #assert(calc.ceil(3) == 3)
652651
/// #assert(calc.ceil(3.14) == 4)
653652
/// #assert(calc.ceil(decimal("-3.14")) == -3)
654-
/// #calc.ceil(500.1)
655653
/// ```
656654
#[func]
657655
pub fn ceil(
@@ -675,10 +673,10 @@ pub fn ceil(
675673
/// 64-bit signed integer or smaller than the minimum for that type.
676674
///
677675
/// ```example
676+
/// #calc.trunc(15.9)
678677
/// #assert(calc.trunc(3) == 3)
679678
/// #assert(calc.trunc(-3.7) == -3)
680679
/// #assert(calc.trunc(decimal("8493.12949582390")) == 8493)
681-
/// #calc.trunc(15.9)
682680
/// ```
683681
#[func(title = "Truncate")]
684682
pub fn trunc(
@@ -698,9 +696,9 @@ pub fn trunc(
698696
/// If the number is an integer, returns `0`.
699697
///
700698
/// ```example
699+
/// #calc.fract(-3.1)
701700
/// #assert(calc.fract(3) == 0)
702701
/// #assert(calc.fract(decimal("234.23949211")) == decimal("0.23949211"))
703-
/// #calc.fract(-3.1)
704702
/// ```
705703
#[func(title = "Fractional")]
706704
pub fn fract(
@@ -734,6 +732,7 @@ pub fn fract(
734732
/// for maximum and minimum respectively.
735733
///
736734
/// ```example
735+
/// #calc.round(3.1415, digits: 2)
737736
/// #assert(calc.round(3) == 3)
738737
/// #assert(calc.round(3.14) == 3)
739738
/// #assert(calc.round(3.5) == 4.0)
@@ -745,7 +744,6 @@ pub fn fract(
745744
/// #assert(calc.round(decimal("7.123456789"), digits: 6) == decimal("7.123457"))
746745
/// #assert(calc.round(decimal("3333.45"), digits: -2) == decimal("3300"))
747746
/// #assert(calc.round(decimal("-48953.45"), digits: -3) == decimal("-49000"))
748-
/// #calc.round(3.1415, digits: 2)
749747
/// ```
750748
#[func]
751749
pub fn round(
@@ -776,11 +774,11 @@ pub fn round(
776774
/// Clamps a number between a minimum and maximum value.
777775
///
778776
/// ```example
777+
/// #calc.clamp(5, 0, 4)
779778
/// #assert(calc.clamp(5, 0, 10) == 5)
780779
/// #assert(calc.clamp(5, 6, 10) == 6)
781780
/// #assert(calc.clamp(decimal("5.45"), 2, decimal("45.9")) == decimal("5.45"))
782781
/// #assert(calc.clamp(decimal("5.45"), decimal("6.75"), 12) == decimal("6.75"))
783-
/// #calc.clamp(5, 0, 4)
784782
/// ```
785783
#[func]
786784
pub fn clamp(
@@ -991,7 +989,7 @@ pub fn div_euclid(
991989
/// #calc.rem-euclid(7, -3) \
992990
/// #calc.rem-euclid(-7, 3) \
993991
/// #calc.rem-euclid(-7, -3) \
994-
/// #calc.rem-euclid(1.75, 0.5)
992+
/// #calc.rem-euclid(1.75, 0.5) \
995993
/// #calc.rem-euclid(decimal("1.75"), decimal("0.5"))
996994
/// ```
997995
#[func(title = "Euclidean Remainder")]

crates/typst/src/foundations/decimal.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ use crate::World;
3434
/// constructing a decimal from a [floating-point number]($float), while
3535
/// supported, **is an imprecise conversion and therefore discouraged.** A
3636
/// warning will be raised if Typst detects that there was an accidental `float`
37-
/// to `decimal` cast through its constructor (e.g. if writing `{decimal(3.14)}`
38-
/// - note the lack of double quotes, indicating this is an accidental `float`
39-
/// cast and therefore imprecise).
37+
/// to `decimal` cast through its constructor, e.g. if writing `{decimal(3.14)}`
38+
/// (note the lack of double quotes, indicating this is an accidental `float`
39+
/// cast and therefore imprecise). It is recommended to use strings for
40+
/// constant decimal values instead (e.g. `{decimal("3.14")}`).
4041
///
4142
/// The precision of a `float` to `decimal` cast can be slightly improved by
4243
/// rounding the result to 15 digits with [`calc.round`]($calc.round), but there
@@ -81,11 +82,11 @@ use crate::World;
8182
/// multiplication, and [power]($calc.pow) to an integer, will be highly precise
8283
/// due to their fixed-point representation. Note, however, that multiplication
8384
/// and division may not preserve all digits in some edge cases: while they are
84-
/// considered precise, digits past the limits specified below are rounded off
85+
/// considered precise, digits past the limits specified above are rounded off
8586
/// and lost, so some loss of precision beyond the maximum representable digits
8687
/// is possible. Note that this behavior can be observed not only when dividing,
8788
/// but also when multiplying by numbers between 0 and 1, as both operations can
88-
/// push a number's fractional digits beyond the limits described below, leading
89+
/// push a number's fractional digits beyond the limits described above, leading
8990
/// to rounding. When those two operations do not surpass the digit limits, they
9091
/// are fully precise.
9192
#[ty(scope, cast)]
@@ -287,7 +288,7 @@ impl Decimal {
287288
/// writing `{decimal(1.234)}` (note the lack of double quotes), which is
288289
/// why Typst will emit a warning in that case. Please write
289290
/// `{decimal("1.234")}` instead for that particular case (initialization of
290-
/// a constant decimal). Also note that floats equal to NaN and infinity
291+
/// a constant decimal). Also note that floats that are NaN or infinite
291292
/// cannot be cast to decimals and will raise an error.
292293
///
293294
/// ```example
@@ -296,6 +297,7 @@ impl Decimal {
296297
#[func(constructor)]
297298
pub fn construct(
298299
engine: &mut Engine,
300+
/// The value that should be converted to a decimal.
299301
value: Spanned<ToDecimal>,
300302
) -> SourceResult<Decimal> {
301303
match value.v {

crates/typst/src/foundations/float.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl f64 {
9797
///
9898
/// - If the number is positive (including `{+0.0}`), returns `{1.0}`.
9999
/// - If the number is negative (including `{-0.0}`), returns `{-1.0}`.
100-
/// - If the number is `{float.nan}`, returns `{float.nan}`.
100+
/// - If the number is NaN, returns `{float.nan}`.
101101
///
102102
/// ```example
103103
/// #(5.0).signum() \

crates/typst/src/introspection/location.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ impl Location {
8585
/// local numbering. This is useful if you are building custom indices or
8686
/// outlines.
8787
///
88-
/// If the page numbering is set to `none` at that location, this function
89-
/// returns `none`.
88+
/// If the page numbering is set to `{none}` at that location, this function
89+
/// returns `{none}`.
9090
#[func]
9191
pub fn page_numbering(self, engine: &mut Engine) -> Option<Numbering> {
9292
engine.introspector.page_numbering(self).cloned()

crates/typst/src/layout/align.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ use crate::text::TextElem;
6464
/// left.
6565
/// ])
6666
/// ```
67+
///
68+
/// # Alignment within the same line
69+
/// The `align` function performs block-level alignment and thus always
70+
/// interrupts the current paragraph. To have different alignment for parts
71+
/// of the same line, you should use [fractional spacing]($h) instead:
72+
///
73+
/// ```example
74+
/// Start #h(1fr) End
75+
/// ```
6776
#[elem(Show)]
6877
pub struct AlignElem {
6978
/// The [alignment] along both axes.

crates/typst/src/layout/measure.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use crate::syntax::Span;
1919
///
2020
/// # Example
2121
/// The same content can have a different size depending on the [context] that
22-
/// it is placed into. For example, in the example below `[#content]` is of
23-
/// course bigger when we increase the font size.
22+
/// it is placed into. In the example below, the `[#content]` is of course
23+
/// bigger when we increase the font size.
2424
///
2525
/// ```example
2626
/// #let content = [Hello!]
@@ -53,12 +53,12 @@ pub fn measure(
5353
span: Span,
5454
/// The width available to layout the content.
5555
///
56-
/// Defaults to `{auto}`, which denotes an infinite width.
56+
/// Setting this to `{auto}` indicates infinite available width.
5757
///
58-
/// Using the `width` and `height` parameters of this function is
59-
/// different from measuring a [`box`] containing the content;
60-
/// the former will get the dimensions of the inner content
61-
/// instead of the dimensions of the box:
58+
/// Note that using the `width` and `height` parameters of this function is
59+
/// different from measuring a sized [`block`] containing the content. In
60+
/// the following example, the former will get the dimensions of the inner
61+
/// content instead of the dimensions of the block.
6262
///
6363
/// ```example
6464
/// #context measure(lorem(100), width: 400pt)
@@ -70,7 +70,7 @@ pub fn measure(
7070
width: Smart<Length>,
7171
/// The height available to layout the content.
7272
///
73-
/// Defaults to `{auto}`, which denotes an infinite height.
73+
/// Setting this to `{auto}` indicates infinite available height.
7474
#[named]
7575
#[default(Smart::Auto)]
7676
height: Smart<Length>,

crates/typst/src/layout/page.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ pub struct PageElem {
189189
///
190190
/// When set to `{none}`, the background becomes transparent. Note that PDF
191191
/// pages will still appear with a (usually white) background in viewers,
192-
/// but they are conceptually transparent. (If you print them, no color is
193-
/// used for the background.)
192+
/// but they are actually transparent. (If you print them, no color is used
193+
/// for the background.)
194194
///
195195
/// The default of `{auto}` results in `{none}` for PDF output, and
196196
/// `{white}` for PNG and SVG.

0 commit comments

Comments
 (0)