Rewrap icon indicating copy to clipboard operation
Rewrap copied to clipboard

Feature Request: Rewrap option so line ends at a period for LaTeX text

Open rickhg12hs opened this issue 4 years ago • 9 comments

It can be useful to end each sentence with a period and then a newline in LaTeX, for example when storing the .tex files in a git repo (minimize diffs) or when just diff'ing .tex files in general. This is especially useful within paragraphs.

So, using this optional feature, rewrapping a paragraph would look like this:

Before Rewrapped
This is a sentence.
And this is another sentence that is too long.
Short sentence. A sentence
starting on the same line.
Followed by
one more.
This is a sentence.
And this is another sentence
that is too long.
Short sentence.
A sentence starting on the
same line.
Followed by one more.

Currently, to replicate this functionality, the user needs to carefully select each sentence in a paragraph that already has a newline after the sentence period and then hit Alt+Q. This is error prone, so this proposed feature request would be very useful.

rickhg12hs avatar Oct 27 '21 01:10 rickhg12hs

Hi, while this is doable, I feel it's quite a specific request. So I'm reluctant to add this feature until more people request it too.

stkb avatar Nov 19 '21 19:11 stkb

Understood.

For reference, amongst many others:

https://stackoverflow.com/a/6190412

rickhg12hs avatar Nov 20 '21 16:11 rickhg12hs

Thanks for that.

I know it's not everything you want, but would it be ok if it simply preserved existing newlines after a '.'? So you have to make sure you write one-sentence-per-line yourself, but then Rewrap will keep that:

Before Rewrapped
This is a sentence.
And this is another sentence that is too long.
Short sentence.
A sentence
starting on the next line.
Followed by
one more.
This is a sentence.
And this is another sentence
that is too long.
Short sentence.
A sentence starting on the
next line.
Followed by one more.

I can easily roll that into existing settings. Also trying to detect sentence endings within lines by .'s can be fraught with false positives.

stkb avatar Nov 29 '21 07:11 stkb

If I understand correctly, yes your proposal would be helpful. Currently I need to carefully select each line a sentence is on. With your proposal, I could just select the entire paragraph, yes?

rickhg12hs avatar Nov 29 '21 12:11 rickhg12hs

Yeah, so if you had the input on the left here and just pressed alt+q while the cursor was in that paragraph, you'd get the output on the right.

Sentences

The only thing it doesn't do is "fix" the Short sentence. A sentence.... So it would be up to you to make sure that every sentence starts on a new line, but then that would be preserved.

stkb avatar Nov 29 '21 14:11 stkb

Ah, I see. It's not perfect, but it would be very helpful. It's almost muscle memory for me now to hit Enter after finishing a sentence. Rewrapping becomes the most useful during the revising stage - As you can imagine, the length of lines change a lot during insert/delete/modify editing.

rickhg12hs avatar Nov 29 '21 20:11 rickhg12hs

FYI Having all sentences reformatted (thing I said I probably wouldn't do) is looking more likely now it's also been requested in #301.

stkb avatar Dec 01 '21 18:12 stkb

I'd also like an option to rewrap not based on column width, but by punctuation such that the result is one sentence/phrase per line.

This is what we suggest for writing in markdown with Manubot:

However, "one paragraph per line" makes the git diff less precise, leading to less granular review commenting, and makes conflicts more likely. Therefore, we recommend using semantic linefeeds — newlines between sentences. We have found that "one sentence per line" is preferable to "word wrap" or "one paragraph per line".

Would be nice to have this automated. When tracking prose with git, one sentence/phrase per line creates the cleanest diffs.

dhimmel avatar Aug 18 '22 13:08 dhimmel

Semantic line-feeds reflow content so that single line-breaks follow punctuation, and double-line breaks signify paragraphs; this is also known as semantic line breaks. I wrote a plugin for Sublime Text that does this.

reagle avatar Jun 03 '24 19:06 reagle