Initial commit

This commit is contained in:
Lyes Saadi 2026-01-15 17:26:07 +01:00
commit 940f1f64b2
Signed by: lyes
GPG key ID: 55A1D803917CF39A
10 changed files with 406 additions and 0 deletions

69
environment.typ Normal file
View file

@ -0,0 +1,69 @@
#import "palette.typ": *
#let envc = counter("environment")
#let count(counter, follows) = {
let c = counter;
if c == auto {
c = envc;
}
if type(c) == str {
c
} else if not follows {
c.step()
context c.display()
} else {
context c.display()
}
}
#let environment(body, name: "Environment", subtitle: none, counter: auto, follows: false, boxed: true, margin: 2.5cm, scheme: light) = [
#v(10pt)
// #v(margin + 2pt)
#pad(block(
width: 100% + 2*margin,
inset: (left: margin, right: margin, top: 1em, bottom: 1em),
fill: scheme.env.bg,
stroke: (top: scheme.env.stroke, bottom: scheme.env.stroke),
breakable: true,
text(fill: scheme.env.fg)[
#place(
block(
fill: scheme.env.bg,
inset: .4em,
radius: .2em,
stroke: scheme.env.title-stroke,
)[
#text(
name + if counter != none { " " + count(counter, follows) } + if subtitle != none { ":" },
weight: if not follows { "bold" } else { "regular" },
style: if follows { "italic" } else { "normal" },
fill: scheme.env.fg
)
#if cite != none {
subtitle
}
],
dx: -3em, dy: -1.8em
)
#body
]),
left: -margin,
right: margin)
// top: -margin - 2pt,
// bottom: -margin - 2pt)
// #v(margin + 2pt)
]
#let environment_(body, name: "Environment", counter: auto, follows: false, boxed: true, margin: 2.5cm, scheme: light) = {
scheme.env.insert("bg", scheme.bg)
scheme.env.insert("title-stroke", none)
scheme.env.insert("stroke", scheme.env.sub-stroke)
environment(body, name: name, counter: counter, follows: follows, boxed: boxed, margin: margin, scheme: scheme)
}

3
lib.typ Normal file
View file

@ -0,0 +1,3 @@
#import "palette.typ": *
#import "paper.typ": paper, abstract
#import "environment.typ": environment, environment_

97
math.typ Normal file
View file

@ -0,0 +1,97 @@
#let math_shorthands = (
($-o$, $multimap$),
($~=$, $tilde.equiv$),
($(*)$, $times.o$),
($(times)$, $times.o$),
($(+)$, $plus.o$),
($(plus)$, $plus.o$),
($|=$, $tack.r.double$),
($|-$, $tack.r$),
($t->$, $mapsto$),
($t-->$, $mapsto.long$),
)
#let par = rotate(180deg, "&")
#let yo = $$
#let inj = $"inj"$
#let lA = $overline(A)$
#let lB = $overline(B)$
#let lC = $overline(C)$
#let lD = $overline(D)$
#let lE = $overline(E)$
#let lF = $overline(F)$
#let lG = $overline(G)$
#let lH = $overline(H)$
#let lI = $overline(I)$
#let lJ = $overline(J)$
#let lK = $overline(K)$
#let lL = $overline(L)$
#let lM = $overline(M)$
#let lN = $overline(N)$
#let lO = $overline(O)$
#let lP = $overline(P)$
#let lQ = $overline(Q)$
#let lR = $overline(R)$
#let lS = $overline(S)$
#let lT = $overline(T)$
#let lU = $overline(U)$
#let lV = $overline(V)$
#let lW = $overline(W)$
#let lX = $overline(X)$
#let lY = $overline(Y)$
#let lZ = $overline(Z)$
#let la = $overline(a)$
#let lb = $overline(b)$
#let lc = $overline(c)$
#let ld = $overline(d)$
#let le = $overline(e)$
#let lf = $overline(f)$
#let lg = $overline(g)$
#let lh = $overline(h)$
#let li = $overline(i)$
#let lj = $overline(j)$
#let lk = $overline(k)$
#let ll = $overline(l)$
#let lm = $overline(m)$
#let ln = $overline(n)$
#let lo = $overline(o)$
#let lp = $overline(p)$
#let lq = $overline(q)$
#let lr = $overline(r)$
#let ls = $overline(s)$
#let lt = $overline(t)$
#let lu = $overline(u)$
#let lv = $overline(v)$
#let lw = $overline(w)$
#let lx = $overline(x)$
#let ly = $overline(y)$
#let lz = $overline(z)$
#let cA = math.cal("A")
#let cB = math.cal("B")
#let cC = math.cal("C")
#let cD = math.cal("D")
#let cE = math.cal("E")
#let cF = math.cal("F")
#let cG = math.cal("G")
#let cH = math.cal("H")
#let cI = math.cal("I")
#let cJ = math.cal("J")
#let cK = math.cal("K")
#let cL = math.cal("L")
#let cM = math.cal("M")
#let cN = math.cal("N")
#let cO = math.cal("O")
#let cP = math.cal("P")
#let cQ = math.cal("Q")
#let cR = math.cal("R")
#let cS = math.cal("S")
#let cT = math.cal("T")
#let cU = math.cal("U")
#let cV = math.cal("V")
#let cW = math.cal("W")
#let cX = math.cal("X")
#let cY = math.cal("Y")
#let cZ = math.cal("Z")

