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

Text wrapping: Multiple overflowing lines leads to small remainers #62

Open
TiborVoelcker opened this issue Dec 6, 2024 · 5 comments
Open

Comments

@TiborVoelcker
Copy link

Hey! First of all, great project! I can see how this will become the new standard in the future.

I feel like this issue must have come up before, but did not find it. I had a hard time coming up with a good descriptive title, I think it is best explained with an example. My issue is with this text:

something something something something
something something something something something

Wrapping with a length of 30 (3 something's) will result in:

something something something
something
something something something
something something

While I feel like it should format to:

something something something
something something something
something something something

This happens quite frequently to me, as I format my document on every save (as probably many do). Then I will add a word here, remove a word there... At the end I am stuck with way too many lines, where many of which only have a few words in it.

@WGUNDERWOOD
Copy link
Owner

WGUNDERWOOD commented Dec 6, 2024

Thanks for this! You might be interested in #6, which addressed a similar problem. Here are some of my thoughts on this.

The line wrapping logic is currently implemented as follows.

  • If the line length is at most wraplen, no changes are made.
  • If the line length is more than wraplen, it is wrapped to a length of wrapmin.

Here, wrapmin = max(wraplen - 10, 40). The idea is to anticipate such multiple wrappings by trimming slightly more than is absolutely necessary.

All this is to say, maybe try an example with the wrap length set to at least 50? This may partially help your issue, though of course it is not an exact fix. A more robust solution is likely to be quite difficult, as the line length depends on the indentation, which depends on the content of the line, which depends on where it is wrapped, etc.

@brad-ellert
Copy link

The problem is that the wrapping here is not reflowing the text. While this is technically wrapping it to the required line length, this is not what most would expect when specifying a wrapping parameter. To expand on the original example, going in the opposite direction (i.e., trying to increase the wrap) will do nothing.

something something something
something something something
something something something

wrapped to 40 will result in

something something something
something something something
something something something

instead of

something something something something
something something something something
something

@TiborVoelcker
Copy link
Author

@WGUNDERWOOD I did not realize about this minimum wrapping, that does indeed make it look less choppy. But like you said, this does not really fix the issue. Also as @brad-ellert correctly stated, one would expect that increasing the wrapping length later on would change the wrapping.

I also do understand that this is MUCH harder to implement. I presume one has to detect the blocks of text and then wrap the block in its entirety. This comes with all the issues that latexindent is facing. But in my humble opinion, this is the path that this tool should take, if it strives to be the latex formatting tool. And I believe it should and can become this.

Long story short, this is meant as an issue to sit around for a while where people drop a "+1" every now and then. Not sure if this is helpful.

@cdesaintguilhem
Copy link
Contributor

Hi everyone, the re-wrapping feature of other formatters is also something I'm very keen to see tex-fmt capable of doing.

I've started some preliminary work in my fork of the project (https://github.com/cdesaintguilhem/tex-fmt/tree/cdsg-rewrap) to see what can be done. For now there is quite a lot to implement so I won't open even a draft PR, but I'm hoping to have some time to work on it some more.

@WGUNDERWOOD
Copy link
Owner

Thanks very much for this @cdesaintguilhem ; let me know if you need me to take a look at anything!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants