From cd3c5dac83c3a238cdefa24ceede01a1b4047b2c Mon Sep 17 00:00:00 2001 From: Jean-Marie 'Histausse' Mineau Date: Fri, 22 Mar 2024 19:33:13 +0100 Subject: [PATCH] add template selection --- README.md | 10 +++++++++- lib.typ | 38 +++++++++++++++++++++++++++++++++++++- template/main.typ | 2 +- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6f76dbd..2c92bca 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ a -- b; b -- c; c -- a; \``` +``` ``` \```pintora @@ -76,7 +77,6 @@ mindmap *** DOT Diagram \``` ``` -``` ### Todo @@ -98,6 +98,14 @@ To hid todos, you can add this line at the top of the document: #show-todos.update(_ => false) ``` +### Templates + +Parameters can be passed to the template depending on the usage. The `doc_type` parameter indicate the specific template to use: + +``` +#show: notes-template.with(doc_type: "research_journal", keywords: ("ipsum",)) +``` + ## TODO: - biblio diff --git a/lib.typ b/lib.typ index 4a6bc98..77ff945 100644 --- a/lib.typ +++ b/lib.typ @@ -23,7 +23,29 @@ } } -#let notes-template(keywords: (), doc) = { +#let note_header(title: "Notes", ..args) = { + [ = #title ] +} + +#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: (), doc) = { 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 + "}") @@ -42,6 +64,20 @@ rest } + let args = (:) + for (arg, val) in ("title": title, "keywords": keywords) { + if val != none { + args.insert(arg, val) + } + } + if doc_type == "notes" { + 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() diff --git a/template/main.typ b/template/main.typ index b8ed9d8..19dd830 100644 --- a/template/main.typ +++ b/template/main.typ @@ -1,5 +1,5 @@ #import "@local/notes:0.0.1": * -#show: notes-template +#show: notes-template.with(doc_type: "research_journal", keywords: ("ipsum",)) ```dot-render digraph mygraph {