Configurable character protrusion for both margins#7782
Configurable character protrusion for both margins#7782sicikh wants to merge 4 commits intotypst:mainfrom
Conversation
|
i would propose it differently: lets keep an option that make simple things simple but still allows complex behavior: for "bool" case
this is actually a weak case and could be dropped entirely by using the case below. for the string/enum casesimple "left", "right", "both", "default", and "none" overhang layout with whatever characters agreed as the default. for the dict casethis follows the proposal of the OP but more refined: what do you think ? |
|
Thanks for the suggestions! My thoughts on this:
With this, the API for the dict case may look like the following: #set text(overhang: (
map: (
"«": (100%, 100%),
"»": (100%, 100%),
"”": (100%, 100%),
"“": (100%, 100%),
// Enable overhang only for the left margin.
"A": (10%, 0%),
// Customize protrusion only for the left margin,
// use default values for the right one.
"-": (100%, auto),
),
// Use built-in values for other characters on the right margin
// (could be `left`, `right`, `true` or `false`).
// If omitted, results in `false`.
rest: right,
)) |
|
I'm not yet ready to comment on this at large, but still wanted to add three points to the discussion:
|
|
You could use the alignment type, i.e. |
|
unfortunately, adding |
I think that we should not deprecate
That is quite an interesting idea! The question now what signature should this function have. I see two options:
Currently, I'm leaning more towards the first option. |
5ea7ed5 to
02cb067
Compare
|
The situation is as follows.
|
|
As I read in Hàn Thế Thành's dissertation, this PR implements so-called "level 1 character protruding" (pp. 41-43), when "margin kerning" is used when lines are already laid. "Level 2", on the other hand, incorporates margin kerning into the layout algorithm. Since very good results were obtained in #6161 when character-level justification was included in the layout algorithm without much changes, I think we can do this too. I will study this in more detail. See the comparison between level 1 and level 2 character protruding from Hàn Thế Thành dissertation (p. 47) below:
|
…ert `overhang` value from function to dictionary
|
Hi! I see that
Is that an essential limitation of the current design, or merely a superficial restriction of the interface (or data types)? Besides, I suggest updating the PR description or at least adding a note. The current version is outdated and misleading. |
Hi! Yes, this is a current limitation of the interface, but not a technical one. I just haven't had time to think about how to describe the protrusions for several characters, but at the same time to disallow, for example,
Also thought of this, will change it in a minute. UPD: done. |
overhang configurable, add overhanging to the left margin

Resolves #261, resolves #7231, and closes #6582.
This PR changes the behaviour of the
text.overhangproperty, such that:Left and right margins can be used for overhang characters for LTR and RTL languages accordingly.
Users can now specify where overhang characters should happen:
trueorfalse),leftorright),startorend),Old values
overhang: falseandoverhang: truestay, buttruechanges its meaning from "enable default overhang punctuation only for the end margin" to "enable default protrusions for both margins".The default value changes from
truetoend, that works as previoustrue.Most beneficial result is that overhang punctuation is now considered when paragraph is being laid out, what leads to better linebreaks and hyphenation. Now documents, that were using default values (and that will continue to use them), will benefit from this PR without additional changes from their side.
For the results see below:
Code
API
Rationale
As written in #7231 (comment), the main problem for this functionality is the API. #7231 (comment) proposes some kind of automatic calculation for the amount of protrusion for characters.
Main argument against disabling the possibility for customizing protrusions is that such algorithm, that can be implemented in the future, may yield suboptimal results. In some circumstances users may want to customize behaviour per character or per margin basis (see #7231 (comment) and #6582).
Thus, the API should take into account, that such algorithm for calculating protrusions by default may be implemented later, but also should give users a possibility to directly adjust values.
Another option was considered to rather recieve function
(char, side) => protrusion, but it has some technical limitations. Also manipulating dictionaries from the user-side is better than with the black-box functions (think of possible typst's "microtype" package with those protrusion tables).TODO
Improve API such that table may contain keys for the characters, consisting of multiple UTF-8 characters (see Configurable character protrusion for both margins #7782 (comment)), while disallowing incorrect usage.
Improve error handling (nested dictionaries have bad ergonomics...).
Design and implement folding for
text.overhang.