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
864 stars 84 forks source link

Add linebreak after `\par` #523

Closed reneas closed 5 months ago

reneas commented 5 months ago

As the title says I want to add an automatic linebreak after each appearance of \par. I'm sorry if im posting this here as somewhat of a question, but I couldn't find any solution in the documentation or maybe I am just not experienced enough to understand all of it...

Sample of what i want:

\chapter{One}
Some random text here.\par And some more random text after the paragraph.

should become:

\chapter{One}
    Some random text here.\par
    And some more random text after the paragraph.

The indentation after the chapter is working fine but I can't get the linebreak to work. I'm using the default yaml file with only the indentation after \chapter and \section setting added to it.

cmhughes commented 5 months ago

Thanks for this.

option 1

replacements:
  - 
   substitution: |-
     s/(\\par)(\h+)(\H)/$1\n$3/sg

and call with

latexindent.pl  -l issue-523.yaml -r issue-523.tex 

option 2

specialBeginEnd:
  par:
    begin: (?<!\\)\\p
    end: ar

modifyLineBreaks:
  specialBeginEnd:
    par: 
      SpecialEndFinishesWithLineBreak: 1

and call with

latexindent.pl -l issue-523a.yaml -m issue-523.tex 
reneas commented 5 months ago

that worked perfectly, thanks a bunch!