Template inheritance

Hello,

I’m struggling to define templates for my different documents types, such that they inherit from the definition of a more general template.

In concrete term, what I want is to be able to have one general template document doc-template.typ such as:

#let template(
  doc_title: [],
  author: "",
  doc
) = [
  // Some template rules
  ...
]

One other template document my-doc-template, that inherits from the previous one, but fixing some of its arguments and adding new rules:

#let my_template(
  doc_title: [],
  doc
) = [
  // Definition of the template inheritance
  #show template.with(
    doc_title: doc_title,
    author: "DreamerPhi",
  )

  // Definition of the new template rules
  ...
]
 


And finally being able to use this second template in a document my-document.typ:

#import "my-doc-template.typ": my_template

#show my_template.with(
  doc_title: [My document title],
)

Thanks in advance!

Hi. As far as I know, it is difficult to arbitrarily adjust the behavior of the inner template. For example, if a fixed font size/color is set in the inner template.

// template.typ
#let template(
  doc_title: [],
  author: "",
  doc
) = [
  #set text(fill: blue)
  Title: *#doc_title* \
  Author: *#author* \
  #doc
]

// my-doc-template.typ
// import "template.typ": *
#let my_template(
  doc_title: [],
  doc
) = [
  // new rules (not working)
  #set text(fill: maroon)

  #show: template.with(
    doc_title: doc_title,
    author: "DreamerPhi"
  )

  #doc
]

// main.typ
// import "my-doc-template.typ": my_template
#show: my_template.with(
  doc_title: [My document title],
)

Content

You may have a look at community-cnam-thesis which is built on top of bookly.

Not necessarily a thread with concrete answers, but a lot of relevant discussion: