How to use the name of an object in the definition of a function in Mantys?

Hi all, I am writing the documentation of a new template that I want to submit soon in Typst Universe using Mantys. When writing the documentation, I am facing a problem that I can’t solve after reading the documentation of Mantys.

To help you to understand my problem, here is a short code snippet:

#command("mytemplate", ..args(
  paper-type: [Article],
  journal: journal-name,
  [body])
)[]

Here, journal-name is a dictionary. This definition displays the content of the dictionary in the arguments of the function, which is not desired.

My question is: How to only display the name of the variable (here the dictionary) ?

Thank you

I couldn’t find anything in the Docs like a nameof() type function but here is a hack:

#let x = none
#let name-of-x = (x: none).keys().first()

The variable x is defined, then used as the key in a dictionary. The dictionary itself isn’t important so it isn’t saved into a new variable, instead the first key of the dictionary is saved in name-of-x.
The result of the above code is “x”.

In your case it would be used like this:

#command("mytemplate", ..args(
  paper-type: [Article],
  journal: (journal-name: none).keys().first(),
  [body])
)[]

Thank you for the reply. However, as you mentioned, the results is "x", while I am looking for x. I don’t know whether a cleaner solution exists.

What type should the name of the variable be if not str?

Or maybe I’m misunderstanding your request:
You would like to pass the name of journal-name as the journal parameter, is that correct? That is to say, the actual value stored in journal-name is not used here.

Actually, displaying the result as "x" can lead to infer that the type of journal is a str instead of a dict. Of course, this can be specified later when defining the #argument and by giving some use case.

Ideally, I would like that the dictionary won’t be interpret. I am not sure to be clear enough.

The variable is not used as the key in the dictionary. The name is. To use the variable('s value) as a key, you need ((x): none).

1 Like

I now understand that is a question specifically about how to work with mantys and has nothing to do with general Typst scripting/syntax.

I’m sorry to say that I don’t have any experience with mantys so I can’t offer any advice other than:

  1. Look into the source code for the command() and args() functions and see if there is some way to get them to do what you want
  2. If it’s not possible, request it from the maintainer of the package
  3. Worst case fork the project and write the feature that you want.

@gezepi Thank you for trying to help me. I have already looked at the source code, but not found a workaround. May be, should I ping jneug

1 Like

Hi. From looking at arg and Typst, you can only add concrete default value. I assume you can set parameter types with argument.types. But to pass a dictionary name and display it as identifier, I think needs a new feature.