Skip to content

Commit

Permalink
Added multiple show rules, removing indents, grid examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sitandr committed Sep 8, 2024
1 parent aa8d5a8 commit bb390f9
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
- [Lines between list items](./snippets/layout/insert_lines.md)
- [Shadowed shape](./snippets/layout/shapes.md)
- [Code formatting](./snippets/code.md)
- [Tables & grids](./snippets/grids.md)
- [Hyphenation]()
- [Scripting](./snippets/scripting/index.md)
- [Numbering](./snippets/numbering.md)
Expand All @@ -75,6 +76,7 @@
- [Fake italic & Text shadows](./snippets/text/text_shadows.md)
- [Special documents](./snippets/special/index.md)
- [Use with external tools](./snippets/external.md)

- [Typst Packages](./packages/index.md)
- [Overview]()
- [Drawing](./packages/drawing.md)
Expand All @@ -92,6 +94,7 @@
- [Misc](./packages/misc.md)
- [Counting words](./packages/word_count.md)
- [External](./packages/external.md)

- [Typstonomicon, or The Code You Should Not Write](./typstonomicon/index.md)
- [Image with original size](./typstonomicon/original_image.md)
- [Word count](./typstonomicon/word_count.md)
Expand All @@ -101,4 +104,6 @@
- [Inline with](./typstonomicon/inline_with.md)
- [Create zero-level chapters](./typstonomicon/chapters.md)
- [Make all math display](./typstonomicon/math_display.md)
- [Empty pages without numbering](./typstonomicon/totally-empty.md)
- [Empty pages without numbering](./typstonomicon/totally-empty.md)
- [Multiple show rules](./typstonomicon/multiple-show.md)
- [Removing indent of nested lists](./typstonomicon/remove-indent-nested.md)
22 changes: 22 additions & 0 deletions src/snippets/grids.md
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]
)
```
29 changes: 29 additions & 0 deletions src/typstonomicon/multiple-show.md
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$
```
34 changes: 34 additions & 0 deletions src/typstonomicon/remove-indent-nested.md
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
+
```

0 comments on commit bb390f9

Please sign in to comment.