How can I add labels to a plot inside another plot

Copying the code from the examples here

I have tried to add a label to the inner plot like:

#import "@preview/lilaq:0.6.0" as lq

#let weierstrass(x, k: 8) = {
  range(k).map(k => calc.pow(0.5, k) * calc.cos(calc.pow(5, k) * x)).sum()
}

#let xs = lq.linspace(-0.5, .5, num: 1000)
#let xs-fine = lq.linspace(-0.05, 0, num: 1000)

#show: lq.set-grid(stroke: none)

#lq.diagram(
  width: 14cm,
  height: 7cm,
  ylim: (0, 2),
  margin: (x: 2%),

  lq.plot(xs, weierstrass, mark: none),

  lq.rect(-0.05, 1.5, width: .05, height: .3),

  lq.place(
    60%, 100% - 1.2em,
    align: bottom,
    lq.diagram(
      width: 5.4cm, height: 2cm,
      margin: 0%,
      ylim: (1.5, 1.8),
      fill: white,
      lq.plot(
        xs-fine,
        weierstrass,
        mark: none,
        label: [Inner],
      ),
    )
  )
)

It fails with the error:

error: expected function, found alignment
   ┌─ @preview/lilaq:0.6.0/src/style/styling.typ:32:4
   │
32 │     (it.align)((
   │     ^^^^^^^^^^

help: error occurred while applying show rule to this grid
   ┌─ @preview/lilaq:0.6.0/src/model/legend.typ:88:4
   │
88 │     grid(..it.children)
   │

I have also tried to put it manually with lq.legend in the inner plot, but it gives the same error.

I guess it is possible to “fake” it in the outer plot, and move it by hand. In this case:

  1. How do I make it appear on top of the inner plot? I played with the z-index, but it never shows up.
  2. How do I make the figure of “dashed”, “dotted”, “solid” and “marker with error bars” appear in the legends by hand?

I managed to solve the first point. I had to manually set a different z-index both to the inner plot, and to the outer manually-placed legend.

I still don’t know how to create the equivalent legend drawings that get generated for “no marker dashed line”, “no marker dotted line”, “no marker solid line”, and “no marker, no stroke error bars”.

I would appreciate if someone could point me to some examples creating these legend entries by hand.

Hi @Katty , this sounds like a bug, I will investigate!

Okay, so the error you got is definitely a bug: it’s due to an internal workaround that I use to implement show rules for marks. You might be aware of the long-standing problem that Typst does not yet allow users to create new types (for which set and show rules can be applied). In order to mimic an essential feature of Lilaq (style cycles), I have lq.mark be an alias for grid to allow flexible styling. Legends, however, also use the grid and there is an internal conflict between those.

Fortunately, this issue will go away automatically as soon as custom types are available and Lilaq uses them. As of now I see no temporary fix that I can make but your workaround is clever.

Does your other diagram also need a legend or do you just need the one legend for the inner diagram?