diff --git a/README.md b/README.md index 7c33ade..bff14d0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# typst-oxifmt (v0.3.0) +# typst-oxifmt (v1.0.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. Check out the ["Examples" section](#examples) for more. @@ -9,7 +9,7 @@ A few extras (beyond the Rust-like syntax) will be added over time, though (feel ## Quick examples ```typ -#import "@preview/oxifmt:0.3.0": strfmt +#import "@preview/oxifmt:1.0.0": strfmt // "User John has 10 apples." #strfmt("User {} has {} apples.", "John", 10) @@ -17,8 +17,8 @@ A few extras (beyond the Rust-like syntax) will be added over time, though (feel // "if exp > 100 { true }" #strfmt("if {var} > {num} {{ true }}", var: "exp", num: 100) -// "1.10e2 meters" -#strfmt("{:.2e} meters", 110.0) +// "1.10e2 meters (**wow**)" +#strfmt("{:.2e} meters ({:*^7})", 110.0, "wow") // "20_000 players have more than +002,300 points." #strfmt( @@ -50,7 +50,7 @@ A few extras (beyond the Rust-like syntax) will be added over time, though (feel You can use this library through Typst's package manager (for Typst v0.6.0+): ```typ -#import "@preview/oxifmt:0.3.0": strfmt +#import "@preview/oxifmt:1.0.0": strfmt ``` For older Typst versions, download the `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): @@ -64,7 +64,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`): ```typ -#import "@preview/oxifmt:0.3.0": strfmt +#import "@preview/oxifmt:1.0.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}.") @@ -104,7 +104,7 @@ You can use `{:spec}` to customize your output. See the Rust docs linked above f Some examples: ```typ -#import "@preview/oxifmt:0.3.0": strfmt +#import "@preview/oxifmt:1.0.0": strfmt #let s1 = strfmt("{0:?}, {test:+012e}, {1:-<#8x}", "hi", -74, test: 569.4) #assert.eq(s1, "\"hi\", +00005.694e2, -0x4a---") @@ -120,7 +120,7 @@ Some examples: - **Inserting labels, text and numbers into strings:** ```typ -#import "@preview/oxifmt:0.3.0": strfmt +#import "@preview/oxifmt:1.0.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})") @@ -128,7 +128,7 @@ Some examples: - **Forcing `repr()` with `{:?}`** (which adds quotes around strings, and other things - basically represents a Typst value): ```typ -#import "@preview/oxifmt:0.3.0": strfmt +#import "@preview/oxifmt:1.0.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