#Custom reference format for figure kind
19 messages · Page 1 of 1 (latest)
?r ```#figure(kind: "mykind", supplement: "My Kind")[
#box(stroke: 1pt + red, inset: 10pt)[#lorem(20)]
] <k1>
See @k1.```
I came a cross #1088830044153065512 message, but its unclear how to filter w/ it.func() for the Figure kind
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
In your case you can do something like this:
show ref: it => {
let el = it.element
if el != none and el.func() == figure and el.kind == "mykind" {
return underline(it)
} else {
return it
}
}
Thank you. I knew I could do something like that but I didn't know how to access kind. Where would I docs for whatever type it and el are?
it is a ref since it's a ref show rule, and the element field for ref is described in the page I linked
hmmm... maybe I'm overlooking something, but is there an API anywhere that lists what the fields are? I see nothing that would have told me that element.kind even exists or what type element is. Furthermore, even the existance of ref.element is only mentioned in prose and the example.
yeah it seems that constructor parameters are systematically documented but other fields are only mentioned in the prose or not at all, so for ref you do need to read the prose
also true that the doc doesn't say what type element is, though maybe you can infer that it's a piece of content, which is documented here: https://typst.app/docs/reference/foundations/content/
content has a func method you can call to check what type of content it is, which I do in the example above to check if element is a figure
if yes, then I know that this element has a kind field because it's documented here: https://typst.app/docs/reference/model/figure/
finally, when you have a piece of content it can help to use repr during development to get a sense of what's inside, although that can reveal internals I think so if you see something that's not documented, use it at your own risk: https://typst.app/docs/reference/foundations/repr/
?r
#show ref: it => repr(it) // or just #show ref: repr
#figure[Some figure] <k1>
@k1
Thank you that is very helpful. Especially repr. I see what you mean about the figure docs showing kind, but that is really documenting the constructor, not really the type itself. Is it safe to assume that a subset of the fields always includes the parameters verbatim?
yes, have a look at the "representation" section in the content doc: https://typst.app/docs/reference/foundations/content/#representation
if the parameter was set explicitly then you can always access it. if it's set by a set rule you'll need a context, see https://typst.app/docs/reference/context/#style-context