Skip to content

Commit 0f2733f

Browse files
committed
Use grid instead of table
1 parent 02d5a6f commit 0f2733f

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ with the `style-algorithm` show rule.
129129
- `caption-style (function): strong` is applied to the algorithm's title. Normal text can be used with `caption-style: text`, or `caption-style: c => c`.
130130
- `caption-align (alignment): start` aligns the title to the start (left for LTR, and right for RTL languages) by default
131131
- `breakable (bool): true` controls whether or not the figure will break across pages.
132-
- `hlines (array of 3 content): (table.hline(), table.hline(), table.hline())` provides horizontal lines at the top, middle, and bottom of the algorithm figure.
132+
- `hlines (array of 3 content): (grid.hline(), grid.hline(), grid.hline())` provides horizontal lines at the top, middle, and bottom of the algorithm figure.
133133

134134
An example of how to style the algorithm figure:
135135

@@ -138,19 +138,19 @@ An example of how to style the algorithm figure:
138138
breakable: false,
139139
caption-align: end,
140140
caption-style: emph,
141-
hlines: (table.hline(stroke: 2pt + red), table.hline(stroke: 2pt + blue), table.hline(stroke: 2pt + green)),
141+
hlines: (grid.hline(stroke: 2pt + red), grid.hline(stroke: 2pt + blue), grid.hline(stroke: 2pt + green)),
142142
)
143143
```
144144
which will result in something like
145-
![image of the binary search algorithm with a right-aligned and italics figure caption enclosed within a red and blue 2pt table horizontal lines. The algorithm is finally ended with a green 2pt horizontal line](https://raw.githubusercontent.com/typst-community/typst-algorithmic/refs/tags/v1.0.2/tests/style-2/ref/1.png).
145+
![image of the binary search algorithm with a right-aligned and italics figure caption enclosed within a red and blue 2pt grid horizontal lines. The algorithm is finally ended with a green 2pt horizontal line](https://raw.githubusercontent.com/typst-community/typst-algorithmic/refs/tags/v1.0.2/tests/style-2/ref/1.png).
146146

147147
#### Control flow
148148

149149
Algorithmic provides basic control flow statements: `If`, `While`, `For`,
150150
`Else`, `ElseIf`, and a `IfElseChain` utility.
151151

152152
<!-- Table -->
153-
<table>
153+
<grid>
154154
<thead>
155155
<tr>
156156
<th>Statement</th>
@@ -253,14 +253,14 @@ IfElseChain( // Alternating content and bits
253253
<td><img src="https://raw.githubusercontent.com/typst-community/typst-algorithmic/refs/tags/v1.0.2/tests/ifelsechain/ref/1.png" alt="image of an ifelsechain statement with condition x < y and conditional statement assign y to x, then condition x" width="500"></td>
254254
</tr>
255255
</tbody>
256-
</table>
256+
</grid>
257257

258258
#### Commands
259259

260260
The package provides a few commands: `Function`, `Procedure`, `Assign`,
261261
`Return`, `Terminate` and `Break`.
262262

263-
<table>
263+
<grid>
264264
<thead>
265265
<tr>
266266
<th>Command</th>
@@ -347,7 +347,7 @@ Break()
347347
<td><img src="https://raw.githubusercontent.com/typst-community/typst-algorithmic/refs/tags/v1.0.2/tests/break/ref/1.png" alt="image of a break statement" width="500"></td>
348348
</tr>
349349
</tbody>
350-
</table>
350+
</grid>
351351

352352
Users can also define their own commands using both `Call(..args)` and
353353
`Fn(..args)` and their inline versions `CallInline` and `FnInline`.
@@ -388,7 +388,7 @@ There are three kinds of comments: `Comment`, `CommentInline`, and `LineComment`
388388
2. `CommentInline` is an inline comment that returns content on the same line.
389389
3. `LineComment` places a comment on the same line as a line of code to the right.
390390

391-
<table>
391+
<grid>
392392
<thead>
393393
<tr>
394394
<th>Comment</th>
@@ -435,4 +435,4 @@ LineComment(Assign[a][1], [Initialize $a$ to 1])
435435
<td><img src="https://raw.githubusercontent.com/typst-community/typst-algorithmic/refs/tags/v1.0.2/tests/linecomment/ref/1.png" alt="image of a line comment with text 'Initialize a to 1'" width="500"></td>
436436
</tr>
437437
</tbody>
438-
</table>
438+
</grid>

algorithmic.typ

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@
2828
caption-style: strong,
2929
caption-align: start,
3030
breakable: true,
31-
hlines: (table.hline(), table.hline(), table.hline()),
31+
hlines: (grid.hline(), grid.hline(), grid.hline()),
3232
) = {
3333
show figure.where(kind: "algorithm"): it => {
3434
set block(breakable: breakable)
35-
table(
35+
grid(
3636
columns: 1,
3737
stroke: none,
38+
inset: 0% + 5pt,
3839
hlines.at(0),
3940
caption-style(align(caption-align, it.caption)),
4041
hlines.at(1),
@@ -50,29 +51,29 @@
5051
if content.len() == 0 or content == (none,) {
5152
return none
5253
}
53-
let table-bits = ()
54+
let grid-bits = ()
5455
let line-number = 1
5556

5657
let indent-list = content.map(c => c.line-indent)
5758
let max-indent = indent-list.sorted().last()
5859
let colspans = indent-list.map(i => max-indent + 1 - i)
59-
let indent-content = indent-list.map(i => ([], table.vline(stroke: vstroke), []) * int(i / 2))
60+
let indent-content = indent-list.map(i => ([], grid.vline(stroke: vstroke), []) * int(i / 2))
6061
let indents = (indent,) * max-indent
6162
let offset = 18pt + if indents.len() != 0 { indents.sum() }
6263
let columns = (18pt, ..indents, 100% - offset)
6364

6465
while line-number <= content.len() {
65-
table-bits.push([#line-number:])
66-
table-bits = table-bits + indent-content.at(line-number - 1)
67-
table-bits.push(table.cell(content.at(line-number - 1).line-content, colspan: colspans.at(line-number - 1)))
66+
grid-bits.push([#line-number:])
67+
grid-bits = grid-bits + indent-content.at(line-number - 1)
68+
grid-bits.push(grid.cell(content.at(line-number - 1).line-content, colspan: colspans.at(line-number - 1)))
6869
line-number = line-number + 1
6970
}
70-
return table(
71+
return grid(
7172
columns: columns,
7273
// line spacing
7374
inset: inset,
7475
stroke: none,
75-
..table-bits
76+
..grid-bits
7677
)
7778
}
7879

tests/style-2/test.typ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
breakable: false,
66
caption-align: end,
77
caption-style: emph,
8-
hlines: (table.hline(stroke: 2pt + red), table.hline(stroke: 2pt + blue), table.hline(stroke: 2pt + green)),
8+
hlines: (grid.hline(stroke: 2pt + red), grid.hline(stroke: 2pt + blue), grid.hline(stroke: 2pt + green)),
99
)
1010
#algorithm-figure(
1111
"Binary Search",

0 commit comments

Comments
 (0)