How to duplicate a function, but with different settables?

Hi. I want to create a variant of a standard function:

#let major-enum = enum

#set major-enum(
  spacing: 0.5cm,
)

However it didn’t work as intended, since major-enum would be considered the same object as enum, and #set statements would be applied to them at the same time.

#let major-enum(..args) = enum(..args)

won’t work either, since spacing would not be considered as a named argument of major-enum, thus not settable.

How can I achieve this effect?

Hi. Without a concrete use case, this is just How can I have global configuration parameters for a module/package? - #2 by Andrew, but from a different angle.

Generally speaking, you can’t. But with enough hacks you can manually exploit one element for storing relevant/updated field values with a set rule, like here:

Or use Introduction - The Elembic Handbook.

1 Like

Hi. Thanks for your answer! The use case is to create a different style of enum for a very long enum spanning multiple pages, containing a few homework exercises. I don['t want this style to interfere with usual enums.

Have you tried just adding #[ at the start and ] at the end of the section with a normal set rule? This is the most straightforward way, with no hacking. Or #custom-enum[].

No, that’s not possible, because I want normal enums inside it.

Thanks @bluss in Discord for the answer!

1 Like

You will use normal enums inside of it…

Do you mean the section where I want normal enums, or the section containing the mega enum?

Do you mean the section where I want normal enums, or the section containing the mega enum?

Both. That’s the whole point of scoping the set rules.

That seems cumbersome, since I will have many items inside the mega enum. Thanks for @bluss,

#let major-enum = enum.with(spacing: 0.5cm)

worked perfectly.

1 Like

You are literally providing a custom-enum, but you are calling it major-enum here.

Yeah, that’s my problem: I wanted to provide a custom-enum, but I didn’t know the function.with(...) syntax, and there isn’t a dedicated documentation page for with.

EDIT: I looked for set in the documentations, but didn’t find it.

function.with

Making a Template – Typst Documentation.

If this is not enough, you can request more documentation about this.

Where can I request for new documentation? Can I request for it here?

  • There is a ref of set in function.with, but not its reverse.
  • Instead of styling, I think they could be best categorized as scripting.

To track it, it needs to be in the issue tracker.