#Named arguments, positional arguments and content, who is who?

1 messages · Page 1 of 1 (latest)

old bison
#

How to specify a function that takes a mandatory destargument and an optional labelargument that could be some extra content, much like the link()function ?

hasty delta
#

like this, or did you have something else in mind? #let my-fun(dest, label: none) = {...}

old bison
#

I have it like this but it complains whenever I do something like #path("path/to/myfile.txt")[myfile]

#

Throws unexpected argument at [myfile]

hasty delta
#

?render ```rs
#let my-fun(dest, ..label) = {
dest
label.pos().at(0)
}
#my-fun("hi")[bye]

old bison
#

I would prefer using just an optional argument, as I test it beforehand to see if its defined

#

This is my function :

#let path(dest, label: none) = {
    if type(label) == "none" {
        label = dest
    }
    dest = "file:///" + dest.replace("\\", "/")
    box(
        fill: rgb("#eee"), 
        radius: 1pt, 
        inset: (left: 1pt, right: 3pt), 
        outset: (x: 0pt, y: 3pt), 
        emph(link(dest)[#label])
    )
}```