How to repress line breaking before punctuation

(Note: Thai spaces at the phrasal level and not the word level.)

I have a ~900 page Thai document that I am trying to typeset and in the first paragraph I noticed that a line is breaking before a closing smart quote. So that in my pdf I have something like the following

นายบุญคำไปตลาดเพื่อซื้อทุเรียน.
"

Where the quotation mark is actually a double closing smart quote (U+201D). It is still early days in typesetting this book and there may be other punctuation that lines are being broken before.

  1. How can I suppress breaking before single and double closing smart quotes?
  2. How can I suppress breaking before other punctuation in case that becomes an issue?

In case there is something here that is causing my problem. Here are my settings:

#set page(
  width: 176mm,
  height: 250mm,
  margin: (inside: 20mm, outside: 15mm, top: 15mm, bottom: 20mm)
)

#set text(font: "Sarabun", 
     size: 11pt,
     lang: "th",
     hyphenate: true)

#set par(justify: true, 
     justification-limits: (
       spacing: (min: 90% - 0.01em, max: 100% + 0.02em), 
       tracking: (min: -0.01em, max: 0.01em)),
     first-line-indent: (amount: 1.5em, all: true),
     linebreaks: "optimized",
     leading: 0.85em,
     spacing: 0.85em)

EDIT:

Here is the actual text causing the problem. However, the text should be irrelevant. Given a ~900 page document with numerous quotes, if splitting before a quotation mark is possible, then statistically, it will happen. I need a way to repress it.

“พระเจ้าทรงเป็นความรัก” (1 ยอห์น 4:16 THSV) ทั้งพระลักษณะและพระบัญญัติของพระองค์ก็เป็นความรัก เป็นอย่างนั้นเสมอมา และจะเป็นอย่างนั้นสืบไปเป็นนิตย์ “องค์ผู้สูงเด่น คือผู้อยู่ในนิรันดร์กาล” และทางแห่ง “การเสด็จของพระองค์ก็เป็นดังดั้งเดิม” นั้น ไม่ทรงเปลี่ยนแปลง ในพระองค์ “ไม่มีการแปรปรวน หรือไม่มีเงาอันเนื่องจากการเปลี่ยนแปลง” (อิสยาห์ 57:15 TH1971; ฮาบากุก 3:6 TH1971; ยากอบ 1:17 TH1971)

After playing around with each of your settings individually, it seems that the issue comes from the small min tracking value:

tracking: (min: -0.01em, max: 0.01em)

If I set it to -0.16em I can’t find a page width that causes the error again. It’s up to you, of course, to decide whether this change is acceptable or not.

MWE
#set page(width: 61mm)

#set text(
  //font: "Sarabun", 
  size: 11pt,
  lang: "th",
  hyphenate: true
)

#set par(justify: true, 
  justification-limits: (
    spacing: (min: 90% - 0.01em, max: 100% + 0.02em), 
    tracking: (min: -0.16em, max: 0.01em)
  ),
  first-line-indent: (amount: 1.5em, all: true),
  linebreaks: "optimized",
  leading: 0.85em,
  spacing: 0.85em
)


"นายบุญคำไปตลาดเพื่อซื้อทุเรียน"

Thank you, my nonsensical example (“Mr. Boonkham went to the market to buy durian”) was not the actual paragraph. (I didn’t want to share my private information on the public forum.) The issue with the break before the quotation mark was there even before I added the “tracking” code. Also, if we adjust the tracking and fix the first paragraph, who is to say that the change doesn’t cause a break before a quotation mark somewhere down stream in the ~900 page document. I need a solution that forbids breaks before closing quotation marks. In my TeX header, I have code that does this for my ~700 page Lao book. However, I am trying to avoid using TeX moving forward, if possible.

I cannot reproduce quote being left alone with the given settings.

#h(22.0051em)นายบุญคำไปตลาดเพื่อซื้อทุเรียน."

image

I also don’t have the specified font.

Thank you. I have edited the original post to include my actual text. However, the text should be irrelevant. I don’t want to have to adjust margins, font size, and/or other spacing rules at each paragraph in order to trick typst not to split before certain punctuation. I need a way to globally repress splitting before certain characters. (I would have thought that not splitting before a closing quote would be automatically enforced and that it should be people wanting to split before the closing quote who should be asking for assistance on how to do it.)

I don’t understand what’s the point of using " U+22 to represent the output of PDF, only to then immediately say that it’s not actually " U+22, but U+201D.

I found out that it’s a free font, but changing font did not change the situation.

Looking at the “actual text”, there is not only no overlap, so it’s a completely different thing, but there is also no combination of period and comma. So it’s all very confusing.

Given a new “actual” text, I tried again the same thing, but without a period, and this time was able to put a quote on a separate line.

// Noto Sans Thai + Libertinus Serif
#h(22.1em)นายบุญคำไปตลาดเพื่อซื้อทุเรียน"

// Sarabun
#h(21.5em)นายบุญคำไปตลาดเพื่อซื้อทุเรียน"

I’m pretty sure that in other languages, quote does not detach itself. I assume it should just work for all scripts. So this probably means that each language should have some kind of logic attached to it. I don’t know where this logic lives, but there are definitely no smartquotes for Thai, that’s for sure (typst/crates/typst-library/src/text/smartquote.rs at a2aa1274b9af95b132599fb47a7e495a15f9e3aa · typst/typst · GitHub). Only some translations (typst/crates/typst-library/translations/th.txt at a2aa1274b9af95b132599fb47a7e495a15f9e3aa · typst/typst · GitHub).

So my guess is that Thai typesetting rules should be added, or at least quote behavior logic.

Sorry. I probably should have tried to copy-paste the smart quote, since typing a quote here gives straight quotes.

Thai doesn’t use periods or commas in regular text. From the many Thai books on my book shelf, all of the quotes are smart. But not all fonts have a smart quote glyph. So I think that publishers must grep a Latin font for the smart quotes or some other method if the Thai font doesn’t have it. (I don’t know if my selected font has a glyph or not and don’t know how to check.) Regardless, there should be no break before single or double smart quotes.

Look at embedded fonts in the PDF file. The Sarabun font is the only one present, so that means it has the quotes.

If you don’t know yet, you need to create an issue for that.

Thank you. I have created an issue.

1 Like