How to have different supplements for the same heading depending on the location?

In my PhD thesis, I have to do a small introduction in French, but the rest of the document is in English. In this introduction, I must have French supplements for the headings I’m referring to, however the following solution does not work. It seems that the supplement that is chosen when we do a reference is the one applied at the location of the heading. Is there a simple solution to fix this?

#set heading(numbering: "1.", supplement: [Chapitre])

= C'est une introduction en français
// It's displaying "Chapter 2", but I want "Chapitre 2"
Dans cette thèse on va voir @chap.

#set heading(supplement: [Chapter])

= This is a chapter in English <chap>
This is @chap.

Not sure how to properly fix it with the set-rules but in the meantime, you can manually change the supplement where needed with @chap[Chapitre].

Yes that’s what I do currently, I’m just asking in case there is a more general solution. I also understand that this is the correct behaviour for referencing headings, as when we redefine the supplement to “Appendix” at the start of the appendix, we want the references to appendices in the body of the document to display “Appendix”, not “Chapter”.

You can use contextual content as the supplement

#set heading(numbering: "1.", supplement: context {
  if text.lang == "fr" [ Chapitre ] else [ Chapter ]
})

and then wrap any French chapters in a to text(lang: "fr")[ ... ]. If French is the default language of your document, and only some parts are in English, you can of course do the same with "en" instead of "fr".

3 Likes

If you do no want to wrap the whole chapter, you can also set the lang at the beginning, and set it back to another language at the end.

#set text(lang: "fr")