platformer / typst-algorithms

MIT License
141 stars 4 forks source link

`#algo` causes error when used with touying slides #23

Open NonDairyNeutrino opened 2 weeks ago

NonDairyNeutrino commented 2 weeks ago

When creating a slide show with touying and using #algo on a slide,

typst compile main.typ

results in the error

error: panicked with: "You should not use set/show rule here, please put it before `#show: slides` or inside `#slide[]`, or use `#slides-end` to terminate `#show: slides` first. Use `#(s.enable-styled-warning = false)` if you think it's a false warning."
    ┌─ @preview/touying:0.4.2/slide.typ:704:6
    │
704 │       panic("You should not use set/show rule here, please put it before `#show: slides` or inside `#slide[]`, or use `#slides-end` to terminate `#show: slides` first. Use `#(s.enable-styled-warning = false)` if you think it's a false warning.")
    │       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This can be recreated with the basic Fibonacci example

#algo(
  title: "Fib",
  parameters: ("n",)
)[
  if $n < 0$:#i\        // use #i to indent the following lines
    return null#d\      // use #d to dedent the following lines
  if $n = 0$ or $n = 1$:#i #comment[you can also]\
    return $n$#d #comment[add comments!]\
  return #smallcaps("Fib")$(n-1) +$ #smallcaps("Fib")$(n-2)$
]

My preamble:

#import "@preview/touying:0.4.2": *
#import "@preview/unify:0.6.0": num
//#import "../themes/aus-beamer.typ" as theme-aus
#import "@preview/academic-conf-pre:0.1.0" as theme-aus
#import "@preview/cades:0.3.0": qr-code
#import "@preview/algo:0.3.3": algo, i, d, comment, code

#let s = theme-aus.register(aspect-ratio: "16-9") //4-3, 16-9
#let s = (s.methods.info)(
  self: s,
  // title, authors, etc.
)

#let (init, slides, touying-outline, alert, speaker-note, tblock) = utils.methods(s)
#let (slide, empty-slide, title-slide, outline-slide, new-section-slide, ending-slide) = utils.slides(s)

// #show link: underline
#show: init
#show: slides.with()

NOTE: the error does not occur with #code and everything compiles just fine.

platformer commented 2 weeks ago

Could you provide an MWE with this bug? (Or if necessary, and if you're comfortable with it, you can email me your main.typ.) I copied your preamble, made a few slides with the Fib example, and even mixed in some #pause commands, but couldn't produce a panic. I'm also testing it on the Typst web app, so I'm not sure if that makes a difference.

NonDairyNeutrino commented 2 weeks ago

Using the example from the slide template

#import "@preview/touying:0.4.2": *
#import "@preview/unify:0.6.0": num //标号
//#import "../themes/aus-beamer.typ" as theme-aus
#import "@preview/academic-conf-pre:0.1.0" as theme-aus
#import "@preview/algo:0.3.3": algo, i, d, comment, code

// 首先注册PPT的基本信息
#let s = theme-aus.register(aspect-ratio: "4-3") //4-3, 16-9
#let s = (s.methods.info)(
  self: s,
  title: [This is a template for academic research presentation in Typst],
  short-title: [My essay short title],
  subtitle: [This is the subtitle],
  author: [Jun Liu],
  date: datetime.today(),
  institution: [My Institution \
    University of Blablabla],
)

// 这些是一些常用的方法
// tblock是小方框
#let (init, slides, touying-outline, alert, speaker-note, tblock) = utils.methods(s)
#let (slide, empty-slide, title-slide, outline-slide, new-section-slide, ending-slide) = utils.slides(s)

// 封面
#show: init
#show: slides.with(title-slide: false)

= section
== Slide title
This is content
#algo(
  title: "Fib",
  parameters: ("n",)
)[
  if $n < 0$:#i\        // use #i to indent the following lines
    return null#d\      // use #d to dedent the following lines
  if $n = 0$ or $n = 1$:#i #comment[you can also]\
    return $n$#d #comment[add comments!]\
  return #smallcaps("Fib")$(n-1) +$ #smallcaps("Fib")$(n-2)$
]

produces a panic using a local cli, but if the #algo... is commented out, it compiles just fine.