sahasatvik / typst-theorems

An implementation of numbered theorem environments in typst
MIT License
209 stars 12 forks source link

Missing qed symbol in nested proofs #25

Open fagu opened 6 months ago

fagu commented 6 months ago

If you nest multiple proofs, only the innermost ones get a qed symbol.

#set page(width: 11cm, height: auto, margin: 1em)
#set par(justify: true)

#import "@preview/ctheorems:1.1.2": *
#show: thmrules
#let theorem = thmplain("theorem", "Theorem")
#let claim = thmplain("claim", "Claim", base: "theorem")
#let proof = thmproof("proof", "Proof")

#theorem[
  #lorem(10)
]
#proof[
  #lorem(10)
  #claim[
    #lorem(10)
  ]
  #proof[
    #lorem(20)
  ]
  #claim[
    #lorem(10)
  ]
  #proof[
    #lorem(20)
  ]
  #lorem(20)
]

nested-qed

A solution could be to make the thm-qed-done state a stack of booleans: At the start of a proof, push false. When showing the qed symbol, set the last entry to true. At the end of a proof, remove the last entry and show the qed symbol if the removed entry was false.

(That also seems to be what latex does.)

sahasatvik commented 6 months ago

Thanks for pointing this out, and for the fix; I'll implement this in v2.0.0.

I'm pretty sure that there's some wonky behavior when nesting theorems (mainly with numbering and referencing), fair warning.