105
palette.typ Normal file
View file

@ -0,0 +1,105 @@
#let broken-stroke(paint) = (thickness: 1pt, paint: paint, dash: (array: (2em, 1em, 1em, 1em)))
#let dotted-stroke(paint) = (thickness: 1pt, paint: paint, dash: "densely-dotted")
#let fill-stroke(paint) = (thickness: 1pt, paint: paint)
#let light = (
bg: white,
fg: black,
title: (
bg: rgb("eee"),
fg: black,
sub: rgb("555"),
stroke: broken-stroke(rgb("999")),
),
env: (
bg: rgb("eee"),
fg: black,
stroke: broken-stroke(rgb("999")),
title-stroke: fill-stroke(rgb("999")),
sub-stroke: dotted-stroke(rgb("999")),
),
)
#let printing = (
bg: white,
fg: black,
title: (
bg: white,
fg: black,
sub: rgb("555"),
stroke: broken-stroke(black),
),
env: (
bg: white,
fg: black,
stroke: broken-stroke(black),
title-stroke: fill-stroke(black),
sub-stroke: dotted-stroke(black),
),
)
#let ensps-light = (
bg: light.bg,
fg: light.fg,
title: (
bg: rgb("00778b"),
fg: white,
sub: rgb(255, 255, 255, 200),
img: (
path: "static/ensps.png"
),
stroke: broken-stroke(color.hsl(187deg, 80%, 20%)),
),
env: light.env
)
#let dark = (
bg: black,
fg: white,
title: (
bg: rgb("111"),
fg: white,
sub: rgb("aaa"),
stroke: broken-stroke(rgb("777")),
),
env: (
bg: rgb("111"),
fg: white,
stroke: broken-stroke(rgb("777")),
title-stroke: fill-stroke(rgb("777")),
sub-stroke: dotted-stroke(rgb("777")),
),
)
#let ensps-dark = (
bg: dark.bg,
fg: dark.fg,
title: (
bg: rgb("00778b"),
fg: white,
sub: rgb(255, 255, 255, 200),
img: (
path: "static/ensps.png"
),
stroke: broken-stroke(color.hsl(187deg, 80%, 20%)),
),
env: dark.env
)
#let night = (
bg: rgb("#111b3b"),
fg: rgb("#f2ecbe"),
title: (
bg: rgb("#1c113a"),
fg: rgb("#f2ecbe"),
sub: rgb("#f2ecbe"),
stroke: broken-stroke(rgb("#3a3011")),
),
env: (
bg: rgb("#1c113a"),
fg: rgb("#f2ecbe"),
stroke: broken-stroke(rgb("#3a3011")),
title-stroke: fill-stroke(rgb("#3a3011")),
sub-stroke: dotted-stroke(rgb("#3a3011")),
),
)

