Skip to content

Adjust PP blockquotes for Typst#740

Merged
mattleff merged 7 commits into
mainfrom
typst-poetry
Apr 24, 2026
Merged

Adjust PP blockquotes for Typst#740
mattleff merged 7 commits into
mainfrom
typst-poetry

Conversation

@mattleff

Copy link
Copy Markdown
Collaborator

Refs #735. This solution was found here and we will need to add the poetry definition in the process of rendering the documents:

#show raw.where(lang: "poetry"): it => {
  set par(leading: 0.76em) // increase spacing between lines
  set text(font: "EB Garamond", size: 1em * 1.25) //factor of 1.25 cancels default raw font-size
  set raw(theme: none)
  let space-width = 0.5em
  block(
    inset: (x: 2em, y: 1em),
    eval(
      it.text
        .replace(regex("\n\n+"), "#parbreak()")
        .replace(regex("\n( *)"), (i) => {
          "\ "
          if i.captures.at(0).len() > 0 { "#h(" + repr(i.captures.at(0).len() * space-width) + ")" }
        }),
      mode: "markup",
      scope: (
        :
        // add whatever you need here
      )
    )
  )
}

@bountonw I'm not sure how you're testing the rendering now. Do you have a place where you're keeping the custom functions, etc.? Do we need to set up GitHub Actions for rendering these on PRs? If you can let me know what you've figured out so far and how you want it to work I can try to hook up the plumbing.

@mattleff mattleff self-assigned this Apr 13, 2026
@mattleff mattleff changed the title Adjust blockquotes for Typst Adjust PP blockquotes for Typst Apr 13, 2026
@mattleff

Copy link
Copy Markdown
Collaborator Author

I wasn't sure how you wanted to handle the highly indented references. I had Claude put those as quote attribution elements, but if that's the wrong thing let me know and I can move them. So just a heads up...

@bountonw bountonw left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattleff ok. This will at least get us something to work with. We can adjust when we see the output.

@bountonw

Copy link
Copy Markdown
Owner

@mattleff Don't merge yet. Kenton is looking at it.

@kenton-r

Copy link
Copy Markdown
Collaborator

So there is a big limitation to using a Code block. The limitation is single-line evaluation. So this means that all of Typst text processing is not available inside the code block (bold, italic, and horizontal indents). setting up a new element would probably be better if we want to use any styling inside the poetry text.

There is a down side to this way as well. Each manual line break must have a \

The styling would look like this:

#let poem(
  body,
  attribution: none,
  font: "EB Garamond",
  size: 11pt,
  style: "italic",
  indent: 2em,
) = {
  set text(font: font, size: size, style: style)
  pad(left: indent, right: indent, {
    body
    if attribution != none {
      v(0.5em)
      align(right, text(style: "normal", size: size * 0.9, [— #attribution]))
    }
  })
}

The usage would be:

#poem(attribution: "Name of Author")[
  Under the greenwood tree \
  Who _loves_ to lie with me, \
  And turn his merry note \
  Unto the sweet bird's throat, \
  Come hither, come hither, come hither: \
  #h(1em) Here shall he see \
  #h(1em) No enemy \
  But winter and rough weather.
]

So I guess it depends on what the needs are for the inside text of the quotes.

@mattleff

Copy link
Copy Markdown
Collaborator Author

@kenton-r Doesn't the eval(...) in the code I found allow in-text markup too? Would the #poem[] element support multiple levels of indentation?

@kenton-r

kenton-r commented Apr 14, 2026

Copy link
Copy Markdown
Collaborator

I am sorry, I was looking at the wrong code in the forum instead of the one you copied to here.
Yes, the eval() would work for single line evaluation and multi-line spanning. And the above code you sited the spaces do get turned into horizontal spaces.

So you are adding a block for an attridute. Are you wanting to do this on all quoted Bible verses?

#quote(block: true, attribution: [(เฉลยธรรมบัญญัติ 33:26–29 THSV) #EGW[{PP 471.2}]])[
```poetry
“ไม่มีผู้ใดเสมอเหมือนพระเจ้าแห่งเยชูรุน
ผู้ประทับอยู่บนฟ้าสวรรค์เพื่อช่วยท่าน

พระองค์ทรงเป็นโล่และเป็นผู้ช่วยท่าน”
```
]

The code you have also deals with extra lines too.

I think that the eval() is good.

@bountonw

Copy link
Copy Markdown
Owner

@mattleff @kenton-r Where are we with this? Is it ready to merge or are we still discussing?

@mattleff

Copy link
Copy Markdown
Collaborator Author

@bountonw If this makes sense to @kenton-r I think we're good to merge. FWIW, I haven't been able to test this yet myself. When I try to compile I get a unknown variable: chapter error. I'm assuming we will need to include #chapter somehow in what we compile, but I don't see where it's defined atm.

@bountonw

Copy link
Copy Markdown
Owner

@mattleff @kenton-r We need the style sheet for anything to work. #chapter and #EGW need to be defined. But where it is put and how it is linked etc. is something that @kenton-r is working on.

@mattleff mattleff merged commit 0774820 into main Apr 24, 2026
9 checks passed
@mattleff mattleff deleted the typst-poetry branch April 24, 2026 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants