How can I create a specific heading styles for appendix in template?

Hello,

I try to format my document as consistently as possible. So I use a template file defining most of my layout.
I would like to use on single template for the main file even if all functions are not used.
For example I would like to create in my template an “appendix” style used to style the appendix titles differently than the main titles if some appendix titles are used.

i tried to create a specific styling in my template without success. The only thing I have been able to do is to create a different numbering using:

#let appendix(body) = {
  set heading(numbering: "A.1 :", supplement: [Annexe])
  counter(heading).update(0)
  body
}

 #show: appendix

But directly in my main file whcih is not what I want to do.

I also tried t do something like that in my template

// Appendix Pages
let appendix(title) = {
  align(center)[    *#title*  ]
  line(length: 100%, stroke: 1pt)
  v(1em)
} 

With no success either.

I refered to the doc but I guess I am misunderstooding something.

Thanks

You can use a show rule inside your appendix template to change the heading style. The code snippet below will center the heading title and add a line + the vertical space below the title.

You can move the two functions to your template file, only the actual show rule to “activate” the appendix needs to be in your main file.

#let appendix-heading(it) = {
  set align(center)
  it
  line(length: 100%, stroke: 1pt)
  v(1em)
}

#let appendix(body) = {
  set heading(numbering: "A.1 :", supplement: [Annexe])
  show heading: appendix-heading
  counter(heading).update(0)
  body
}

Thanks for your answer : I tried to add in my template.py


// Appendix Pages
let appendix-heading(it) = {
  set align(center)
  it
  line(length: 100%, stroke: 1pt)
  v(1em)
}

And in my main report file :


#show appendix-heading("test-appendix")

But I have an error “expected column” just after the show

When I type #show eit suggests éppendix-heading" so I guess the template file is parsed corrctly but my calls must be wrong

The function appendix-heading() is the custom function to put inside your show rule for headings. You are not supposed to pass a string to the function to create a new heading. Just create your heading with the regular Typst syntax and the compiler will apply the show rule for you.

Instead of

#show appendix-heading("test-appendix")

try to write

#show heading: appendix-heading
= Test appendix

and the show rule will be applied to the heading "Test appendix".

Thanks this syntax works if the #let function and the #show are in the same document.

If I keep the #let in my template
And put only the #show in the main document I have an error :

error: unknown variable: appendix-heading

That sounds like you are just not importing the function appendix-heading() from your template.typ file?

I created a minimal working example here. The file template.typ also has the appendix() function. You can use that in place of the lines 13 to 15 in main.typ after importing it from template.typ. In that case you do not need to import appendix-heading() anymore since this is already “included” in the function appendix().

Thanks, It works great.

I was inserting your template functions inside my project function.
So without the # before the let.

It did not work that way, if I put it outsie the project with the # it worked.

I guess there is still something not clear to me as I do not understand how the function

#let appendix(body) = {

Is imported. I still do some more tests but you cleraly helped to solve the issue.