Hello everyone,
For a personal project i have automated imports of pages into main.typ using a json file with the following structure :
{
"reglement": [],
"officiel": [
"Braban\u00e7onne",
"WoltjeKreet",
"Gaudeamus",
"IoVivat",
"marche_etudiants",
"LiedVanGeenTaal",
"WoltjeClubLied"
],
"leekes": [],
"groupe_folklorique": [],
"andere": [],
"index": [],
"others": [
"fulltext",
"repetition"
]
}
Basically, the keys in the following json file represent section of the the future text and the array represent variables to include.
I retrieve the content of the json in a dict and i iterate over each “section” and “variable”. After that i use eval()
to call and use my variables :
// in main.typ
#import "imports.typ" : * // for importing variables
// normal call of my variable previously defined
#sacre_page
#WoltjeClubLied
#CridesPres
#Gaudeamus
#Brabançonne // Variable brabançonne here
#marche_etudiants
#IoVivat
#LiedVanGeenTaal
// using json, dictionnary and eval
#for key in dict.keys() {
for songname in dict.at(key){
"#" + str(songname) + linebreak() // used to debug -> correct names
eval("#" + str(songname), mode : "markup") // unknown variable Brabançonne
}
}
I suppose it could be due to the scope of the evaluated code that is not the same as the code located on top. Unfortunately i don’t really know how to correctly define it.
Another supposition is to evaluate the code including the #import "imports.typ" : *
For more insight you can check the project here : Typst and main.typ
should be the most useful file to check.
( It is quite big and partially automated via python script so not everything make sense. )
Thank you in advance for your help