From 2100cff067e775c9db29ca16a34e3f235f56efd5 Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Mon, 6 May 2024 11:24:50 -0300 Subject: [PATCH] Release v0.2.1 (#7) --- README.md | 72 +++++++++++++++++++++++++++++------------------------- typst.toml | 2 +- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 7f04eae..4782894 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# typst-oxifmt (v0.2.0) +# typst-oxifmt (v0.2.1) 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. A few extras (beyond the Rust-like syntax) will be added over time, though (feel free to drop suggestions at the repository: https://github.com/PgBiel/typst-oxifmt). The first "extra" so far is the `fmt-decimal-separator: "string"` parameter, which lets you customize the decimal separator for decimal numbers (floats) inserted into strings. E.g. `strfmt("Result: {}", 5.8, fmt-decimal-separator: ",")` will return the string `"Result: 5,8"` (comma instead of dot). See more below. -**Compatible with:** [Typst](https://github.com/typst/typst) v0.4.0, v0.5.0, v0.6.0 +**Compatible with:** [Typst](https://github.com/typst/typst) v0.4.0+ ## Table of Contents @@ -21,13 +21,13 @@ 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+): -```js -#import "@preview/oxifmt:0.2.0": strfmt +```typ +#import "@preview/oxifmt:0.2.1": 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): -```js +```typ #import "oxifmt.typ": strfmt ``` @@ -35,8 +35,8 @@ 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 "@preview/oxifmt:0.2.0": strfmt +```typ +#import "@preview/oxifmt:0.2.1": 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}.") @@ -73,8 +73,8 @@ You can use `{:spec}` to customize your output. See the Rust docs linked above f Some examples: -```js -#import "@preview/oxifmt:0.2.0": strfmt +```typ +#import "@preview/oxifmt:0.2.1": strfmt #let s1 = strfmt("{0:?}, {test:+012e}, {1:-<#8x}", "hi", -74, test: 569.4) #assert.eq(s1, "\"hi\", +00005.694e2, -0x4a---") @@ -89,57 +89,57 @@ Some examples: ### Examples - **Inserting labels, text and numbers into strings:** -```js -#import "@preview/oxifmt:0.2.0": strfmt +```typ +#import "@preview/oxifmt:0.2.1": 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})") ``` - **Forcing `repr()` with `{:?}`** (which adds quotes around strings, and other things - basically represents a Typst value): -```js -#import "@preview/oxifmt:0.2.0": strfmt +```typ +#import "@preview/oxifmt:0.2.1": 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