Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widow and orphan prevention can unnecessarily move text into next column #1445

Closed
1 task done
zylthinking opened this issue Jun 9, 2023 · 5 comments · Fixed by #4767
Closed
1 task done

Widow and orphan prevention can unnecessarily move text into next column #1445

zylthinking opened this issue Jun 9, 2023 · 5 comments · Fixed by #4767
Labels
bug Something isn't working layout Related to layout, positioning, etc. text Text layout, shaping, internationalization, etc.

Comments

@zylthinking
Copy link

zylthinking commented Jun 9, 2023

Description

The following code will put fault in the 2nd column and put the correct in both columns


#let split_2_columns(text) = {
    layout(size => style(styles => {
        let (height,) = measure(
            block(width: size.width - 22pt, text),
            styles,
        );

        block(
            width: size.width,
            height: height,
            columns(2, gutter: 11pt, text)
        )
    }))
}

#let s = [
    This research was funded by the
    In recent years, deep learning has
    increasingly been used to solve a
    variety of problems, what is the fuck with y.
]

// fault
#split_2_columns()[
    #set par(justify: true)
    #s
]

//correct
#split_2_columns()[
    #set par(justify: false)
    #s
]

Operating system

linux

Typst version

  • I am using the latest version of Typst
    YES
@zylthinking zylthinking added the bug Something isn't working label Jun 9, 2023
@zylthinking
Copy link
Author

another found:

#let split_2_columns(content) = {
    layout(size => style(styles => {
        let sz = measure(
            block(width: size.width - 22pt, content),
            styles,
        );

        block(
            width: sz.width,  // ------------------- replace it size.width causes problems
            height: sz.height,
            columns(2, gutter: 11pt,  content)
        )
    }))
}

sz.width = 431.6pt
size.width = 453.6pt

In my system

@zylthinking
Copy link
Author

zylthinking commented Jun 9, 2023

Found the rule:

if (sz.width - gutter) < size.width - 22pt {
      put text to 2nd column
} else {
    put text to both columns
}

seems not the rule


#let split_2_columns(content) = {
    layout(size => style(styles => {
        let sz = measure(
            block(width: size.width - 22pt, content),
            styles,
        );

        block(
            width: 654.0pt, // 655.0pt  is different
            height: sz.height,
            columns(2, gutter: 0pt,  content)
        )
    }))
}

@laurmaedje
Copy link
Member

The reason for this is Typst's widow and orphan preventation. Without justification, your text fits into four lines, two in the first and two in the second. With justification enabled, spaces can be shrinked a bit and now the text suddenyl fits into three lines. To prevent a single line from being alone, Typst forces all three to be together. Because together they don't fit into the first column, they are moved into the second (where they also don't fit in this case).

@zylthinking
Copy link
Author

zylthinking commented Jun 14, 2023

But how to explain width: 654.0pt is different with 655.0pt, both are large enough to hold the text (while 2 columns together will exceed the width of page).

654pt will put the text in 1st column
while, 655.0 pt will put the text in 2nd column.

And because 453.6pt will also put the text in 2nd column, I belive there is some width W ( 453.6pt < W <= 654pt), which will begin to put the text from 2nd to 1st column.

#let split_2_columns(content) = {
    layout(size => style(styles => {
        let sz = measure(
            block(width: size.width - 22pt, content),
            styles,
        );

        block(
            width: 654.0pt, // 655.0pt  is different
            height: sz.height,
            columns(2, gutter: 0pt,  content)
        )
    }))
}

@laurmaedje laurmaedje added layout Related to layout, positioning, etc. text Text layout, shaping, internationalization, etc. labels Nov 14, 2023
@laurmaedje laurmaedje changed the title set par(justify: true) will force the text be put into the 2nd column set par(justify: true) will force the text be put into the 2nd column May 21, 2024
@laurmaedje laurmaedje changed the title set par(justify: true) will force the text be put into the 2nd column Widow and orphan prevention can unnecessarily move text into next column Jun 14, 2024
@laurmaedje
Copy link
Member

Minimized:

#block(height: 30pt, fill: aqua, columns(2, lorem(19)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working layout Related to layout, positioning, etc. text Text layout, shaping, internationalization, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants