#Custom reference format for figure kind

19 messages · Page 1 of 1 (latest)

limpid mason
#

How can I change how a reference is displayed as a function of a custom figure kind? For example, I want to do this, but have all references to mykind be underlined

#

?r ```#figure(kind: "mykind", supplement: "My Kind")[
#box(stroke: 1pt + red, inset: 10pt)[#lorem(20)]
] <k1>

See @k1.```

limpid mason
wispy wharf
#

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
  }
}
limpid mason
#

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?

wispy wharf
#

it is a ref since it's a ref show rule, and the element field for ref is described in the page I linked

limpid mason
#

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.

wispy wharf
#

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

#

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

#

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
limpid mason
#

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?

wispy wharf