cmhughes / latexindent.pl

Perl script to add indentation (leading horizontal space) to LaTeX files. It can modify line breaks before, during and after code blocks; it can perform text wrapping and paragraph line break removal. It can also perform string-based and regex-based substitutions/replacements. The script is customisable through its YAML interface.
GNU General Public License v3.0
884 stars 84 forks source link

Compressing multiple blank spaces between words into one #336

Closed musm closed 2 years ago

musm commented 2 years ago

Is there a simple yaml setting I could turn on to compress spaces between words, such that

hello     world, my      name is    Joe

to

hello world, my name is Joe
cmhughes commented 2 years ago

Yes, absolutely!

Try the following

replacements:
  -
    substitution: s/([a-zA-Z0-9.}{])\h{2,}([a-zA-Z0-9.}{])/$1 $2/sg
    when: before
  -
    substitution: s/([a-zA-Z0-9.()}{])\h{2,}([a-zA-Z0-9.()}{]|(?:\\(?!\\)))/$1 $2/sg
    when: after

You'll need to use one of the replacement switches, for example

latexindent.pl - rv myfile.tex 
musm commented 2 years ago

Thank you @cmhughes, my regex attempts to get this to work weren't successful.

I frequently type in extraneous additional whitespaces. I wonder if something like this shouldn't just be an option, but perhaps more effort than it's worth?

musm commented 2 years ago

The substitution for the before case makes sense. What is the substitution handling for the after case?

cmhughes commented 2 years ago

The second one can be helpful if text wrapping is active.

On Sat, 5 Feb 2022, 05:25 Mustafa M, @.***> wrote:

The substitution for the before case makes sense. What is the substitution handling for the after case?

— Reply to this email directly, view it on GitHub https://github.com/cmhughes/latexindent.pl/issues/336#issuecomment-1030530631, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ7CYFROGKLX67MFWMA463UZSYDLANCNFSM5NSZFWRQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>