Word wrapping works like in LaTeX?

I’m considering typst as a possible alternative to LaTeX, but I can’t seem to reproduce how LaTeX breaks words.

I’ve experimented a bit and found that justify improves the results somewhat, but it’s still not perfect.


latex


typst

If possible, I’d like typst to simply fit as many characters as possible into a line and wrap what doesn’t fit, regardless of any hyphenation rules

Code example

#set page(paper: "a4", columns: 2, margin: (top:10mm, bottom:5mm, left:10mm, right:5mm), numbering: "1")

#set par(first-line-indent: (
  amount: 1em,
  all: true,
), justify: true)
#set text(lang: "uk", font: "New Computer Modern", size:10pt, hyphenate: true)
#set columns(gutter: 10pt)

Розрiзняють також: 1. *Оборотнi* процеси - це такi круговi процеси, пiсля яких
система повертається до початкового стану i при цьому в оточуючому середовищi
не вiдбувається нiяких змiн. 2. Всi процеси, якi протiкають самодовiльно -
*необоротнi*. В результатi необоротного процесу неможливо повернути до
початкового стану нi систему, нi навколишнє середовище.

Also, I see that the distance between lines of text is somewhat larger than in latex, how to make them the same

In the compared examples, the latex example has 4 consecutive lines with hyphens, that’s normally not considered good typography so doesn’t typst already kind of win this comparison?

Could you clarify - do you want hyphenation but without using dictionary/rules for where to break words, or you don’t want any hyphenation at all?

There is this hack which probably could cause unexpected problems - intersperse every word with soft hyphens, which allows it being broken at any point. That should be a kind of maximal allowed hyphenation. See also this issue

#show regex("\b.+?\b"): it => it.text.clusters().join(sym.hyph.soft)

This is how the example looks with that code. It’s broken one word in a radical way, leaving a lonely я on the new line.

bild


This is what your example looks like using a development build of Typst where just the microtypal shrink/expansion is enabled (This pull request in its current state) - the result shows typst now didn’t need hyphenation for the example.

bild

Well, I’m not really worried about typography. I’m just a student, and I use LaTeX for notes and lab protocols (we can change them, just the identity of the material is necessary), and printing these labs is quite expensive if you don’t have your own printer, so I need to compress any text as much as possible, and LaTeX performed this task quite well, but I encountered some technical limitations (especially the fact that the Cyrillic i is somehow replaced by the Latin i)

The first one variant

And I also found the answer to my question.

#set text(costs: (hyphenation: 1%))

using this property makes them, if not identical, then practically the same

But this question of things is not resolved for me:

I think you didn’t really understand the question. I just don’t know what this section is called between the lines of the text. It’s between
“Розрiзняють також: 1. Оборотнi процеси - це такi кру”
and
“говi процеси, пiсля яких система повертається до початко” …
(in my LaTeX example)

P.s. I’m using a translator, sorry for the bad English.

1 Like

I did understand that question too, I just don’t have an answer to it. Hopefully someone on the forum has an answer.

1 Like

In word it is “Line and Paragraph Spacing”

par.leading

Great, that’s a good point, I didn’t think about the costs at all. I’m not sure if it makes the text actually shorter, though.

When I compare your initial two pictures, Latex typesets the text with 6 full lines and two more words, and Typst with 6 full lines and one more word. That means that Typst is actually using less space for the same text, right? With more eager hyphenation (lower cost) typst also uses 6 full lines + two words, same as Latex… but wasn’t that actually longer, less compact?

Either way, when you have all the parameters, you can experiment with them for best results.