-
-
Notifications
You must be signed in to change notification settings - Fork 806
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
Trim weak spacing at line start/end in paragraph layout #4087
Conversation
Ignoring any kind of spacing at the end of the line is a bit problematic, as it might be an intentional #set align(right)
Hello #h(2cm) What could be a good alternative is only doing this for weak spacing. I've on multiple occassions thought that it's somewhat odd and maybe a bug that |
Yeah after think about it is is a littlle bit problematic. I will take a look so that we only consume weak space. BTW how do you see the updated test case for bidi-reset-whitespace? (I checked the commit history and seems to be early commits done by you @laurmaedje ) |
Looks like the text space before the |
Okay I just read the code and some relevant PRs about weak spacing. It seems to me that mainly the weak space is all handled inside the Equation and would not really be handled properly when the space item goes into linebreak. So I think we will modify some data structure to pass the weak attribute so that the later linebreak procedure can know whether a space is weak or not. For the example you provide, I think I understand the expected behaviour for this is the non-weak space would be preserved
But I am still a little unsure of what you mean by the following
I am not sure about what the expected behaviour would be (Can you elaborate on this a little? And then I can put into new test cases) |
Exactly.
Just what you said above: Weak spacing is removed, non-weak spacing is preserved. If a line happens to end with or start with a weak spacing, we trim it. Basically, my idea was to add a This code snippet illustrates the problem (with default A4 page, not test runner style): #lorem(15) #h(5cm, weak: true) #lorem(5) There are actually multiple issues here: First that the |
PR updated. Now will propgate the weak attribute to segment::spacing and item:absoulte, which will be used in line layouting.. Now added three test cases |
@laurmaedje can this PR be merged? anything blocking it? |
Since it touches the core paragraph layout, I wanted to give it another careful review and I haven't gotten to that yet. |
Thanks! |
Refactor frame metadata into tags (typst#4212) Require `Send` and `Sync` for worlds (typst#4219) Optimize counters and state (typst#4223) Add `windows` method to array (typst#4136) Improve `CITATION.cff` file (typst#4201) Fix equation resizing when adding the equation number (typst#4179) `layout` documentation improvements (typst#4196) Allow somewhat arbitrary characters as `mat`, `vec` and `cases` `delim` (typst#4211) Do layout short-circuit in flow instead of realization (typst#4231) Split `BitSet` into two types and make it a bit nicer (typst#4249) Set default value of `raw.theme` to `auto`, and allow setting `raw.theme` to `auto` (typst#4186) Extended cargo installation instructions (typst#4168) Hint for language-region pair on `text.lang` (typst#4183) Improve macro docs (+ Native*Data docs) (typst#4240) Rephrase the sentence on variable scope in Scripting documentation (typst#4250) Refactor `Capable::vtable` to return `Option<NonNull<()>>` (typst#4252) Nicer test helper CSS (typst#4269) Trim weak spacing at line start/end in paragraph layout (typst#4087) Add ability to choose between minified and pretty-printed JSON (typst#4161) Refactor PDF export (typst#4154) Reorder syntax kinds (typst#4287) Fix figure centering (typst#4276) Fix `Default` impls for AST nodes (typst#4288) Bump libc to v0.2.155 (typst#4268) Bump time dependency (typst#4294)
updated
This PR adds a bool to Segment::Spacing and Item::Absolute so that when layouting a line, the weak space in the beginning or the end of the line is removed. Note that spaces introduced by math (MathParItem) are made to be weak space. Otherwise space are specified by the weak attribute such as
#h(..., weak: true)
.Test cases are updated with the following names
Old
Math Equations might introduce a whitespace as a item to be layouted. For normal text, any white space at the end of line is trimmed; but for white spaces introduces by math equations this procedure of trimming space is not applied.
Essentially, whether a space is eaten/trimmed is a decision made during linebreak algorithm, so like in text elements we can only decide whether to trim the trailing whitespace during actual line construction when we know that a certain range of items is going to be layouted in a line; we need to make the decisions for math-equation-introduced white space when we are doing actual line construction.
Context: this bug is brought up in #3953 which planned to add decoration for math equations #2200, during the process this bug is brought up and it seems if this bug is fixed the solution of #3953 would not be working. So this PR proposes to solve the whitespace bug first, and we can figure new ways for #2200
I am hoping to fix this bug and then continue to on revising #3953 to solve #2200