Why bottom pad in paragraph breaks left pad in quote?

If I add a relative bottom padding to paragraphs via show rule, it breaks an absolute left padding to quotes, which gets then wrong size. A minimal working example:

#set page("a7") // just for presentation here
#show quote: set pad(left: 1cm)
A text.

#quote(block: true)[This quote gets correct padding.]

#show par: it => {
  pad(bottom: 1em, it)
}
#quote(block: true)[This quote gets wrong padding.]

Ideally, in fact, I would use a weak vertical space after every paragraph, not padding. I tried to do so with code below, but it doesn’t work. That’s why I resorted to the pad function. If anyone knows a better way to accomplish this, please let me know.

#show par: it => {
  it
  v(1em, weak: true)
}

Hello,
The way you are writing things results in the following code:

#set page("a7") // just for presentation here
#quote(block: false)[
  #set pad(left: 1cm)
  Not padded.
  #pad(bottom: 1em)[Padded.]
]

To explain further:

  1. The first show rule sets the left property of pad for the entire document.
  2. The second show rule wraps the content of any par in pad(bottom: 1em).

The two rules do not interfere with each other. You can read the documentation at Styling – Typst Documentation to get a better idea of how show rules work!

It seems you didn’t try the minimal working example I wrote. I’ve put in it very small paragraphs and quotes, and a little padding (1cm) but the problem happens independently of that. Also, you’ve cited the docs: please note that I’ve styled the quotes according to the quotes documentation.

So, anyone has any idea why a paragraph’s bottom padding interferes (doubles) a quote’s left padding?

The problem, as I understand it, is that show quote: set pad(...) doesn’t just affect the specific pad that quote itself adds, but all pads inside the quote. Your second show rule adds another pad inside, so it also gets left: 1cm.

Unfortunately I’m not sure how to best fix this cleanly. As a workaround, you can manually specify left: 0em for that pad, I wouldn’t consider that clean really clean…

Yeah, there is one pad already existing: typst/crates/typst/src/model/quote.rs at 40fcd97d584fc1dfa6446bc4922d3b1e440e0afd ¡ typst/typst ¡ GitHub. The second one would wrap the whole quote. So there are 2 pad elements in total. And since the show-set rule is global, it applies to both pads. Which indeed will explain why left padding has a x2 multiplier when it gets set.

You probably don’t need a second pad, so I would write the last show rule like this:

#show quote: set pad(bottom: 1em)

Otherwise, the solution given by @SillyFreak is probably your next best bet.

1 Like

I would have suggested that, but it doesn’t seem to do anything; I’m not sure why. Vertical spacing between blocks is something I have not understood fully yet…

1 Like

Here it does succeed in apply the paragraph’s padding without interfere in the quote’s padding…

But in fact I changed the way of accomplish this to setting the spacing in block element:

#set page("a7") // just for presentation here
#show quote: set pad(left: 1cm) // left padding
#show quote: set block(spacing: 2.2em) // vertical space around block quote
#show par: set block(spacing: 1.5em) // vertical space around paragraphs

#lorem(13)

#lorem(13)

#quote(block: true)[#lorem(13)]

#lorem(13)

2 Likes

I did in in fact try your MWE before writing my answer, but it seems my reply was too confusing. Sorry about that! As you found your answer and @Andrew explained, when I wrote

The two rules do not interfere with each other

I meant to emphasise that your show quote: set pad and show par: it => {} were adding up to each other.

About the documentation, there is nothing wrong with the way you wrote quote styling. As you say, it’s very much the same way the documentation does things.

Just so you’re aware,

#show par: set block(spacing: 1.5em) // vertical space around paragraphs

Removing this does not seem to affect your desired output, and I believe these exist only in the form of boxed display mathematics? See below

#set page("a7") // just for presentation here
#show par: set block(fill: yellow, spacing: 1.5em) // vertical space around paragraphs

#box[test, $"test"$, $ "test" a x + b $]

#block[test, $"test"$, $ "test" a x + b $]

#quote[test, $"test"$, $ "test" a x + b $]

Oops, I didn’t test this. After some debugging, I think par should be replaced with quote. The problem is that (I’m pretty sure) par doesn’t have pad inside of it, so changing pad for par doesn’t have any effect. If pad affected the `par, then instead this could be used:

#show quote: it => { show par: set pad(bottom: 1em); it }

This means that you didn’t in fact apply “paragraph’s padding”. Almost all elements are block-level, which means that modifying block’s settings will affect such elements. And you used show par|quote: set block in this case, so this would make sense (to work).

It does for me with v0.11.1.

I am running on the latest Typst master, which may explain why we don’t have the same output… nevertheless I’m surprised there’s a difference?

I’m not familiar with Typst dev/internals, so I cannot think of any explanation :frowning:.

P.S.: just in case someone is also running on the master I have 8c813cb7.

Ohhh! I remembered! It’s because now you have to write set par(spacing: 1.5em) instead. But… this still doesn’t affect the layout…

@laurmaedje, do you know what’s the problem here?

that seems to do the trick! how did you ever remember that haha

Some things are easily remembered. And with time, some issues are easier to remember, but others — harder. It also depends on whether the problem has surfaced/was mentioned several times or not. And on how big/impactful the change is. This will probably have a big impact.