Some must-have Typst general snippets
Last active
June 26, 2024 03:35
-
-
Save tapyu/7c961e9a891bd9087ce93c6949519b67 to your computer and use it in GitHub Desktop.
Typst general snippets
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
#show regex("function|if|or|and|return"): it => strong(it) | |
#set list(marker: none, indent: .7em) | |
#show list: it => block( | |
stroke: (left: 1pt), | |
outset: (left: -.3em, top: .8em), | |
inset: (left: -.4em, top: -.5em, bottom: .3em), | |
{ | |
place(dx: .6em + .5pt, dy: -.3em, line(length: .6em)) | |
it | |
place(dx: .6em + .5pt, dy: .3em, line(length: .6em)) | |
}, | |
) | |
function fib$(n)$: | |
- if $n < 0$: | |
- return null | |
- if $n = 0$ or $n = 1$: | |
- return $n$ | |
- return fib$(n-1) +$ fib$(n-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
#let tablemaker(data, header: none) = { | |
let items = data.pairs() | |
table( | |
columns: 2, | |
stroke: (x, y) => if y == 0 { (bottom: black) }, | |
..if header != none { (table.header(..header),) } else { () }, | |
..items.map(((key, value)) => ([*#key*], [#value])).flatten() | |
) | |
} | |
#tablemaker( | |
( | |
Name: [John], | |
Age: 25, | |
Data: [Cool] | |
), | |
header: ([*Property*], [*Value*]) | |
) |
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
// upright+bold (usually used for vectors and matrices | |
#let bu(it) = [ | |
$bold(upright(it))$ | |
] | |
// <a> | |
#let avg(it) = [ | |
$#lr(#sym.angle.l #it #sym.angle.r)$ | |
] | |
#let Re(it) = $op("Re") {#it}$ | |
#let Im(it) = $op("Im") {#it}$ | |
// expected value | |
#let exp(it) = $op("E ")[#it]$ | |
// script font | |
#let scr(it) = [ | |
#set text(stylistic-set: 1) | |
$cal(it)$ | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment