Setting a dymanic reference

Hi there!

I am trying to overload the image markdown, so that I can use it with the same styling etc in the whole document.

Here is my code:

#let image(img, 
           width: 70%, height: auto, fit: auto,
           caption: "", reflink: "") = {
  align(horizon, [
    #figure( 
      std.image(img, 
            width: width, height: height),
            caption: caption) [<#reflink>]]
  )
}


#image("../" + ImageTransfercurve,
        caption: "This is the description", reflink: "Transfercurve")

It basically works, except for the image reference. “Transfercurve” is just printed below the image and the caption.
I also tried around with different bracket formattings, but I cannot get it to work in a simple way.
What am I doing wrong?

How to create dynamic reference and label? Does not seem to be same problem, is it?

Maybe, I already found the solution by myself:

#let image(img, 
           width: 70%, height: auto, fit: auto,
           caption: "", reflink: "") = {
  align(horizon, [
    #figure( 
      std.image(img, 
            width: width, height: height),
            caption: caption) #reflink]
  )
}


#image("../" + ImageTransfercurveLIN,
        width: 90%,
        caption: "This is the description", reflink: <Transfercurve>)


In @Transfercurve, something is shown.

This seems to be working without problems.

Thanks for the support anyway, this forum is a great source of information!

To make the code from the question work, you have to use #label(reflink).

#let image(img, 
           width: 70%, height: auto, fit: auto,
           caption: "", reflink: "") = {
  align(horizon, [
    #figure( 
      std.image(img, 
            width: width, height: height),
            caption: caption) #label(reflink)]
  )
}
1 Like

This works as well, but the relevant thing is that I have to pass the Link name with angle brackets <>.

So, in the text, if I use #image, I have to pass reflink: <Transfercurve> to the #figure element instead of reflink: "Transfercurve"

I posted the snipped to show that passing the link name as a string (reflink: "Transfercurve") is also possible.

You are right and I will also use it like this. This solution is more straightforward to the user than using angle brackets.

Thanks!

1 Like