diff options
author | Sudipto Mallick <smlckz@termux-alpine> | 2024-01-12 10:13:01 +0000 |
---|---|---|
committer | Sudipto Mallick <smlckz@termux-alpine> | 2024-01-12 10:13:01 +0000 |
commit | ac7aba2bacaaf74a91e218ee537fe3bf267b8e4d (patch) | |
tree | ffa6a98fa31b9031b918d448a6cb7744ad66122d /java | |
parent | 87554cf575a4a92f00908a7cccfe6c92db2ef3ef (diff) | |
download | zadania-ac7aba2bacaaf74a91e218ee537fe3bf267b8e4d.tar.gz |
Initial implementation of complete assignment
This is the initial implementation of the generation of complete document of the assignments. java/buildall: Generates a Typst document from the list of assignments in `alist.txt` (needs to updated to work with `state.sql` in future). java/prelude.typ: Contains the prelude code responsible for generating the table of contents, using the facilities provided by Typst. java/template.typ: Updated so that it can be used with `prelude.typ` for generating the table of contents. .gitignore: To ignore `all.typ`, which is a build artifact.
Diffstat (limited to 'java')
-rw-r--r-- | java/buildall | 6 | ||||
-rw-r--r-- | java/prelude.typ | 38 | ||||
-rw-r--r-- | java/template.typ | 17 |
3 files changed, 54 insertions, 7 deletions
diff --git a/java/buildall b/java/buildall index 7cdd0c0..4468d35 100644 --- a/java/buildall +++ b/java/buildall @@ -1,4 +1,4 @@ #!/bin/sh - -awk '$3 == "#" { printf("#include(\"text/%s.typ\")\n", $2) }' alist.txt > all.typ -typst compile --root $PWD all.typ a/all.pdf +cat prelude.typ > all.typ +awk '$2 == "#" { printf("#include(\"text/%s.typ\")\n", $1) }' alist.txt >> all.typ +typst compile --root $PWD all.typ docs/all.pdf diff --git a/java/prelude.typ b/java/prelude.typ new file mode 100644 index 0000000..027bfef --- /dev/null +++ b/java/prelude.typ @@ -0,0 +1,38 @@ +#import "@preview/tablex:0.0.7": tablex, cellx +#import "/template.typ": * + +#apply(page-numbering: "(i)" , [ + #align(center, [== Contents]) + #let heading-format(content) = cellx(align: center + horizon, content) + #let col-aligns = (right, auto, center + horizon, center + horizon, auto) + #let preprocess-alist(l, lpno) = { + let i = 0 + let e = l.len() - 1 + let nl = () + while i < e { + let it = l.at(i) + i = i + 1 + let nit = l.at(i) + it.at(2) = [ #it.at(2) - #{nit.at(2) - 1} ] + it.push([]) + nl.push(it) + } + l.at(e).at(2) = [ #{l.at(e).at(2)} - #lpno ] + l.at(e).push([]) + nl.push(l.at(e)) + nl + } + #list-of-assignments((l, lpno) => + tablex( + columns: (3em, 1fr, 4em, 8em, 10em), + stroke: 1pt + gray, + map-cols: (i, cells) => (cells.first(), ..cells.slice(1).map(cell => (..cell, align: col-aligns.at(i)))), + heading-format[*Sl.* \ *No.*], heading-format[*Description*], heading-format[*Page No.*], heading-format[*Date*], heading-format[*Teacher’s* \ *Signature*], + ..preprocess-alist(l, lpno).flatten(), + )) +]) + +#colbreak() + +#counter(page).update(0) + diff --git a/java/template.typ b/java/template.typ index 47a97a1..57e2e48 100644 --- a/java/template.typ +++ b/java/template.typ @@ -31,13 +31,13 @@ } /* Draws page border around the provided content, taking an optional function to be called at the footer. */ -#let apply-page-borders(body, ..font-options, footer-special-func: none) = { +#let apply-page-borders(body, ..font-options, footer-special-func: none, page-numbering: none) = { let page-margin = (left: 0.75in, right: 0.25in, top: 0.25in, bottom: 0.25in) let margin = (left: 0.65in, right: 0.15in, top: 1.5em, bottom: 1.5em) let page-border-thickness = 1.25pt set page( margin: (..page-margin, bottom: margin.bottom + 2em), - numbering: "1", + numbering: if page-numbering != none { page-numbering } else { "1" }, background: align(top + start, pad(..margin, rect(width: 100%, height: 100%, stroke: page-border-thickness + gray, radius: 5pt))), footer: locate(loc => { align(center, move(dy: -margin.bottom + 1em, text(..font-options, size: 9pt, counter(page).display(loc.page-numbering())))) @@ -50,7 +50,7 @@ body } -#let apply(body) = { +#let apply(body, page-numbering: none) = { let body-font-settings = (font: "Nunito Sans 10pt", size: 12pt, stretch: 75%) // let body-font-settings = (font: "Hanken Grotesk", size: 12pt, stretch: 75%) set text(..body-font-settings) @@ -74,7 +74,7 @@ show raw.where(block: true): it => align(left, it) set list(marker: ([$square.filled.tiny$], [--])) set par(leading: 0.5em) - apply-page-borders(body, ..body-font-settings, footer-special-func: signature-footer) + apply-page-borders(body, ..body-font-settings, footer-special-func: signature-footer, page-numbering: page-numbering) } #let scos(name) = { @@ -86,9 +86,18 @@ include ofname } +#let alist = state("assignment-list", ()) + +#let list-of-assignments(cb) = locate(loc => { + let l = alist.final(loc) + let lpno = counter(page).final(loc).first() + cb(l, lpno) +}) + #let assignment(number, description) = align(center, [ = #text(weight: 600, [Assignment #number]) == #text(weight: 500, [Program statement:]) #text(weight: 400, description) +#locate(loc => alist.update(lst => (..lst, (number, description, counter(page).at(loc).first(), [])))) ]) #let skind(kind) = [ |