#let qctr = counter("question") #let pctr = counter("points") #let french_month = ("janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre") #let points_counter(h) = { // Find the first heading at a level equal or higher than this one let headings_after = query(selector(heading) .after(h.location()) ).filter(nh => nh.level >= h.level); let start_value = pctr.at(h.location()) let stop_value = if headings_after.len() == 0 { pctr.final() } else { pctr.at(headings_after.last().location()) } stop_value.at(0) - start_value.at(0) } #let show_points(pts) = [#pts] + if pts < 2 { " pt" } else { " pts" } // Rend les réponses visibles seulement si compilé avec `--input grading=true` #let grading(content) = if sys.inputs.at("grading", default: "solution") == "solution" { set text(fill: olive); content } else { hide(content) } #let exam(title: "Exam", course: none, date: none, class: none, author: none, subtitle: none, indications: none, doc) = { { set text(font: "Montserrat") let date = if date == none { datetime.today() } else { date }; align(center, text(size:26pt, course + " - " + date.display("[year]"))) align(center, text(size:26pt, title)) align(center, text(size:15pt, fill: luma(80), subtitle)) v(5%) align(center, text(size:14pt, author)) v(3%) align(center, text(size:14pt, date.display("[day] ") + french_month.at(date.month() - 1) + date.display(" [year]"))) v(7%) align(left, text(size: 20pt, "Nom :")) align(left, text(size: 20pt, "Prénom :")) v(3%) line(length: 100%, stroke: luma(80)) v(3%) text(size: 16pt, "Indications :") { set text(size: 12pt) set list(marker: "●", indent: 2em, body-indent: 1em) indications } } pagebreak() set text(font: "Carlito", size: 12pt) show heading: h => pad(bottom: 0.5em, text(fill: eastern, size: 16pt, weight: "light", h.body + [ (#show_points(points_counter(h)))])) doc }; #let question(points: 1, q, a) = { context pctr.step() let pts = strong([(#show_points(points))]); let num = context { qctr.step(); qctr.display() } [#num) #q #pts] let answ_block = block(width: 100%, inset: 1em, grading(a)); block(stroke: black, answ_block) }