How to have a long+short figure caption work in a multi-file project and display in the outline?

Disclaimer:
This might be done wrong to begin with

Goal:

  1. I’d like to move all code related to captions/outline into a config.typ file rather than have it in main.

Issue:
see “code in question” in main.typ and supplemental_page.typ below.

I’m unable to migrate “code in question” into my config file, and the only way I can get it to work across other pages is to include the 2 lines found in supplemental_page.typ

Note: flexCaption and the outline, under this setup, are intermixed, so I haven’t been able to separate one from the other.

Current working version:

main.typ

#import "config.typ": *
#import "supplemental_page.typ": supplemental_page

#show: applyConfig

#set document(title: [Notes])

#makeTitleAndHeader(context document.title)

// code in question // -----------------------------
#let in-outline = state("in-outline", false)

#show outline: it => {
  in-outline.update(true)
  it
  in-outline.update(false)
}

#let flex-caption(long, short) = context if in-outline.get() { short } else { long }

#show outline.entry.where(
  level:1,
): set block(above: 1.2em)
#show outline.entry.where(
  level:2
): set block(above: 1.1em)
#show outline.entry.where(
  level:3
): set block(above: 1.1em)

#outline(
  title: "Contents")
#outline(
  title: "List of Tables",
  target: figure.where(kind: table))
#outline(
  title: "List of Figures",
  target: figure.where(kind: image))
// ------------------------------------------------------------

// example use 
= Heading 1
#supplemental_page

config.typ

#let applyConfig(
  title: [Untitled Notes],
  paper: "a4",
  margin: (x: 1.8cm, y: 1.5cm),
  text-font: "New Computer Modern Math",
  text-size: 10pt,
  body,
  ) = {

    set page(
      paper:paper,
      margin: margin,
      numbering: "1",
      header: align(right + horizon, context document.title))
    set text(
      font: text-font,
      size: text-size)
    set par(
      justify: true,
      leading: 0.52em,
      first-line-indent: 1.5em)

    set list(indent:1.1em, body-indent: 4pt)

    show heading: set align(center)
    show heading: set text(size: 17pt, weight: "bold")

    show figure: set block(above: 1.2em, below: 1.2em)

    body
  }


#let makeTitleAndHeader(body) = [
  #v(29em)
  #align(center)[
    #text(size: 25pt, weight: "bold")[#body]
    ]
  #pagebreak()
  ]

supplemental_page.typ

// Code in question ------------------------------------
#let in-outline = state("in-outline", false)
#let flexCaption(long, short) = context if in-outline.get() { short } else { long }
// ---------------------------------------------------------

// example use
#let supplemental_page = [
    #figure(
        table(
            columns: 2, 
              [ a], [ b ]
        ),
        caption: flexCaption([long caption...], [short caption]),
        kind: table,   
    )
]

Current/Desired output

Hi @Drix, I kept the “Code in question” comments so that you can easily see where I moved the code parts.
Two notes, the naming convention for Typst is Kebab case, IMO it is much more readable. I modified your makeTitleAndHeader function to use code mode as you primarily call functions. It looks a bit better and sometimes if you use markup mode unexpected spaces or line breaks sneak in if you aren’t careful.
main.typ

#import "config.typ": *
#import "supplemental_page.typ": supplemental_page

#show: applyConfig

#set document(title: [Notes])

#makeTitleAndHeader(context document.title)

#make-outlines

// example use 
= Heading 1
#supplemental_page

config.typ

// Code in question ------------------------------------
#let in-outline = state("in-outline", false)
#let flexCaption(long, short) = context if in-outline.get() { short } else { long }
// ---------------------------------------------------------

#let applyConfig(
  title: [Untitled Notes],
  paper: "a4",
  margin: (x: 1.8cm, y: 1.5cm),
  text-font: "New Computer Modern Math",
  text-size: 10pt,
  body,
  ) = {

    set page(
      paper:paper,
      margin: margin,
      numbering: "1",
      header: align(right + horizon, context document.title))
    set text(
      font: text-font,
      size: text-size)
    set par(
      justify: true,
      leading: 0.52em,
      first-line-indent: 1.5em)

    set list(indent:1.1em, body-indent: 4pt)

    show heading: set align(center)
    show heading: set text(size: 17pt, weight: "bold")

    show figure: set block(above: 1.2em, below: 1.2em)

    // code in question // -----------------------------
    show outline: it => {
      in-outline.update(true)
      it
      in-outline.update(false)
    }
    
    show outline.entry.where(
      level:1,
    ): set block(above: 1.2em)
    show outline.entry.where(
      level:2
    ): set block(above: 1.1em)
    show outline.entry.where(
      level:3
    ): set block(above: 1.1em)
    // ------------------------------------------------------------

    body
  }

#let makeTitleAndHeader(body) = {
  v(29em)
  align(center,
    text(size: 25pt, weight: "bold", body)
    )
  pagebreak()
  }

// code in question // -----------------------------
#let make-outlines = {
  outline(
    title: "Contents")
  outline(
    title: "List of Tables",
    target: figure.where(kind: table))
  outline(
    title: "List of Figures",
    target: figure.where(kind: image))
  }
// ------------------------------------------------------------

supplemental_page.typ

#import "config.typ": flexCaption 

// example use
#let supplemental_page = [
    #figure(
        table(
            columns: 2, 
              [ a], [ b ]
        ),
        caption: flexCaption([long caption...], [short caption]),
        kind: table,   
    )
]
2 Likes