80
paper.typ Normal file
View file

@ -0,0 +1,80 @@
#import "palette.typ": *
#import "environment.typ": *
#import "math.typ": math_shorthands
#import "@preview/quick-maths:0.2.1": shorthands
#let header(title, author, scheme, margin) = (
context {
let p = here().page()
// if p >= 1 {
move(dx: - margin - 1pt, block(
width: 100% + 2*margin + 2pt,
height: margin,
stroke: scheme.title.stroke,
fill: scheme.title.bg,
)[
#place(top + left, block(inset: 30% * margin)[#text(title, scheme.title.fg) #text("- " + author, scheme.title.sub)])
#place(top + right, block(inset: 30% * margin, text(scheme.title.fg)[Page #p / #counter(page).final().at(0)]))
])
// }
}
)
#let paper(
body,
title: "Titre",
subtitle: none,
author: "Lyes Saadi",
scheme: light,
margin: 2.5cm,
) = [
#set document(title: title, author: author)
#set page(fill: scheme.bg, footer: header(title, author, scheme, margin), margin: margin)
#set text(fill: scheme.fg, font: "New Computer Modern")
#set table(stroke: scheme.fg)
#set heading(numbering: "I.1 -")
#show heading: it => [
#block[
#place(text("#", size: 0.8em), dx: -0.8em)
#it
]
]
#show heading.where(level: 1): it => [
#move(block(
text(it, scheme.title.fg),
width: 100% + 2*margin,
inset: (left: margin, right: margin, top: 1em, bottom: 1em),
fill: scheme.title.bg,
stroke: (top: scheme.title.stroke, bottom: scheme.title.stroke),
), dx: -margin)
]
#show <nonumber>: set heading(numbering: none)
#show: shorthands.with(..math_shorthands)
#move(block(
[
#if "img" in scheme.title.keys() and scheme.title.img != none {
place(top + right, image(scheme.title.img.path, height: margin), dx: margin, dy: -margin)
}
#align(center, text(size: 3em, title, fill: scheme.title.fg))
#align(center, text(size: 2em, fill: scheme.title.sub, subtitle))
#align(center, text(size: 1.5em, fill: scheme.title.sub, author))
],
fill: scheme.title.bg,
inset: margin,
height: auto,
width: 100% + 2 * margin,
stroke: (bottom: scheme.title.stroke),
), dx: -margin, dy: -margin)
#body
]
#let abstract(body, name: [Abstract.], margin: 2.5cm) = {
align(center, move(dy: -margin/2, block(width: 75%, par(justify: true)[#text(name, weight: "bold") #text(style: "italic", body)])))
}

6
state.typ Normal file
View file

@ -0,0 +1,6 @@
#import "palette.typ": *
#let template = (
margin: 0,
scheme: light,
)

BIN
static/ensps.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
test.pdf Normal file

Binary file not shown.

39
test.typ Normal file
View file

@ -0,0 +1,39 @@
#import "lib.typ": *
#show: paper.with(scheme: ensps-light, title: "Devoir Maison de Catégories", subtitle: "2ème DM")
= hi
#lorem(40)
== hi
#lorem(40)
== hi
#lorem(40)
=== hi
#lorem(40)
=== hi
#lorem(40)
== hi
#lorem(40)
=== hi
#lorem(40)
= hi
#lorem(40)
== hi
#lorem(40)
=== hi
#lorem(40)
= hi
#lorem(40)
== hi
#lorem(40)
=== hi
#lorem(40)

7
typst.toml Normal file
View file

@ -0,0 +1,7 @@
[package]
name = "lyes-typstbox"
version = "0.1.0"
entrypoint = "lib.typ"
authors = ["Lyes Saadi <dev@lyes.eu>"]
license = "MIT-0"
description = "Lyes' Typst ToolBox"