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

textWrapOptions broken? #355

Closed
tdegeus opened this issue Mar 27, 2022 · 14 comments
Closed

textWrapOptions broken? #355

tdegeus opened this issue Mar 27, 2022 · 14 comments
Labels
answered question has been answered implemented implemented tag means that either an enhancement or feature request has been implemented, or bugfix one-sentence-per-line one sentence per line; documented at https://latexindentpl.readthedocs.io/en/latest/sec-the-m-switch question user-centred question about behaviour of latexindent.pl text-wrap text wrapping; documented at https://latexindentpl.readthedocs.io/en/latest/sec-the-m-switch.html

Comments

@tdegeus
Copy link
Contributor

tdegeus commented Mar 27, 2022

Please provide the following when posting an issue:

original .tex code

This is a very long sentence that I would like to be cut at the set line width which is however currently not done. Sentences are put on different lines.

yaml settings

defaultIndent: '    '
removeTrailingWhitespace: 1

modifyLineBreaks:
  condenseMultipleBlankLinesInto: 1
  oneSentencePerLine:
    manipulateSentences: 1
    removeSentenceLineBreaks: 0
  textWrapOptions:
    columns: 100

actual/given output

This is a very long sentence that I would like to be cut at the set line width which is however currently not done.
Sentences are put on different lines.

desired or expected output

This is a very long sentence that I would like to be cut at the set line width which is however 
currently not done.
Sentences are put on different lines.

Note that this is working with latexindent.pl=3.15 but not with latexindent.pl=3.16 neither latexindent.pl=3.17

@cmhughes
Copy link
Owner

Text wrapping and oneSentencePerLine are orthogonal processes....

If you want sentences wrapped, how about https://latexindentpl.readthedocs.io/en/latest/sec-the-m-switch.html#lst-sentence-wrap1-yaml

@tdegeus
Copy link
Contributor Author

tdegeus commented Mar 28, 2022

Thanks for you response.

I don't think of them as orthogonal. Consider the following formatting rule:

  1. Every sentence starts on a new line.
  2. No line can exceed 100 characters.
  3. Only format if 1 or 2 is violated.

I don't think this can be done anymore? When I add textWrapSentences: 1 then 3 is violated. But 2 is violated if I put textWrapSentences: 0.

@cmhughes
Copy link
Owner

OK, understood. I don't have access to a computer for a few days. I'll test this when I can.

@cmhughes cmhughes mentioned this issue Mar 29, 2022
@cmhughes
Copy link
Owner

When I start with your file

This is a very long sentence that I would like to be cut at the set line width which is however currently not done.
Sentences are put on different lines.

and the yaml file (say tom.yaml)

modifyLineBreaks:
  condenseMultipleBlankLinesInto: 1
  oneSentencePerLine:
    manipulateSentences: 1
    removeSentenceLineBreaks: 1
    textWrapSentences: 1 
  textWrapOptions:
    columns: 100

and run

latexindent.pl -m -l tom.yaml myfile.tex -o myfile-mod1.tex

then I receive your desired output

This is a very long sentence that I would like to be cut at the set line width which is however
currently not done.
Sentences are put on different lines.

@cmhughes cmhughes added question user-centred question about behaviour of latexindent.pl answered question has been answered labels Mar 30, 2022
@tdegeus
Copy link
Contributor Author

tdegeus commented Mar 30, 2022

Like I tried to describe before, textWrapSentenses: 1 violates condition 3 above.

Consider

This is a very long sentence that I would like to be cut at the set line width which is however currently not done.
Sentences are put on different lines.
This is a very long sentence that is formatted like it should and it
should therefore not be touched by the formatter.

I want it to be

This is a very long sentence that I would like to be cut at the set line width which is however
currently not done.
Sentences are put on different lines.
This is a very long sentence that is formatted like it should and it
should therefore not be touched by the formatter.

but it formats to

This is a very long sentence that I would like to be cut at the set line width which is however
currently not done.
Sentences are put on different lines.
This is a very long sentence that is formatted like it should and it should therefore not be
touched by the formatter.

notice the last sentence.

I want this because:

  • I want to avoid unnecessary changes that cloud version management
  • I want to keep manual interventions that aid readability a lot

