I am using a counter as a label and index for block and inline quotations. The counter should appear in the right margin of the page on the same line as the beginning of the quotation.
When used with inline quotations, the index works only if it is at the beginning of a paragraph, otherwise the index causes a paragraph break before it is placed. Why is this?
#let qi = counter("qi")
#let QI(label) = {
qi.step()
context{
place(right,
dx: 15mm,// How can this be made relative to the page?
text(
fill: red,
size: 0.8em,
weight: "semibold",
qi.display()
)
)
[
#metadata("qi")#label
]
}
}
#QI(<RB1>)Synesius wrote (as translated by Robert Burton): #quote(block: false)[It is a greater offence to ſteale dead mens labours, than their clothes.]
Synesius wrote (as translated by Robert Burton): #quote(block: false)[#QI(<RB2>)It is a greater offence to ſteale dead mens labours, than their clothes.]
Overlaid elements don’t take space in the flow of content, but a place call inserts an invisible block-level element in the flow. This can affect the layout by breaking the current paragraph. To avoid this, you can wrap the place call in a box when the call is made in the middle of a paragraph. The alignment and offsets will then be relative to this zero-size box. To make sure it doesn’t interfere with spacing, the box should be attached to a word using a word joiner.
First, thank you for the replies to this and my other questions. I have learned quite a bit about Typst semantics and coding style.
I now have addressed the issues from the question dealing with the two-level arrays to my satisfaction.
The other two questions are, as you note, related. They do not seem to have simple (relative to my skills with Typst scripting) answers.
One possible solution, I have realized, is that I should have two index functions, one for block quotations and one for inline quotations, each of which references and increments the same counter. This allow me to specify a different dx in the placement of each. However, I am still troubled by the weak break inserted before place for the inline quotations. If I do not box it, a dx value of 7.5mm (for this font face and size) places the index properly in the margin but the break is inserted. If I box it, however, the x-position is tied to the placement of the #Qi function in the text, and no easy calculation seems available to adjust it.
I am able to get around this problem by using the drafting package. This allows placement of the index in the right margin and allows dy adjustment to move it back up to the proper line. I have not yet tested this with edge cases like quotes starting near the bottom of a page, but obviously need to be sure that there is no issue there.
It seems to me to be a cumbersome way to accomplish something that otherwise seems should be simple to do.
This question is, I supposed, solved in the sense there is no way with Typst 0.13.1 to avoid the break in such a way that dx is relative to the size of the container, and not the box that inhibits the break.