Is it possible to redefine a function within a package? I want to use the package, but this one function does not fit my needs.
You can rename a specific function of a package in the import.
#import "foo.typ": bar as baz
#baz()
In this case, I am not directly calling the function. The package is calling the function internally.
In that case, AFAIK there isn’t a way to redefine it, unless you can modify the source code.
What package are you using?
Hi, welcome and thank you for your question! I have changed your post’s title from to “Can I redefine a function in a package?” as the question guidelines recommend this:
Good titles are questions you would ask your friend about Typst.
I also added tags to make your question easier to find.
regarding your question, unfortunately there is really no mechanism for this. The package you use would have to explicitly support “replacing” that function (it would need to be passed as a parameter to the function(s) that should use it).
I am using moderner-cv
but I want the header to include more contact info. In the end, I chose to have a local module that inherits most of the original package but uses a custom header function.
Looks like it uses the _header()
function for header.
#let moderner-cv(
name: [],
subtitle: [CV],
social: (:),
color: moderncv-blue,
lang: "en",
font: ("New Computer Modern"),
show-footer: true,
body,
) = [
Since it doesn’t have anything resembling a substitution feature @SillyFreak was talking about, your best course of action is to have a modified local copy of the original template. Or if it’s possible, you indeed can only override a few things (functions) in your own module, which results in smaller code size for your document and ability to depend on external source via import "@preview/*"
(and update it if new version comes out).
It’s also possible to ask author of this template to add an ability for adding more info in header