From bb390f9fc92545b622c2d98e54cbd19b7a7dc53f Mon Sep 17 00:00:00 2001 From: sitandr Date: Mon, 9 Sep 2024 01:44:35 +0300 Subject: [PATCH] Added multiple show rules, removing indents, grid examples --- src/SUMMARY.md | 7 ++++- src/snippets/grids.md | 22 +++++++++++++++ src/typstonomicon/multiple-show.md | 29 +++++++++++++++++++ src/typstonomicon/remove-indent-nested.md | 34 +++++++++++++++++++++++ 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 src/snippets/grids.md create mode 100644 src/typstonomicon/multiple-show.md create mode 100644 src/typstonomicon/remove-indent-nested.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index aa02ee3..51e551e 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -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) @@ -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) @@ -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) @@ -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) \ No newline at end of file + - [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) diff --git a/src/snippets/grids.md b/src/snippets/grids.md new file mode 100644 index 0000000..3748003 --- /dev/null +++ b/src/snippets/grids.md @@ -0,0 +1,22 @@ +## Fractional grids + +For tables with lines of changing length, you can try using _grids in grids_. + +
+Don't use this where cell.colspan and rowspan will do. +
+ +```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] +) +``` diff --git a/src/typstonomicon/multiple-show.md b/src/typstonomicon/multiple-show.md new file mode 100644 index 0000000..42903cd --- /dev/null +++ b/src/typstonomicon/multiple-show.md @@ -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$ +``` \ No newline at end of file diff --git a/src/typstonomicon/remove-indent-nested.md b/src/typstonomicon/remove-indent-nested.md new file mode 100644 index 0000000..17ff29c --- /dev/null +++ b/src/typstonomicon/remove-indent-nested.md @@ -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 ++ +``` \ No newline at end of file