From 26906f487549c4a843935d74a74d5dc9f090a350 Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Sun, 5 May 2024 20:55:00 -0300 Subject: [PATCH 1/7] v0.2.1 changelog --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7f04eae..283d64e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# 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. @@ -214,6 +214,12 @@ The tests succeeded if you received no error messages from the last command (ple ## Changelog +### v0.2.1 + +- Fixed formatting of UTF-8 strings. Before, strings with multi-byte UTF-8 codepoints would cause formatting inconsistencies or even crashes. ([Issue #6](https://github.com/PgBiel/typst-oxifmt/issues/6)) +- Fixed an inconsistency in negative number formatting. Now, it will always print a regular hyphen (e.g. '-2'), which is consistent with Rust's behavior; before, it would occasionally print a minus sign instead (as observed in a comment to [Issue #4](https://github.com/PgBiel/typst-oxifmt/issues/4)). +- Added compatibility with Typst 0.8.0's new type system. + ### v0.2.0 - The package's name is now `oxifmt`! From 035ff02fda937b575a1e17635dfff5deb98d8ed8 Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Sun, 5 May 2024 20:59:39 -0300 Subject: [PATCH 2/7] typst v0.4.0+ --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 283d64e..7deb9eb 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A Typst library that brings convenient string formatting and interpolation throu 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 From 10aa90529dd0dd8d9825fbe1b027f53bebfa56c8 Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Sun, 5 May 2024 21:20:41 -0300 Subject: [PATCH 3/7] update typst.toml to v0.2.1 --- typst.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typst.toml b/typst.toml index 59286eb..6f680c1 100644 --- a/typst.toml +++ b/typst.toml @@ -1,6 +1,6 @@ [package] name = "oxifmt" -version = "0.2.0" +version = "0.2.1" authors = ["PgBiel "] license = "MIT-0" description = "Convenient Rust-like string formatting in Typst" From 20dd96e6c1e0d88b1d350db63ba2a9199f7bd9f1 Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Sun, 5 May 2024 21:22:04 -0300 Subject: [PATCH 4/7] use 'typ' codeblocks in README --- README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 7deb9eb..bd6c9e1 100644 --- a/README.md +++ b/README.md @@ -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 +```typ #import "@preview/oxifmt:0.2.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): -```js +```typ #import "oxifmt.typ": strfmt ``` @@ -35,7 +35,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 +```typ #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) @@ -73,7 +73,7 @@ You can use `{:spec}` to customize your output. See the Rust docs linked above f Some examples: -```js +```typ #import "@preview/oxifmt:0.2.0": strfmt #let s1 = strfmt("{0:?}, {test:+012e}, {1:-<#8x}", "hi", -74, test: 569.4) @@ -89,7 +89,7 @@ Some examples: ### Examples - **Inserting labels, text and numbers into strings:** -```js +```typ #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!!") @@ -97,7 +97,7 @@ Some examples: ``` - **Forcing `repr()` with `{:?}`** (which adds quotes around strings, and other things - basically represents a Typst value): -```js +```typ #import "@preview/oxifmt:0.2.0": strfmt #let s = strfmt("The value is: {:?} | Also the label is {:?}", "something", label("label")) @@ -105,7 +105,7 @@ Some examples: ``` - **Inserting other types than numbers and strings** (for now, they will always use `repr()`, even without `{...:?}`, although that is more explicit): -```js +```typ #import "@preview/oxifmt:0.2.0": strfmt #let s = strfmt("Values: {:?}, {1:?}, {stuff:?}", (test: 500), ("a", 5.1), stuff: [a]) @@ -113,7 +113,7 @@ Some examples: ``` - **Padding to a certain width with characters:** Use `{:x<8}`, where `x` is the **character to pad with** (e.g. space or `_`, but can be anything), `<` is the **alignment of the original text** relative to the padding (can be `<` for left aligned (padding goes to the right), `>` for right aligned (padded to its left) and `^` for center aligned (padded at both left and right)), and `8` is the **desired total width** (padding will add enough characters to reach this width; if the replacement string already has this width, no padding will be added): -```js +```typ #import "@preview/oxifmt:0.2.0": strfmt #let s = strfmt("Left5 {:_<5}, Right6 {:*>6}, Center10 {centered: ^10?}, Left3 {tleft:_<3}", "xx", 539, tleft: "okay", centered: [a]) @@ -122,7 +122,7 @@ Some examples: ``` - **Padding numbers with zeroes to the left:** It's a similar functionality to the above, however you write `{:08}` for 8 characters (for instance) - note that any characters in the number's representation matter for width (including sign, dot and decimal part): -```js +```typ #import "@preview/oxifmt:0.2.0": strfmt #let s = strfmt("Left-padded7 numbers: {:07} {:07} {:07} {3:07}", 123, -344, 44224059, 45.32) @@ -130,7 +130,7 @@ Some examples: ``` - **Defining padding-to width using parameters, not literals:** If you want the desired replacement width (the `8` in `{:08}` or `{: ^8}`) to be passed via parameter (instead of being hardcoded into the format string), you can specify `parameter$` in place of the width, e.g. `{:02$}` to take it from the third positional parameter, or `{:a>banana$}` to take it from the parameter named `banana` - note that the chosen parameter **must be an integer** (desired total width): -```js +```typ #import "@preview/oxifmt:0.2.0": strfmt #let s = strfmt("Padding depending on parameter: {0:02$} and {0:a>banana$}", 432, 0, 5, banana: 9) @@ -138,7 +138,7 @@ Some examples: ``` - **Displaying `+` on positive numbers:** Just add a `+` at the "beginning", i.e., before the `#0` (if either is there), or after the custom fill and align (if it's there and not `0` - see [Grammar](#grammar) for the exact positioning), like so: -```js +```typ #import "@preview/oxifmt:0.2.0": strfmt #let s = strfmt("Some numbers: {:+} {:+08}; With fill and align: {:_<+8}; Negative (no-op): {neg:+}", 123, 456, 4444, neg: -435) @@ -147,7 +147,7 @@ Some examples: ``` - **Converting numbers to bases 2, 8 and 16:** Use one of the following specifier types (i.e., characters which always go at the very end of the format): `b` (binary), `o` (octal), `x` (lowercase hexadecimal) or `X` (uppercase hexadecimal). You can also add a `#` between `+` and `0` (see the exact position at the [Grammar](#grammar)) to display a **base prefix** before the number (i.e. `0b` for binary, `0o` for octal and `0x` for hexadecimal): -```js +```typ #import "@preview/oxifmt:0.2.0": strfmt #let s = strfmt("Bases (10, 2, 8, 16(l), 16(U):) {0} {0:b} {0:o} {0:x} {0:X} | W/ prefixes and modifiers: {0:#b} {0:+#09o} {0:_>+#9X}", 124) @@ -155,7 +155,7 @@ Some examples: ``` - **Picking float precision (right-extending with zeroes):** Add, at the end of the format (just before the spec type (such as `?`), if there's any), either `.precision` (hardcoded, e.g. `.8` for 8 decimal digits) or `.parameter$` (taking the precision value from the specified parameter, like with `width`): -```js +```typ #import "@preview/oxifmt:0.2.0": strfmt #let s = strfmt("{0:.8} {0:.2$} {0:.potato$}", 1.234, 0, 2, potato: 5) @@ -163,7 +163,7 @@ Some examples: ``` - **Scientific notation:** Use `e` (lowercase) or `E` (uppercase) as specifier types (can be combined with precision): -```js +```typ #import "@preview/oxifmt:0.2.0": strfmt #let s = strfmt("{0:e} {0:E} {0:+.9e} | {1:e} | {2:.4E}", 124.2312, 50, -0.02) @@ -171,7 +171,7 @@ Some examples: ``` - **Customizing the decimal separator on floats:** Just specify `fmt-decimal-separator: ","` (comma as an example): -```js +```typ #import "@preview/oxifmt:0.2.0": strfmt #let s = strfmt("{0} {0:.6} {0:.5e}", 1.432, fmt-decimal-separator: ",") From bb6cf0d2dced1658dfdfb3e3c55b7b0227193960 Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Sun, 5 May 2024 21:23:40 -0300 Subject: [PATCH 5/7] use 0.2.1 in examples --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index bd6c9e1..eaf9be0 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,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.2.0": strfmt +#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): @@ -36,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`): ```typ -#import "@preview/oxifmt:0.2.0": strfmt +#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}.") @@ -74,7 +74,7 @@ You can use `{:spec}` to customize your output. See the Rust docs linked above f Some examples: ```typ -#import "@preview/oxifmt:0.2.0": strfmt +#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---") @@ -90,7 +90,7 @@ Some examples: - **Inserting labels, text and numbers into strings:** ```typ -#import "@preview/oxifmt:0.2.0": strfmt +#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})") @@ -98,7 +98,7 @@ Some examples: - **Forcing `repr()` with `{:?}`** (which adds quotes around strings, and other things - basically represents a Typst value): ```typ -#import "@preview/oxifmt:0.2.0": strfmt +#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