|
| 1 | +#import "@preview/latex-lookalike:0.1.4" |
| 2 | + |
| 3 | +#import "@preview/nth:1.0.1": nth |
| 4 | + |
| 5 | +// This function gets your whole document as its `body` and formats it as a lab |
| 6 | +// report. |
| 7 | +#let template( |
| 8 | + logo: image("/inc/default_logo.png", width: 4.3cm), |
| 9 | + title: "Lab report", |
| 10 | + sub-title: none, |
| 11 | + short-title: none, |
| 12 | + course-name: none, |
| 13 | + course-code: none, |
| 14 | + course-part: none, |
| 15 | + lab-name: none, |
| 16 | + author: none, |
| 17 | + lab-partners: none, |
| 18 | + lab-supervisor: none, |
| 19 | + lab-group: none, |
| 20 | + lab-date: none, |
| 21 | + |
| 22 | + // Report contents. |
| 23 | + body, |
| 24 | +) = { |
| 25 | + // Set document metadata. |
| 26 | + set document(title: title) |
| 27 | + |
| 28 | + // Set page size and margins. |
| 29 | + set page( |
| 30 | + paper: "a4", |
| 31 | + margin: (x: 2.5cm, top: 3.1cm, bottom: 3.55cm), |
| 32 | + header: { |
| 33 | + grid( |
| 34 | + columns: (2fr, 1fr, 2fr), |
| 35 | + align: (left, center, right), |
| 36 | + inset: (bottom: 5pt), |
| 37 | + // left |
| 38 | + course-code, |
| 39 | + // middle |
| 40 | + short-title, |
| 41 | + //right |
| 42 | + author, |
| 43 | + grid.hline(stroke: 0.4pt), |
| 44 | + ) |
| 45 | + }, |
| 46 | + ) |
| 47 | + |
| 48 | + // Set default font. |
| 49 | + set text(font: "New Computer Modern") |
| 50 | + |
| 51 | + set text(size: 1.05em) |
| 52 | + |
| 53 | + set par(justify: true) |
| 54 | + |
| 55 | + // Use arabic numbering of headings. |
| 56 | + set heading(numbering: "1.1") |
| 57 | + |
| 58 | + // Style outline as LaTeX "Table of contents". |
| 59 | + show outline: latex-lookalike.style-outline |
| 60 | + |
| 61 | + // Style headings with "1.1" numbering and increased spacing. |
| 62 | + show heading: latex-lookalike.style-heading |
| 63 | + |
| 64 | + // Style links and citations. |
| 65 | + let linkblue = rgb(66, 93, 178) |
| 66 | + show link: it => { |
| 67 | + set text(fill: linkblue) if type(it.dest) == str // style external links |
| 68 | + it |
| 69 | + } |
| 70 | + show cite: set text(fill: linkblue) |
| 71 | + |
| 72 | + // raw figures |
| 73 | + show figure.where(kind: raw): set figure.caption(position: top) |
| 74 | + |
| 75 | + show figure: outer => { |
| 76 | + let alignment = left |
| 77 | + if outer.kind == table or outer.kind == raw { |
| 78 | + alignment = center |
| 79 | + } |
| 80 | + show figure.caption: it => align( |
| 81 | + alignment, |
| 82 | + [ |
| 83 | + #strong[#it.supplement #context it.counter.display(it.numbering)#it.separator] |
| 84 | + #it.body |
| 85 | + ] |
| 86 | + ) |
| 87 | + outer |
| 88 | + } |
| 89 | + |
| 90 | + set bibliography(title: "References") |
| 91 | + |
| 92 | + // === [ Front matter ] ===================================================== |
| 93 | + |
| 94 | + // --- [ Front page ] ------------------------------------------------------- |
| 95 | + |
| 96 | + page( |
| 97 | + numbering: none, |
| 98 | + header: none, |
| 99 | + margin: (x: 1.55cm, top: 3.1cm, bottom: 3.55cm), |
| 100 | + )[ |
| 101 | + #grid( |
| 102 | + columns: (5.10cm, 1fr), |
| 103 | + gutter: 3pt, |
| 104 | + grid.vline(x: 1, stroke: 0.4pt + black), |
| 105 | + // left cell (logo) |
| 106 | + logo, |
| 107 | + // right cell (title) |
| 108 | + block(height: 100%, inset: 2.1em)[ |
| 109 | + #v(6.1cm) |
| 110 | + #if course-name != none { text(size: 1.2em)[ #course-name \ ] } |
| 111 | + #if course-code != none { text(size: 1.2em)[ (#course-code) ] } |
| 112 | + |
| 113 | + // title |
| 114 | + #text(size: 2.1em, weight: "bold", title) |
| 115 | + |
| 116 | + // subtitle |
| 117 | + #if sub-title != none { v(-1.5em) + text(size: 1.5em, weight: "bold", sub-title) } |
| 118 | + |
| 119 | + // date |
| 120 | + #text(size: 1.2em, { |
| 121 | + let today = datetime.today() |
| 122 | + nth(today.display("[day padding:none]")) |
| 123 | + today.display(" [month repr:long] [year]") |
| 124 | + }) |
| 125 | + |
| 126 | + #v(1fr) |
| 127 | + |
| 128 | + #let cells = () |
| 129 | + #if course-name != none { |
| 130 | + cells.push([Course:]) |
| 131 | + cells.push([#course-name]) |
| 132 | + } |
| 133 | + #if course-part != none { |
| 134 | + cells.push([Course part:]) |
| 135 | + cells.push([#course-part]) |
| 136 | + } |
| 137 | + #if lab-name != none { |
| 138 | + cells.push([Lab:]) |
| 139 | + cells.push([#lab-name]) |
| 140 | + } |
| 141 | + #if author != none { |
| 142 | + cells.push([Author:]) |
| 143 | + cells.push([#author]) |
| 144 | + } |
| 145 | + #if lab-partners != none { |
| 146 | + cells.push([Lab partner(s):]) |
| 147 | + cells.push([#lab-partners.join(", ", last: " and ")]) |
| 148 | + } |
| 149 | + #if lab-supervisor != none { |
| 150 | + cells.push([Lab supervisor:]) |
| 151 | + cells.push([#lab-supervisor]) |
| 152 | + } |
| 153 | + #if lab-group != none { |
| 154 | + cells.push([Lab group:]) |
| 155 | + cells.push([#lab-group]) |
| 156 | + } |
| 157 | + #if lab-date != none { |
| 158 | + cells.push([Lab date:]) |
| 159 | + cells.push([#lab-date]) |
| 160 | + } |
| 161 | + #block(inset: 0.4em)[ |
| 162 | + #grid( |
| 163 | + columns: (auto, 1fr), |
| 164 | + gutter: 10pt, |
| 165 | + ..cells, |
| 166 | + ) |
| 167 | + ] |
| 168 | + ], |
| 169 | + ) |
| 170 | + ] |
| 171 | + |
| 172 | + pagebreak(weak: true) |
| 173 | + |
| 174 | + // --- [ Table of contents ] ------------------------------------------------ |
| 175 | + |
| 176 | + set page(numbering: "i") |
| 177 | + counter(page).update(1) |
| 178 | + |
| 179 | + outline() |
| 180 | + pagebreak(weak: true) |
| 181 | + |
| 182 | + |
| 183 | + // --- [ Main matter ] ------------------------------------------------------ |
| 184 | + |
| 185 | + set page(numbering: "1") |
| 186 | + counter(page).update(1) |
| 187 | + |
| 188 | + body |
| 189 | +} |
0 commit comments