How to change default outline title for a specific language?

Having recently fallen in love with Typst, I wish to dive deap and learn as much as I can : )

The other day I got my first package submitted to Typst Universe, latex-lookalike.

Today I started to play around with internationalization support, and realized that one line in latex-lookalike which changes the default title of the outline from “Contents” to “Table of contets”, unfortunately also makes this change for all other languages, not just English.

set outline(title: [Table of contents])

If tried messing around with different options to resolve this issue, but so far I haven’t found a solution.

set outline(title: context {
  if text.lang == "en" [ Table of contents ]
  else {
    // how can I get the `auto` output for other languages here?
  }
})

Any suggestions are much appreciated.

Joyous regards,
Robin

1 Like

Hi there, have you looked at linguify – Typst Universe? I haven’t tried it but maybe it will put you on the right path?

Hello. Since show is not literal if, this won’t work:

#show text.where(lang: "en"): set outline(title: "this")

But literal if still won’t work, since you can’t mix context with set rules directly.

#context set outline(title: "Table of contents") if text.lang == "en"

This will work

#show: it => context {
  set outline(title: "Table of contents") if text.lang == "en"
  it
}

but only if the language is set before the context, so it’s not great. So the only other way would be to use show rules, since you can’t ask Typst to use auto if you override it with something.

#show outline: it => {
  show heading: it => {
    show "Contents": "Table of contents"
    it
  }
  it
}

#outline()

= Heading

#set text(lang: "ru")

#outline()

= Heading

The heading show rule only works for outline’s heading, it looks like.

1 Like

Thanks, I had a look at linguify and will probably use it for some of my documents.

But I don’t want to introduce dependencies in the latex-lookalike package, since I don’t know what internationalisation primitives the end users of the package will be using.

Wonderful, thanks for the detailed reply Andrew! I will have to give it some time to consider the different options. A text-substitute show rules works, but feels a little bit like a hack ^^

I wish we had something like it.default() (Resetting `show` and `set` to its default / Revoke rules · Issue #420 · typst/typst · GitHub) that could be used for the auto value of title.

Cheerful regards,
Robin