“cannot reference sequence” error
Hi everyone,
I’m developing a theorem-like environments package for Typst called theoframe. It provides styled blocks for Definition, Theorem, Lemma, Proof, etc., with automatic numbering, cross-referencing support, and customizable colors.
However, I’ve been stuck on a “cannot reference sequence” error for a long time and can’t figure out the root cause. The error occurs in my lib.typ file when I try to use @ref to reference labeled theorem-like blocks.
Here’s a minimal example of what I’m trying to achieve:
@vmartel08
Hello, my friend. I have carefully read the linked post on typst forum and the context section on typst Documentation, and obtained a deep understanding abot this function/method. But still can’t solve the problem.
Method one:
assign a code block to theoframe(), no compilation error, but render result is not expected.
// theoframe package, version:0.2.0, filename: lib.typ
#let definition-counter = counter("definition")
#let translation = (
definition: (en: "Definition", fr: "Définition", ko: "정의", ja: "定義", zh: "定义"),
)
#let heading-counter-content = context numbering("1.", counter(heading).get().first())
#let theoframe(name: [], framename: [], kind: "", theoframe-counter, color: none, it) = {
theoframe-counter.step()
figure(
block(
width: 100%,
stroke: (left: 2pt + color),
inset: 0em,
)[
// #theoframe-counter.step(level: 1)
#let counter-content = [#heading-counter-content #context theoframe-counter.display("a")]
#block(width: 100%, inset: 1em, outset: 0em, below: 0em, fill: color.lighten(80%).transparentize(70%))[
#align(left)[#text(fill: color, weight: 700)[#framename #counter-content #h(1em) ] #text(weight: 500)[#name]]
]
#block(width: 100%, inset: 1em, outset: 0em, above: 0em, fill: color.lighten(80%).transparentize(90%))[
#align(left)[#it]
]
],
kind: kind,
supplement: kind,
numbering: it => {
heading-counter-content
context theoframe-counter.display("a")
},
outlined: true,
)
}
#let definition(name: [], color: rgb("#794e04"), it) = theoframe(
name: [#name],
framename: [#context translation.definition.at(text.lang, default: "Definition")],
kind: "Definition",
definition-counter,
color: color,
it,
)
#let reset-theorems-counter() = {
definition-counter.update(0)
}
#let reset(doc) = {
show heading.where(level: 1): it => {
it
reset-theorems-counter()
}
show ref: set text(fill: blue)
doc
}
// use in another file
#import "./test11.typ":*
// #import "@preview/theoframe:0.2.0"
#show: reset
= #lorem(1)
= #lorem(1)
#definition[
some texts
] <def1>
#definition[
more texts and @def1
] <def2>
Problems:
[{
“resource”: “/c:/Users/hexio/Documents/typst-packages/packages/packages/preview/theoframe/0.3.0/local/test12.typ”,
“owner”: “generated_diagnostic_collection_name#0”,
“severity”: 8,
“message”: “cannot reference sequence”,
“source”: “typst”,
“startLineNumber”: 14,
“startColumn”: 16,
“endLineNumber”: 14,
“endColumn”: 21,
“modelVersionId”: 38,
“origin”: “extHost1”
}]
Method Two: add a return before the figure in the code block.
Yellow wavy underline indicates:
this return unconditionally discards the content before it Hint: try omitting the return to automatically join all values Hint: state/counter updates are content that must end up in the document to have an effect
outputs:
Please provide some advices.
Has anyone encountered a similar “cannot reference sequence” error when working with custom figures and references? Any help or pointers would be greatly appreciated!
