I want to set page margins that scale with the paper size, something like a percentage of the page dimensions, but clamped to a minimum and maximum in terms of line-height multiples.
I’m a Typst newbie. This isn’t the prettiest code, but it seems to work. There might be subtle side-effects that I am missing.
An auxiliary function, make-page-dict, creates a dictionary array using the page setup values. It passes through extra page arguments. Since the calculations occur inside the auxiliary function, it has access to the values being provided.
Note the .pt() code that grabs the numeric value of the lengths (in terms of points) so calc.clamp will work on numbers. Then multiplying by * 1pt converts the calc.clamp output back to lengths.
Note the . . (double periods) prefixing things to handle extra arguments and converting the dictionary array to arguments.