Skip to content

Commit ec352f4

Browse files
committed
rowtable: Implement space as separator
1 parent ebef801 commit ec352f4

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

docs/rowmantic-manual.pdf

1.92 KB
Binary file not shown.

docs/rowmantic-manual.typ

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,11 @@ Example from Wikipedia#footnote[https://en.wikipedia.org/wiki/Interlinear_gloss]
200200
201201
````)
202202

203-
== Double Semicolon Separator
203+
== Other Separators
204204

205205
#block(sticky: true)[
206-
The cell separator can be more than a single character, like in this example.
206+
The cell separator is specified as a string with the `separator` argument.
207+
It can be more than a single character, like in this example with double semicolon:
207208
]
208209
#show-example(```typst
209210
#rowtable(
@@ -214,10 +215,25 @@ Example from Wikipedia#footnote[https://en.wikipedia.org/wiki/Interlinear_gloss]
214215
)
215216
```)
216217

218+
Using a space as a separator has special behaviour -- because of how spaces are treated in Typst markup: multiple spaces, tabs, or a (single) newline are all collapsed into just whitespace. Using a space as separator splits on any such whitespace:
219+
220+
#show-example(```typst
221+
#rowtable(
222+
separator: " ",
223+
stroke: 0.5pt,
224+
[First Second Third~(3rd)],
225+
[Fourth Fifth Sixth~(6th)],
226+
)
227+
```)
228+
229+
The recommended way to insert a literal space in this case is to use ```typst ~```.
230+
217231

218232
== Using Other Table Functions
219233

220-
Use the `table` argument to let rowtable pass its result to a different table function rather than the standard one, for example `pillar.table` (shown below) or `zero.ztable`.
234+
#block(sticky: true)[
235+
Use the `table` argument to let rowtable pass its result to a different table function rather than the standard one, for example `pillar.table` (shown below) or `zero.ztable`.
236+
]
221237

222238
#show-example(```typst
223239
#import "@preview/pillar:0.3.3"

src/rowtable.typ

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@
9595
} else if contentsep and isfunc(elt, sep.func()) and elt == sep {
9696
res.push(accum)
9797
accum = ()
98+
} else if (sep == " " or sep == " ") and isfunc(elt, space) {
99+
res.push(accum)
100+
accum = ()
98101
} else {
99102
accum.push(elt)
100103
}
@@ -262,7 +265,9 @@
262265
/// Arguments to `table` pass through. A `columns` argument to the table is possible but not
263266
/// mandatory.
264267
/// - separator (str): Configurable cell separator in rows. Good choices are `"&"`, `","` or `";"`.
265-
/// Escape the separator using e.g. ```typst \&```
268+
/// Escape the separator using e.g. ```typst \&```.
269+
/// As a special case `" "` will split on consecutive whitespace (one or more spaces, tabs or a newline).
270+
/// Additionally, using `" "` (two spaces) will only split on
266271
/// - separator-eq (none, auto, equation): Cell separator for equations, must be single symbol.
267272
/// By default depends on `separator` if possible otherwise falls back to ```typst $&$```.
268273
/// Set to ```typc none``` to disable splitting equations.

tests/unit1/test.typ

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
#assert.eq(row-split([A,B\,C], sep: ","), ([A], [B#sym.comma;C]))
1212
#assert.eq(row-split([A&B\&C], sep: "&"), ([A], [B#sym.amp;C]))
1313

14+
// space as delimiter
15+
#assert.eq(row-split([A B], sep: " "), ([A], [B]))
16+
#assert.eq(row-split([A *B*], sep: " "), ([A], [*B*]))
17+
#assert.eq(row-split([A B C D E
18+
F G~H], sep: " "), ([A], [B], [C], [D], [E], [F], [G~H]))
19+
// double space as delimiter
20+
#assert.eq(row-split([A B C D E *F*], sep: " "), ([A B], [C], [D E], [*F*]))
21+
1422
// table
1523
#assert.eq(rowtable(), table(columns: 1))
1624
#assert.eq(rowtable([A & B], [C]), table(columns: 2, [A], [B], [C], []))

0 commit comments

Comments
 (0)