typ-notes/lib.typ

134 lines
3.2 KiB
Plaintext

#import "@preview/gviz:0.1.0"
#import "@preview/pintorita:0.1.0"
#let todo-list = state("todo-list",())
#let show-todos = state("show-todos", true)
#let todo(done: false, content) = context {
if (not done) and (show-todos.get()) {
let todonum = todo-list.get().len() + 1
text(weight: "bold", fill: red, [TODO n°#todonum #label("todo-"+str(todonum)): #content])
todo-list.update(x => x + (("todo-"+str(x.len()+1),x.len()+1, content),))
}
}
#let todos() = context {
if (todo-list.final().len() != 0) and (show-todos.get()) {
pagebreak(weak: true)
[= TO-DOs]
for t in todo-list.final() {
let l = label(t.first())
list.item(link(l)[TODO n°#t.at(1) p.#locate(l).page() : #t.last()])
}
}
}
#let logos = (
"pirat": image("img/pirat.png", width: 30mm),
"pains-perdus": image("img/pains-perdus.png", width: 25mm),
)
#let note_header(title: [ Notes ], authors: (), date: datetime.today(), logo: none, ..args) = {
align(center, text(size: 20pt, title))
if logo != none {
context {
place(
top+left,
dy: -page.margin*0.8,
dx: -page.margin*0.8,
logos.at(logo)
)
}
}
place(top+right, date.display())
if authors != () {
align(center)[
//By:
#v(16pt, weak: true)
#for author in authors {
author
v(16pt, weak: true)
}
]
}
outline(indent: 2em, fill: none)
}
#let research_journal_header(title: "Research Journal", ..args) = {
show link: underline
show heading.where(level: 2): it => {
it
v(5pt, weak: true)
line(length: 100%)
}
// Setup level3 headings
show heading.where(level: 3): it => {
block(smallcaps(it.body))
}
// Set Make title
align(center, text(size: 20pt, font: "Indie Flower", title))
v(2em)
}
#let notes-template(
title: none,
doc_type: none,
keywords: (),
authors: none,
date: none,
logo: none,
doc) = {
set document(title: title)
show raw.where(lang: "dot-render"): it => gviz.render-image(it.text)
show raw.where(lang: "digraphLR"): it => gviz.render-image("digraph mygraph { rankdir=\"LR\";" + it.text + "}")
show raw.where(lang: "digraphTB"): it => gviz.render-image("digraph mygraph { rankdir=\"TB\";" + it.text + "}")
show raw.where(lang: "graphLR"): it => gviz.render-image("graph mygraph { rankdir=\"TB\";" + it.text + "}")
show raw.where(lang: "graphTB"): it => gviz.render-image("graph mygraph { rankdir=\"TB\";" + it.text + "}")
show raw.where(lang: "pintora"): it => pintorita.render(it.text)
// Make keywords bold
show: rest => {
for keyword in keywords {
rest = {
show keyword: set text(weight: "bold")
rest
}
}
rest
}
let args = (:)
for (arg, val) in (
"title": title,
"keywords": keywords,
"authors": authors,
"date": date,
"logo": logo,
) {
if val != none {
args.insert(arg, val)
}
}
set page(
height: auto,
margin: 25mm,
) if doc_type == "notes"
if doc_type == "notes" {
// TODO: import from file instead?
note_header(..args)
} else if doc_type == "research_journal" {
research_journal_header(..args)
} else {
assert.eq(doc_type, none, message: "unknown document type: " + doc_type)
}
doc
todos()
}