From 487eba16af47f06562b37eb0ec9f0442d6e4e84c Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Wed, 2 Aug 2023 13:29:10 -0300 Subject: [PATCH 1/6] bump version to v0.2.0 --- README.md | 42 +++++++++++++++++++++++++++--------------- typst-oxifmt.typ | 2 +- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index d5c4382..04a1fd7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# typst-oxifmt (v0.1.0) +# typst-oxifmt (v0.2.0) A Typst library that brings convenient string formatting and interpolation through the `strfmt` function. Its syntax is taken directly from Rust's `format!` syntax, so feel free to read its page for more information (https://doc.rust-lang.org/std/fmt/); however, this README should have enough information and examples for all expected uses of the library. Only a few things aren't supported from the Rust syntax, such as the `p` (pointer) format type, or the `.*` precision specifier. @@ -19,7 +19,13 @@ A few extras (beyond the Rust-like syntax) will be added over time, though (feel ## Usage -Download the `typst-oxifmt.typ` file either from Releases or directly from the repository. Then, move it to your project's folder, and write at the top of your typst file(s): +You can use this library through Typst's package manager (for Typst v0.6.0+): + +```js +#import "@preview/oxifmt:0.2.0": strfmt +``` + +For older Typst versions, download the `typst-oxifmt.typ` file either from Releases or directly from the repository. Then, move it to your project's folder, and write at the top of your Typst file(s): ```js #import "typst-oxifmt.typ": strfmt @@ -30,7 +36,7 @@ Doing the above will give you access to the main function provided by this libra Its syntax is almost identical to Rust's `format!` (as specified here: https://doc.rust-lang.org/std/fmt/). You can escape formats by duplicating braces (`{{` and `}}` become `{` and `}`). Here's an example (see more examples in the file `tests/strfmt-tests.typ`): ```js -#import "typst-oxifmt.typ": strfmt +#import "@preview/oxifmt:0.2.0": strfmt let s = strfmt("I'm {}. I have {num} cars. I'm {0}. {} is {{cool}}.", "John", "Carl", num: 10) assert.eq(s, "I'm John. I have 10 cars. I'm John. Carl is {cool}.") @@ -68,7 +74,7 @@ You can use `{:spec}` to customize your output. See the Rust docs linked above f Some examples: ```js -#import "typst-oxifmt.typ": strfmt +#import "@preview/oxifmt:0.2.0": strfmt #let s1 = strfmt("{0:?}, {test:+012e}, {1:-<#8x}", "hi", -74, test: 569.4) #assert.eq(s1, "\"hi\", +00005.694e2, -0x4a---") @@ -84,7 +90,7 @@ Some examples: - **Inserting labels, text and numbers into strings:** ```js -#import "typst-oxifmt.typ": strfmt +#import "@preview/oxifmt:0.2.0": strfmt #let s = strfmt("First: {}, Second: {}, Fourth: {3}, Banana: {banana} (brackets: {{escaped}})", 1, 2.1, 3, label("four"), banana: "Banana!!") #assert.eq(s, "First: 1, Second: 2.1, Fourth: four, Banana: Banana!! (brackets: {escaped})") @@ -92,7 +98,7 @@ Some examples: - **Forcing `repr()` with `{:?}`** (which adds quotes around strings, and other things - basically represents a Typst value): ```js -#import "typst-oxifmt.typ": strfmt +#import "@preview/oxifmt:0.2.0": strfmt #let s = strfmt("The value is: {:?} | Also the label is {:?}", "something", label("label")) #assert.eq(s, "The value is: \"something\" | Also the label is