After pages created with a loop, how to place things on those pages?

Hello.

Your code sample is very big, it is very hard to understand what is going on, and which part are relevant.

You don’t take advantage of the scripting, by duplicating the same parts several times, which in this case makes source file very big and hard to modify very quickly.

I fully agree with @bluss, that stuff needs to be split into building blocks, to help the file size, readability, maintainability, etc.

It seems that some stuff looks wrong, but you didn’t say if it is, or is everything is perfect.

Here is how I understand it supposed to look like, and how smallest possible code sample can look like:

#import "@preview/showybox:2.0.4": showybox
#import "@preview/cetz:0.3.4"

#set page(margin: 1cm)
#set text(11pt, lang: "fr", font: "Learning")
#show heading.where(level: 3): set text(14pt, font: "School Book New")

#let card = showybox(
  frame: (
    body-color: gray.lighten(85%),
    thickness: 0.5pt,
    radius: 0pt,
    body-inset: 1em,
  ),
  {
    let dotted-line = box(width: 1fr, line(length: 100%, stroke: (
      paint: gray,
      dash: "densely-dotted",
    )))
    block(width: 81%)[
      NOM : #dotted-line \
      PRENOM : #dotted-line \
      CLASSE : #dotted-line \
    ]
    align(center)[=== Mathématiques]
    set line(stroke: 0.8pt)
    set square(stroke: 0.8pt)
    set rect(stroke: 0.8pt)
    let diagonal-line = line(angle: 45deg, length: 100% * calc.sqrt(2))
    place(top + right, square(size: 2cm, inset: 0cm, diagonal-line))
    v(0.5em)
    rect(width: 100%, height: 2cm, {
      align(top)[Appréciation :]
      align(bottom + right)[PPO : #h(8mm)]
    })
  },
)

#let guide-lines(n, width: 16) = {
  show: place.with(bottom + right)
  cetz.canvas(length: 1cm, {
    import cetz.draw: *
    line((0, 0), (0, -0.8 * (n - 1)))
    line((width, 0), (width, -0.8 * (n - 1)))
    let stroke = (paint: gray, thickness: 0.8pt, dash: "densely-dotted")
    for y in range(n) {
      line((0, -y * 0.8), (width, -y * 0.8), stroke: stroke)
    }
  })
}

#let page-box = {
  show: place.with(bottom + right)
  show: rect.with(fill: white, stroke: 0.8pt, height: 1.6cm, width: 4.2cm)
  set align(center)
  text(8pt)[Pages / Nombre Total de pages]
  v(1fr)
  text(18pt)[#"....." / #"....."]
}

#let a-box(dx: 3.5cm, dy: 6.5cm, width: 15cm, height: 3cm, body) = {
  show: place.with(top + left, dx: dx, dy: dy)
  show: rect.with(height: height, width: width, stroke: gray, fill: white)
  body
}

#let the-box = a-box[Essai]

#let a-page(lines: 35, first: false, ..body) = {
  if not first { pagebreak() }
  guide-lines(lines)
  page-box
  if body.pos().len() != 0 { body.pos().first() }
}

#card

#a-page(lines: 28, first: true)[
  #the-box
]

// #range(2).map(_ => a-page()).join()
#for _ in range(2) [#a-page()]

#a-page[
  #a-box(dy: 2cm)[Something else]
  #a-box(dy: 50% - 1.5cm - 5pt)[#lorem(50)]
]

1 Like