diff --git a/.github/workflows/check-pr.yml b/.github/workflows/check-pr.yml new file mode 100644 index 0000000..6333ac2 --- /dev/null +++ b/.github/workflows/check-pr.yml @@ -0,0 +1,19 @@ +on: + pull_request: + +jobs: + check-pr: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Typstyle + run: | + mkdir -p "$HOME/.local/bin" + wget "https://github.com/typstyle-rs/typstyle/releases/latest/download/typstyle-x86_64-unknown-linux-gnu" -O "$HOME/.local/bin/typstyle" + chmod +x "$HOME/.local/bin/typstyle" + echo "$HOME/.local/bin" >> "$GITHUB_PATH" + - name: Format typst files + run: typstyle --inplace src examples tests + - uses: getsentry/action-git-diff-suggestions@main + with: + message: "Typstyle suggested changes" diff --git a/book/src/toolbox/progress.typ b/book/src/toolbox/progress.typ index df25f48..74bfc12 100644 --- a/book/src/toolbox/progress.typ +++ b/book/src/toolbox/progress.typ @@ -9,8 +9,8 @@ toolbox.progress-ratio(ratio => { stack( dir: ltr, - rect(stroke: blue, fill: blue, width: ratio * 8cm), - rect(stroke: blue, fill: none, width: (1 - ratio) * 8cm), + rect(stroke: blue, fill: blue, width: 8cm * ratio), + rect(stroke: blue, fill: none, width: 8cm * (1 - ratio)), ) }) } diff --git a/examples/demo.typ b/examples/demo.typ index 4cc606e..b6b422f 100644 --- a/examples/demo.typ +++ b/examples/demo.typ @@ -1,4 +1,4 @@ -#import "../src/polylux.typ": * +#import "../src/polylux.typ": * #show link: set text(blue) #set text(font: "Andika", size: 20pt) @@ -26,7 +26,7 @@ // #box(image("../assets/polylux-logo.svg", height: 2em)) #h(1fr) Polylux demo | #toolbox.current-section - ] + ], ) #show heading: set block(below: 2em) @@ -122,7 +122,7 @@ #slide[ = Fine-grained control -  When `#show: later` does not suffice, you can use more advanced commands to + When `#show: later` does not suffice, you can use more advanced commands to show or hide content. These are some of your options: @@ -140,7 +140,7 @@ inset: .5em, fill: aqua.lighten(80%), radius: .5em, - text(size: .8em, body) + text(size: .8em, body), ) #slide[ @@ -183,9 +183,9 @@ #slide[ = Convenient rules as strings -As as short hand option, you can also specify rules as strings in a special -syntax. -Comma separated, you can use rules of the form + As as short hand option, you can also specify rules as strings in a special + syntax. + Comma separated, you can use rules of the form #table( columns: (auto, auto), column-gutter: 1em, @@ -200,7 +200,9 @@ Comma separated, you can use rules of the form ```typ #uncover("-2, 4-6, 8-")[Visible on subslides 1, 2, 4, 5, 6, and from 8 onwards] ``` - #uncover("-2, 4-6, 8-")[Visible on subslides 1, 2, 4, 5, 6, and from 8 onwards] + #uncover( + "-2, 4-6, 8-", + )[Visible on subslides 1, 2, 4, 5, 6, and from 8 onwards] ] ] @@ -214,10 +216,10 @@ Comma separated, you can use rules of the form Again, you can use complex string rules, if you want. #example[ - ```typ - #only("2-4, 6")[Visible on subslides 2, 3, 4, and 6] - ``` - #only("2-4, 6")[Visible on subslides 2, 3, 4, and 6] + ```typ + #only("2-4, 6")[Visible on subslides 2, 3, 4, and 6] + ``` + #only("2-4, 6")[Visible on subslides 2, 3, 4, and 6] ] ] @@ -225,13 +227,13 @@ Comma separated, you can use rules of the form = `#alternatives`: Substituting content You might be tempted to try #example[ - ```typ - #only(1)[Ann] #only(2)[Bob] #only(3)[Christopher] likes #only(1)[chocolate] #only(2)[strawberry] #only(3)[vanilla] ice cream. - ``` - #only(1)[Ann] #only(2)[Bob] #only(3)[Christopher] - likes - #only(1)[chocolate] #only(2)[strawberry] #only(3)[vanilla] - ice cream. + ```typ + #only(1)[Ann] #only(2)[Bob] #only(3)[Christopher] likes #only(1)[chocolate] #only(2)[strawberry] #only(3)[vanilla] ice cream. + ``` + #only(1)[Ann] #only(2)[Bob] #only(3)[Christopher] + likes + #only(1)[chocolate] #only(2)[strawberry] #only(3)[vanilla] + ice cream. ] But it is hard to see what piece of text actually changes because everything @@ -287,7 +289,7 @@ Comma separated, you can use rules of the form - first - second - third - ] + ], ) ] diff --git a/src/logic.typ b/src/logic.typ index 8a84fd4..8e2aea0 100644 --- a/src/logic.typ +++ b/src/logic.typ @@ -26,17 +26,17 @@ if match-until != none { let parsed = int(match-until.captures.first()) // assert(parsed > 0, "parsed idx is non-positive") - ( until: parsed ) + (until: parsed) } else if match-beginning != none { let parsed = int(match-beginning.captures.first()) // assert(parsed > 0, "parsed idx is non-positive") - ( beginning: parsed ) + (beginning: parsed) } else if match-range != none { let parsed-first = int(match-range.captures.first()) let parsed-last = int(match-range.captures.last()) // assert(parsed-first > 0, "parsed idx is non-positive") // assert(parsed-last > 0, "parsed idx is non-positive") - ( beginning: parsed-first, until: parsed-last ) + (beginning: parsed-first, until: parsed-last) } else if match-single != none { let parsed = int(match-single.captures.first()) // assert(parsed > 0, "parsed idx is non-positive") @@ -71,7 +71,9 @@ lower-okay and upper-okay } else { - panic("you may only provide a single integer, an array of integers, or a string") + panic( + "you may only provide a single integer, an array of integers, or a string", + ) } } @@ -93,12 +95,14 @@ } last } else { - panic("you may only provide a single integer, an array of integers, or a string") + panic( + "you may only provide a single integer, an array of integers, or a string", + ) } } #let _conditional-display(visible-subslides, reserve-space, mode, body) = { - context{ + context { let vs = if reserve-space and handout-mode.at(here()) { (:) } else { @@ -128,8 +132,14 @@ } #let item-by-item(start: 1, mode: hide, body) = { - let is-item(it) = type(it) == content and it.func() in ( - list.item, enum.item, terms.item + let is-item(it) = ( + type(it) == content + and it.func() + in ( + list.item, + enum.item, + terms.item, + ) ) let children = if type(body) == content and body.has("children") { body.children @@ -148,7 +158,7 @@ let subslides = subslides-contents.map(it => it.first()) let contents = subslides-contents.map(it => it.last()) - context{ + context { let sizes = contents.map(c => measure(c)) let max-width = calc.max(..sizes.map(sz => sz.width)) let max-height = calc.max(..sizes.map(sz => sz.height)) @@ -156,7 +166,7 @@ only(subslides, box( width: max-width, height: max-height, - align(position, content) + align(position, content), )) } } @@ -165,7 +175,7 @@ #let alternatives( start: 1, repeat-last: false, - ..args + ..args, ) = { let contents = args.pos() let kwargs = args.named() @@ -181,7 +191,7 @@ end: none, count: none, ..kwargs, - fn + fn, ) = { let end = if end == none { if count == none { @@ -222,7 +232,7 @@ panic("Illegal mode: " + str(c)) } }) - for (idx, (from , to)) in lines.windows(2).enumerate() { + for (idx, (from, to)) in lines.windows(2).enumerate() { show raw.line: it => { if it.number <= from { before-action(it) diff --git a/src/polylux.typ b/src/polylux.typ index 7f08320..6f39654 100644 --- a/src/polylux.typ +++ b/src/polylux.typ @@ -1,15 +1,6 @@ #import "logic.typ": ( - slide, - uncover, - only, - alternatives, - alternatives-match, - alternatives-fn, - alternatives-cases, - one-by-one, - item-by-item, - reveal-code, - later, - enable-handout-mode + alternatives, alternatives-cases, alternatives-fn, alternatives-match, + enable-handout-mode, item-by-item, later, one-by-one, only, reveal-code, + slide, uncover, ) #import "toolbox/toolbox.typ" diff --git a/src/toolbox/pdfpc.typ b/src/toolbox/pdfpc.typ index b032ec9..731ecd2 100644 --- a/src/toolbox/pdfpc.typ +++ b/src/toolbox/pdfpc.typ @@ -40,7 +40,10 @@ } else if type(time) == "string" { time } else { - panic(msg-name + " must be either a datetime or a string in the HH:MM format.") + panic( + msg-name + + " must be either a datetime or a string in the HH:MM format.", + ) } [ #metadata((t: tag-name, v: time)) ] @@ -79,14 +82,14 @@ let transition-str = ( default-transition.at("type", default: "replace") - + ":" + - str(default-transition.at("duration-seconds", default: 1)) - + ":" + - dir-to-angle(default-transition.at("angle", default: rtl)) - + ":" + - default-transition.at("alignment", default: "horizontal") - + ":" + - default-transition.at("direction", default: "outward") + + ":" + + str(default-transition.at("duration-seconds", default: 1)) + + ":" + + dir-to-angle(default-transition.at("angle", default: rtl)) + + ":" + + default-transition.at("alignment", default: "horizontal") + + ":" + + default-transition.at("direction", default: "outward") ) [ #metadata((t: "DefaultTransition", v: transition-str)) ] diff --git a/src/toolbox/toolbox-impl.typ b/src/toolbox/toolbox-impl.typ index d814ef2..dac3220 100644 --- a/src/toolbox/toolbox-impl.typ +++ b/src/toolbox/toolbox-impl.typ @@ -34,8 +34,7 @@ #let progress-ratio(ratio-to-content) = context { let ratio = ( - logic.logical-slide.get().first() / - logic.logical-slide.final().first() + logic.logical-slide.get().first() / logic.logical-slide.final().first() ) ratio-to-content(ratio) } @@ -61,7 +60,7 @@ #let side-by-side(columns: none, gutter: 1em, ..bodies) = { let bodies = bodies.pos() - let columns = if columns == none { (1fr,) * bodies.len() } else { columns } + let columns = if columns == none { (1fr,) * bodies.len() } else { columns } if columns.len() != bodies.len() { panic("number of columns must match number of content arguments") } diff --git a/src/toolbox/toolbox.typ b/src/toolbox/toolbox.typ index 86905b2..d57d794 100644 --- a/src/toolbox/toolbox.typ +++ b/src/toolbox/toolbox.typ @@ -1,13 +1,5 @@ #import "toolbox-impl.typ": ( - pdfpc, - register-section, - current-section, - all-sections, - progress-ratio, + all-sections, big, current-section, full-width-block, last-slide-number, + next-heading, pdfpc, progress-ratio, register-section, side-by-side, slide-number, - last-slide-number, - big, - side-by-side, - full-width-block, - next-heading, ) diff --git a/tests/alternatives.typ b/tests/alternatives.typ index 05a337d..0d5eaf5 100644 --- a/tests/alternatives.typ +++ b/tests/alternatives.typ @@ -25,7 +25,7 @@ "-2": [beginning], "3, 5": [main part], "4": [short break], - "6-" : [end] + "6-": [end], )) #uncover("1-8")[I am always here, for technical reasons.] @@ -35,10 +35,10 @@ == Another test that `alternatives-match` works #alternatives-match(position: center, ( - (2, [beginning]), + (2, [beginning]), ((3, 5), [main part]), (4, [short break]), - ("6-" , [end]) + ("6-", [end]), )) #uncover("1-8")[I am always here, for technical reasons.] @@ -57,7 +57,7 @@ // == Test that `alternatives-fn` works // #raw(lang: "typ", repr(range(1, 6))) - + // #alternatives-fn(start: 2, count: 5, subslide => numbering("(i)", subslide)) #only(2)[abc] diff --git a/tests/first-slide.typ b/tests/first-slide.typ index 15b6ef8..89e34b4 100644 --- a/tests/first-slide.typ +++ b/tests/first-slide.typ @@ -14,4 +14,4 @@ #slide[ == Second slide #lorem(10) -] \ No newline at end of file +] diff --git a/tests/later.typ b/tests/later.typ index 96a76c4..bc2b6fd 100644 --- a/tests/later.typ +++ b/tests/later.typ @@ -21,7 +21,7 @@ - `item3` #show: later - + + #underline[item1] + #strike[item2] + #overline[item3] @@ -60,11 +60,15 @@ == Visuals #show: later - + // Fails to be hidden as of Typst 0.7.0 #path( - fill: teal.lighten(50%), stroke: teal, closed: true, - (0cm, 0cm), (1cm, 0cm), (1cm, 1cm) + fill: teal.lighten(50%), + stroke: teal, + closed: true, + (0cm, 0cm), + (1cm, 0cm), + (1cm, 1cm), ) #rect() @@ -80,8 +84,11 @@ // Fails to be hidden as of Typst 0.7.0 #polygon( - fill: teal.lighten(50%), stroke: teal, - (0cm, 0cm), (1cm, 0cm), (1cm, 1cm) + fill: teal.lighten(50%), + stroke: teal, + (0cm, 0cm), + (1cm, 0cm), + (1cm, 1cm), ) #image("../assets/polylux-logo.svg", width: 3em)