diff options
author | Sudipto Mallick <> | 2024-01-02 02:12:16 +0000 |
---|---|---|
committer | Sudipto Mallick <> | 2024-01-02 02:12:16 +0000 |
commit | a70e0a59817ce06a3dd23b3750ae16ee6660deaf (patch) | |
tree | 0843bf4d30edf22c9c4c27ff4887351c85993ccd /java/template.typ | |
parent | 63c589e826829c5f47f95a5642531e02b2b2c8f7 (diff) | |
download | zadania-a70e0a59817ce06a3dd23b3750ae16ee6660deaf.tar.gz |
Add Java assignments to the repository
.gitignore: The build files, files left by editors like *~ and the PDF documents for the assignments are to be ignored for the purposes of version control. README.rst: Rewrite, with one line description in Chinese. java/alist.txt: List of assignments, sorted in the order of the list of assignments, with the ones with completed documentation marked with `#`. java/buildall: Script that will build all of the assignments into one PDF file; to be rehauled for the final document. code/*.java: The Java source code for the assignments. dbld: Script that builds a PDF document for a single assignment. index.typ: The list of assignments, subject to update for further refinement and inclusion of yet more assignments. jbld: Script that compiles code for a single Java assignment. output/*.typ: Typst file containing the output (sessions) obtained from running the individual Java assignments. state.sql: Future alternative to `alist.txt`, under development. template.typ: The Typst template used across all of assignment, containing common code for the uniform styling, such as page border. text/*.typ: Typst file documenting each Java assignment. vendor/Java.sublime-syntax: Updated Sublime Text syntax file for Java, used for newer syntax features, such as `var`, not yet available in syntaxes shipped with Typst. vendor/gr.tmTheme: A grayscale TextMate theme to be used for code in the documents generated by Typst suitable for black and white printing. wltd: Difference between the files in `code/` and `text/`, and `code/` and `output`; need to be rewritten along with `state.sql`.
Diffstat (limited to 'java/template.typ')
-rw-r--r-- | java/template.typ | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/java/template.typ b/java/template.typ new file mode 100644 index 0000000..47a97a1 --- /dev/null +++ b/java/template.typ @@ -0,0 +1,100 @@ +#import "@preview/codelst:1.0.0": sourcefile, sourcecode + +/* 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)))) + +/* Highlight output code block. */ +#let highlight-output(body) = sourcecode(numbering: none, body) + +/* The state variable to indicate whether the end of an assignment is reached. */ +#let eoa = state("is-at-end-of-assignment", false) + +/* Updates the state variable to indicate the end of an assignment. */ +#let signature() = { + eoa.update(true) +} + +/* Draws the signature construct at the bottom right corner in the footer of the last page of an assignment. */ +#let signature-footer(loc) = { + if eoa.at(loc) { + align(bottom + right, + move(dy: -4em, dx: -1em, + block(width: 15em)[ + #v(3em) + #line(length: 100%) \ + #v(-2.5em) + #align(center)[Teacher’s signature] + ])) + eoa.update(false) + } +} + +/* 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 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", + 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())))) + if footer-special-func != none { + footer-special-func(loc) + } + }) + ) + show: block.with(breakable: true, width: 100%, inset: page-border-thickness + 1em) + body +} + +#let apply(body) = { + 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) + + let code-color = rgb("#f4f4f4") + show raw: set text(font: "Iosevka Fixed", size: 1.1em) + set raw(syntaxes: "vendor/Java.sublime-syntax") + set raw(theme: "vendor/gr.tmTheme") + show raw.where(block: false): box.with( + fill: code-color, + inset: (x: 3pt, y: 0pt), + outset: (y: 3pt), + radius: 2pt, + ) + show raw.where(block: true): block.with( + fill: code-color, + inset: 10pt, + radius: 4pt, + width: 100%, + ) + 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) +} + +#let scos(name) = { + v(1em) + [=== Source Code] + highlight-code-file("/code/" + name + ".java") + [=== Output] + let ofname = "/output/" + name + ".typ" + include ofname +} + +#let assignment(number, description) = align(center, [ += #text(weight: 600, [Assignment #number]) +== #text(weight: 500, [Program statement:]) #text(weight: 400, description) +]) + +#let skind(kind) = [ + ==== #text(weight: 500, kind) +] + +#let objective(body) = align(center, [*Objective*: #body]) +#let oset(kind) = block(spacing: 0.6em, [===== #h(1em) #kind]) + |