diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index a03baf3..ce8da4d 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -26,7 +26,7 @@ jobs: - name: Compile Typst to PDF uses: mkpoli/compile-typst-action@main with: - source_paths: "examples/exam-localization.typ examples/exam-minimal.typ" + source_paths: "examples/exam-localization.typ examples/exam-minimal.typ examples/exam-points-position.typ" root_path: '.' - name: Upload PDF file diff --git a/examples/exam-points-position.pdf b/examples/exam-points-position.pdf new file mode 100644 index 0000000..ba45cdf Binary files /dev/null and b/examples/exam-points-position.pdf differ diff --git a/examples/exam-points-position.typ b/examples/exam-points-position.typ new file mode 100644 index 0000000..a62127a --- /dev/null +++ b/examples/exam-points-position.typ @@ -0,0 +1,102 @@ +#import "../g-exam.typ": g-exam, g-question, g-subquestion +#import "@preview/cetz:0.2.1" + +#show: g-exam.with() + +#g-question(point: 2, point-position: right)[Question 1] + +#v(5cm) + +#g-question[ + Given the graphs of the following systems of linear equations, + Determines by the position of the lines the type of system according to the number of solutions. \ + +#columns(2, gutter: 2cm)[ + #g-subquestion(point: 0.5, point-position: left)[ + #align(center, + cetz.canvas(length: 0.7cm, { + cetz.plot.plot( + size: (10, 10), + axis-style: "school-book", + fill: "o" , + fill-below: true, + x-domain: (-5.2, 5.2), + y-domain: (-5.2, 5.2), + x-max: 5.2, + x-min:-5.2, + y-max: 5.2, + y-min:-5.2, + x-grid: "both", + y-grid: "both", + x-tick-step: 1, + y-tick-step: 1, + { + cetz.plot.add(((0,0),), mark-size: 0,) + + cetz.plot.add( + style: (stroke: blue + 2pt), + domain: (-5.2, 5.2), + x=>x + 3 + ) + + cetz.plot.add( + style: (stroke: olive + 2pt), + domain: (-5.2, 5.2), + x=>x + ) + } + ) + } + ) + ) + ] + #colbreak() + + #g-subquestion(point: 0.5, point-position: right)[ + #align(center, + cetz.canvas(length: 0.7cm, { + cetz.plot.plot( + size: (10, 10), + axis-style: "school-book", + fill: "o" , + fill-below: true, + x-domain: (-5.2, 5.2), + y-domain: (-5.2, 5.2), + x-max: 5.2, + x-min:-5.2, + y-max: 5.2, + y-min:-5.2, + x-grid: "both", + y-grid: "both", + x-tick-step: 1, + y-tick-step: 1, + { + cetz.plot.add(((0,0),), mark-size: 0,) + + cetz.plot.add( + style: (stroke: blue + 2pt), + domain: (-5.2, 5.2), + x=>-x - 4 + ) + + cetz.plot.add( + style: (stroke: olive + 2pt), + domain: (-5.2, 5.2), + x=>3 + ) + } + ) + } + ) + ) + ] +] +] + +#pagebreak() + +#g-question(point: 1)[Question 2] + +#g-question(point: 1.5, point-position: left)[Question 3] + +#g-question()[Question 4] \ No newline at end of file diff --git a/g-exam.typ b/g-exam.typ index 7205749..395c6b6 100644 --- a/g-exam.typ +++ b/g-exam.typ @@ -119,7 +119,14 @@ } } -#let g-question(point: none, body) = { +#let g-question( + point: none, + point-position: none, + body) = { + assert(point-position in (none, left, right), + message: "Invalid point position") + let __g-question-point-position = state("__g-question-point-position", none) + __g-question-number.step(level: 1) [#hide[]] @@ -130,9 +137,19 @@ }) locate(loc => { - let __g-question-point-position = __g-question-point-position-state.final(loc) + if __g-question-point-position == none { + __g-question-point-position.push(__g-question-point-position-state.final(loc)) + } + if point != 0 and __g-question-point-position == none { + __g-question-point-position.push(left) + + [kddffddekk #__g-question-point-position -----] + } + + [kkk #__g-question-point-position -----] if __g-question-point-position == left { + [bb] v(0.1em) { __g-question-number.display(__g-question-numbering) @@ -155,24 +172,39 @@ body } else { - v(0.1em) + [ccc] + v(0.1em) __g-question-number.display(__g-question-numbering) body } }) } -#let g-subquestion(point: none, body) = { +#let g-subquestion( + point: none, + point-position: none, + body) = { + + assert(point-position in (none, left, right), + message: "Invalid point position") + let __g-question-point-position = point-position + __g-question-number.step(level: 2) let subg-question-point = 0 if point != none { subg-question-point = point } __g-question-point.update(p => p + subg-question-point ) + locate(loc => { - let g-question-point-position = __g-question-point-position-state.final(loc) - - if g-question-point-position == left { + if __g-question-point-position == none { + let __g-question-point-position = __g-question-point-position-state.final(loc) + } + if point != 0 and __g-question-point-position == none { + let __g-question-point-position = left + } + + if __g-question-point-position == left { v(0.1em) { h(0.7em) @@ -184,7 +216,7 @@ } body } - else if g-question-point-position == right { + else if __g-question-point-position == right { v(0.1em) if(point != none) { place(right,