-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added multiple show rules, removing indents, grid examples
- Loading branch information
Showing
4 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## Fractional grids | ||
|
||
For tables with lines of changing length, you can try using _grids in grids_. | ||
|
||
<div class="warning"> | ||
Don't use this where <a href="https://typst.app/docs/reference/model/table/#definitions-cell-colspan">cell.colspan and rowspan</a> will do. | ||
</div> | ||
|
||
```typ | ||
// author: jimpjorps | ||
#grid( | ||
columns: (1fr,), | ||
grid( | ||
columns: (1fr,)*2, inset: 5pt, stroke: 1pt, [hello], [world] | ||
), | ||
grid( | ||
columns: (1fr,)*3, inset: 5pt, stroke: 1pt, [foo], [bar], [baz] | ||
), | ||
grid.cell(inset: 5pt, stroke: 1pt)[abcxyz] | ||
) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
## Multiple show rules | ||
|
||
Sometimes there is a need to apply several rules that look very similar. Or generate them from code. One of the ways to deal with this, the most cursed one, is this: | ||
|
||
```typ | ||
#let rules = (math.sum, math.product, math.root) | ||
#let apply-rules(rules, it) = { | ||
if rules.len() == 0 { | ||
return it | ||
} | ||
show rules.pop(): math.display | ||
apply-rules(rules, it) | ||
} | ||
$product/sum root(3, x)/2$ | ||
#show: apply-rules.with(rules) | ||
$product/sum root(3, x)/2$ | ||
``` | ||
|
||
Note that just in case of symbols (if you don't need element functions), one can use regular expressions. That is a more robust way: | ||
|
||
```typ | ||
#show regex("[" + math.product + math.sum + "]"): math.display | ||
$product/sum root(3, x)/2$ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Remove indent from nested lists | ||
|
||
```typ | ||
// author: fenjalien | ||
#show enum.item: it => { | ||
if repr(it.body.func()) == "sequence" { | ||
let children = it.body.children | ||
let index = children.position(x => x.func() == enum.item) | ||
if index != none { | ||
enum.item({ | ||
children.slice(0, index).join() | ||
set enum(indent: -1.2em) // Note that this stops an infinitly recursive show rule | ||
children.slice(index).join() | ||
}) | ||
} else { | ||
it | ||
} | ||
} else { | ||
it | ||
} | ||
} | ||
arst | ||
+ A | ||
+ b | ||
+ c | ||
+ d | ||
+ e | ||
+ f | ||
+ g | ||
+ h | ||
+ i | ||
+ | ||
``` |