Typst-Snippets/utils.typ

86 lines
2.2 KiB
Plaintext

#import "@preview/showybox:2.0.1": showybox
#import "@preview/physica:0.9.0" as ph
#import "@preview/pinit:0.1.2": *
#let sp = [#h(0.5em)]
#let pm = [#sym.plus.minus]
#let le = [#sym.lt.eq.slant]
#let ge = [#sym.gt.eq.slant]
#let sim = [#sym.tilde.op]
#let inf = [#sym.infinity]
#let rm(body) = {math.upright(body)}
#let iso(b, A) = [#ph.isotope(b, a: A)]
#let isoz(b, A, Z) = [#ph.isotope(b, a: A, z: Z)]
#let isobox(body, width: 25pt, fill: white) = {block(
fill: fill,
stroke: black,
width: width,
height: width,
align(center + horizon)[#body]
)}
#let box-quote(body, width: 100%, inset: 5pt, outset: 0pt) = {block(
fill: green.lighten(80%),
width: width,
inset: inset,
outset: outset,
radius: 4pt,
stroke: green.darken(60%),
breakable: true,
body
)}
#let box-confusion(body, width: 100%, inset: 8pt, outset: 0pt) = {block(
fill: red.lighten(80%),
width: width,
inset: inset,
outset: outset,
radius: 4pt,
stroke: red.darken(60%),
breakable: false,
body
)}
#let box-title(content, title: none) = {showybox(
title: title,
frame: (
title-color: red.darken(30%),
border-color: red.darken(30%),
body-color: red.lighten(90%),
radius: 0pt,
thickness: 2pt,
),
above: 0.5em,
below: 0.5em,
breakable: false,
content
)}
#let mark-quote(body) = {
rect(fill: luma(240), stroke: (left: 0.25em), inset: (left: 0.5em), body)
}
#let pinit-highlight-equation-from(height: 2em, extended-height: 1.4em, pos: bottom, fill: rgb(0, 180, 255), highlight-pins, point-pin, body) = {
pinit-highlight(..highlight-pins, dy: -extended-height / 2, extended-height: extended-height, fill: rgb(..fill.components().slice(0, -1), 40))
pinit-point-from(
fill: fill,
pin-dx: -0.6em,
pin-dy: if pos == bottom { 0.8em } else { -0.6em },
body-dx: 0pt,
body-dy: if pos == bottom { -0.05em } else { -1.4em },
offset-dx: -0.6em,
offset-dy: if pos == bottom { 0.8em + height } else { -0.6em - height },
point-pin,
rect(
inset: if pos == bottom { 0.4em } else { 0.4em },
stroke: (
bottom: if pos == bottom { 0em } else { 0.12em } + fill,
top: if pos == bottom { 0.12em } else { 0em } + fill
), {
set text(fill: fill)
body
}
)
)
}