@cmhughes
Copy link
Owner

So you want to text wrap some sentences but not others? Once you detail

    textWrapSentences: 1

you are saying 'employ the text wrapping routine on all sentences'. If you don't want that to happen, then the lines switch is for you. https://latexindentpl.readthedocs.io/en/latest/sec-the-line-switch.html

@cmhughes
Copy link
Owner

Or, are you saying that you'd like

    removeSentenceLineBreaks: 0

to be employed by the sentence text wrapping routine as well? This is not currently the behaviour, but I could explore it....


For my reference, I think it would be the following line in Wrap.pm

$textWrapBlockStorageValue =~ s/\R(?!\Z)/ /sg;

and it would need a check to see if the object is a sentence and if removeSentenceLineBreaks is 1.

@cmhughes cmhughes added the text-wrap text wrapping; documented at https://latexindentpl.readthedocs.io/en/latest/sec-the-m-switch.html label Mar 30, 2022
@tdegeus
Copy link
Contributor Author

tdegeus commented Mar 31, 2022

I'm not entirely sure, but I suppose. In pseudo-algorithm what I want is:

text = enforceSentenceStartsOnNewLine(text)
text = enforceHardWrapAtWidth(text, linewidth)

@cmhughes
Copy link
Owner

Yes, this already happens :)

But, the text wrap routine removes line breaks regardless of the value of removeSentenceLineBreaks.

If I've understood this, I need to change this so that removeSentenceLineBreaks is respected by text wrap.

@cmhughes
Copy link
Owner

cmhughes commented Apr 1, 2022

As of 25bbaf1, I think that this is progressed. Here's a demo.

Starting with your text:

This is a very long sentence that I would like to be cut at the set line width which is however currently not done.
Sentences are put on different lines.
This is a very long sentence that is formatted like it should and it
should therefore not be touched by the formatter.

and using

modifyLineBreaks:
  oneSentencePerLine:
    manipulateSentences: 1
    removeSentenceLineBreaks: 0  # <!----- KEY BIT, now respected by sentence text wrap
    textWrapSentences: 1 
  textWrapOptions:
    columns: 100

gives

This is a very long sentence that I would like to be cut at the set line width which is however
currently not done.
Sentences are put on different lines.
This is a very long sentence that is formatted like it should and it
should therefore not be touched by the formatter.

Using

modifyLineBreaks:
  oneSentencePerLine:
    manipulateSentences: 1
    removeSentenceLineBreaks: 1 # <!============ different
    textWrapSentences: 1 
  textWrapOptions:
    columns: 100

gives

This is a very long sentence that I would like to be cut at the set line width which is however
currently not done.
Sentences are put on different lines.
This is a very long sentence that is formatted like it should and it should therefore not be
touched by the formatter.

What do you think?

@tdegeus
Copy link
Contributor Author

tdegeus commented Apr 4, 2022

This seems perfect!! Thanks a lot for this.

Also, the option names now seem to make a lot of sense to me

@cmhughes
Copy link
Owner

cmhughes commented Apr 4, 2022 via email

@tdegeus
Copy link
Contributor Author

tdegeus commented Apr 4, 2022

🙏

@cmhughes cmhughes added the implemented implemented tag means that either an enhancement or feature request has been implemented, or bugfix label Apr 4, 2022
@cmhughes
Copy link
Owner

cmhughes commented Apr 4, 2022

Implemented and released as of https://github.com/cmhughes/latexindent.pl/releases/tag/V3.17.1. Upload to ctan imminent :)

@cmhughes cmhughes closed this as completed Apr 4, 2022
@cmhughes cmhughes added the one-sentence-per-line one sentence per line; documented at https://latexindentpl.readthedocs.io/en/latest/sec-the-m-switch label Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered question has been answered implemented implemented tag means that either an enhancement or feature request has been implemented, or bugfix one-sentence-per-line one sentence per line; documented at https://latexindentpl.readthedocs.io/en/latest/sec-the-m-switch question user-centred question about behaviour of latexindent.pl text-wrap text wrapping; documented at https://latexindentpl.readthedocs.io/en/latest/sec-the-m-switch.html
Projects
None yet
Development

No branches or pull requests

2 participants