- Must-have Typst general snippets
- Preamble
Last active
August 3, 2024 05:01
-
-
Save tapyu/7c961e9a891bd9087ce93c6949519b67 to your computer and use it in GitHub Desktop.
Typst general snippets
This file contains hidden or 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
// *** packages *** | |
#import "@preview/unify:0.6.0": num,qty,numrange,qtyrange | |
#import "@preview/pinit:0.1.4": * // pin things as you like | |
#import "@preview/physica:0.9.3": * // physics-like package | |
// *** operations *** | |
// 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)$ | |
] | |
// Real/Imag | |
#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)$ | |
] |
This file contains hidden or 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 hidden or 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*]) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment