Namespace conflict between packages

Hi all

I’m using the Touying package to develop course slides. I also like the tblr package a lot for helping me typesetting nice tables. However, both packages define a cols function. The former as an alternative to grid, the latter as a means to apply a function to all cells in a column of a table.

What is the best way to avoid these namespace clashes? Should I #import "@preview/tblr:0.5.0" as tblr and use everywhere the prefix tblr. when I want to call a function belonging to the tblr package? This gets cumbersome rather quickly…

Is there a way to tell Typst that in a certain context/code block/… I specifically want to use the namespace of tblr?

I would either go with selective imports
#import "@preview/tblr:0.5.0": cols as tcols, <other selective imports>

or with an alias. MWE:

#import "@preview/tblr:0.5.0": *
#let tcols = cols          // grab tblr's cols while it's still in scope

#import "@preview/touying:0.7.4": *
#import themes.university: *

#show: university-theme.with(
    aspect-ratio: "16-9",
    config-info(
      title: [Test Slides],
      author: [author],
      date: datetime.today(),
    ),
  )


== Slide 1

#cols[a][b]

== Slide 2

#context tblr(header-rows: 1, columns: 4,
  // formatting directives
  tcols(within: "body", 0, fill: gray.lighten(70%), hooks: strong),
  // content
  [Pakistan],      [165],  [803],   [206.2],
  [Bangladesh],    [147],  [144],   [1023.4],
  [Russia],        [142],  [17075], [8.4],  
)
1 Like

I abbreviate package names most of the time to just two letter labels:

  • lilaq is shortened to lq (as per the author’s use in the examples)
  • tiptoe to tt
  • fletcher to fl
  • pavemat to pm

etc.

This makes it much easier to write while avoiding conflicts and keeps the document clean enough for yourself-in-two-weeks to still understand what’s going on.