diff options
author | Sudipto Mallick <smlckz@termux-alpine> | 2024-01-27 08:11:27 +0000 |
---|---|---|
committer | Sudipto Mallick <smlckz@termux-alpine> | 2024-01-27 08:21:21 +0000 |
commit | 36873dd5ac49508b455096e1755740788c49a26f (patch) | |
tree | 87c9b90fccda7307bbab11a37c42ee232a6ed0c3 | |
parent | 13f9553a26a51b95ab194e5328ad302b35d7b118 (diff) | |
download | zadania-36873dd5ac49508b455096e1755740788c49a26f.tar.gz |
Rewrite Java assignment prelude to be more readable
-rw-r--r-- | java/prelude.typ | 46 | ||||
-rw-r--r-- | java/template.typ | 11 |
2 files changed, 35 insertions, 22 deletions
diff --git a/java/prelude.typ b/java/prelude.typ index 027bfef..41eedc5 100644 --- a/java/prelude.typ +++ b/java/prelude.typ @@ -4,31 +4,39 @@ #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) + #let column-alignments = (right, auto, center + horizon, center + horizon, auto) + #let preprocess-alist(assignment-list, last-page-number) = { + let index = 0 + let last-index = assignment-list.len() - 1 + let page-number-list = () + while index < last-index { + let item = assignment-list.at(index) + let next-item = assignment-list.at(index + 1) + let starting-page-number = item.page-number + let finishing-page-number = next-item.page-number - 1 + page-number-list.push((starting-page-number, finishing-page-number)) + index = index + 1 } - l.at(e).at(2) = [ #{l.at(e).at(2)} - #lpno ] - l.at(e).push([]) - nl.push(l.at(e)) - nl + page-number-list.push((assignment-list.at(last-index).page-number, last-page-number)) + let new-assignment-list = () + index = 0 + for (start, end) in page-number-list { + let page-number = [#start - #end] + if start == end { page-number = [#start] } + let assignment = assignment-list.at(index) + let item = ([#{assignment.number}. ], assignment.description, page-number, [], []) + new-assignment-list.push(item) + index = index + 1 + } + new-assignment-list } - #list-of-assignments((l, lpno) => + #list-of-assignments((assignment-list, last-page-number) => 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)))), + map-cols: (i, cells) => (cells.first(), ..cells.slice(1).map(cell => (..cell, align: column-alignments.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(), + ..preprocess-alist(assignment-list, last-page-number).flatten(), )) ]) diff --git a/java/template.typ b/java/template.typ index 30c0a81..0d85269 100644 --- a/java/template.typ +++ b/java/template.typ @@ -2,7 +2,7 @@ /* Highlights the source code file. */ #let highlight-code-file(filename) = sourcefile(read(filename), file: filename, lang: "java-new", - numbers-style: (lno) => align(right, move(dy: 1pt, text(fill: luma(120), size: 9pt, lno)))) + numbers-style: (line-number) => align(right, move(dy: 1pt, text(fill: luma(120), size: 9pt, line-number)))) /* Highlight output code block. */ #let highlight-output(body) = sourcecode(numbering: none, body) @@ -82,6 +82,7 @@ [=== Source Code] highlight-code-file("/code/" + name + ".java") [=== Output] + v(-1em) let ofname = "/output/" + name + ".typ" include ofname } @@ -94,9 +95,10 @@ cb(l, lpno) }) -#let assignment(number, description, block: false) = align(center, [ +#let assignment(number, description, block: false, reduce-gap: false, pad: false) = align(center, [ = #text(weight: 600, [Assignment #number]) #{ + if reduce-gap { v(-0.75em) } if block == true [ #set par(justify: true) #align(left)[ @@ -106,7 +108,10 @@ == #text(weight: 500, [Program statement:]) #text(weight: 400, description) ] } -#locate(loc => alist.update(lst => (..lst, (number, description, counter(page).at(loc).first(), [])))) + #{ + let desc = if pad { [#description \ \ ] } else { description } + locate(loc => alist.update(lst => (..lst, (number: number, description: desc, page-number: counter(page).at(loc).first())))) + } ]) #let skind(kind) = [ |