How to modify variables in other files?

// conf.typ
#let font_size = 14pt
// or?
// #let DEFAULT = (font_size: 12pt, first_line_indent: 2em)

#let conf(doc) = {
  set text(font_size)
  doc
}

#let big(body) = {
  set text(font_size * 2)
  body
}

I want to modify the font_size and other variables in the main.typ.

// main.typ
#import "conf.typ": *
#show: conf

#lorem(20)

#big(lorem(20))

I want to find a simple solution.
Please!!

Hi, welcome to the forum!

  1. If you just want the big function, then you can replace set text(font_size * 2) with set text(2em).

    1em means the current font size. See Length - Typst Documentation.

    You may also simplify big with function.with(…):

    #let big = text.with(2em)
    
  2. If you want something more genenral, then a common pattern is as follows.

// conf.typ
#let conf(font-size: 12pt) = {
  let template(body) = {
    set text(font-size)
    body
  }

  let big(body) = {
    set text(font-size * 2)
    body
  }

  // This creates a dictionary with `big` and `template` as keys and the above functions as values.
  (big: big, template: template)
}
// main.typ
#import "conf.typ": conf

#let (template, big) = conf(font-size: 14pt)
#show: template

#lorem(20)

#big(lorem(20))
2 Likes

Thank you, the more general one is what I want. :grinning:

But if I have more functions, how should I simplify the code?

// main.typ
#import "conf.typ": conf

#let (template, big, fun1, fun2, fun3 /*...*/) = conf(font-size: 16pt)
#show: template

// ...

And how should I modify the variables of the template function? :sob:

// conf.typ
#let conf(font_size: 14pt) = {
  // I want to modify the `fli` variables in the main.typ.
  let template(body, fli: 2em) = {
    set text(font_size)
    set par(first-line-indent: fli)
    body
  }

  let big(body) = {
    text(font_size * 2, body)
  }

  (template: template, big: big)
}

Please!!

Try this:

#show: template.with(fli: 5em)

I have no idea… Perhaps it’s better to let the end author use show/set rules directly? This should reduce the number of functions.

Thank you very much for your help.