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

How to add newlines after headings and labels. #506

Closed shypard closed 7 months ago

shypard commented 7 months ago

Hi, thanks very much for your plugin - it has helped me a lot! However, I am having still trouble configuring my settings, here my two issues:

  1. Linebreaks after headings (\section, \subsection,\chapters`, etc) and Labels {\label}
  2. Block Linebreaks when Block is starting with \textbf{}, \textit{}, \acp{}, \citeauthor{}...

Regarding Problem 2) I already added the regex code (\\textbf{)|(\\textit{) to the blocksBeginWith section, but this seems a bit tedious for such commands, is there another way?

This is the localSettings.yml file:

defaultIndent: "    "
removeTrailingWhitespace: 1
modifyLineBreaks:
  textWrapOptions:
    columns: 80
    multipleSpacesToSingle: 1
    removeBlockLineBreaks: 1
    when: after                         # before/after
    comments:
      wrap: 1                           # 0/1
      inheritLeadingSpace: 1            # 0/1
    blocksFollow:
      headings: 1                       # 0/1
      commentOnPreviousLine: 1          # 0/1
      par: 1                            # 0/1
      blankLine: 1                      # 0/1
      verbatim: 1                       # 0/1
      filecontents: 1                   # 0/1
      other: |-
          (?x)
          \\\]
          |
          \\item(?:\h|\[)
          |
          \\begin\{figure}
          |
          \\end\{figure\}
          \\begin\{table\}
          |
          \\end\{table\}
          |
          \\caption\{\h*\R*}
    indentAfterItems:
      enumerate*: 1                     # 0/1
    blocksBeginWith:
      A-Z: 1                            # 0/1
      a-z: 1                            # 0/1
      0-9: 0                            # 0/1
      other: (\\textbf{)|(\\textit{)
    blocksEndBefore:
      commentOnOwnLine: 1               # 0/1
      verbatim: 1                       # 0/1
      filecontents: 1                   # 0/1
      other: \\begin\{|\\\[|\\end\{     # regex
    huge: overflow                      # forbid mid-word line breaks
    separator: ""

Actual/given output

\section{Heading-1}\label{heading-1}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.

\acp{acr} ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

\citeauthr{author1} Excepeur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Desired or expected output

\section{Heading-1}
\label{heading-1}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.

\acp{acr} ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur.

\citeauthr{author1} Excepeur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.

Thanks & BR :)

shypard commented 7 months ago

Update: I worked around issue 1) by adding the following configuration:

...
modifyLineBreaks:
  commands:
    label:
      CommandStartsOnOwnLine: 1
...

The second issue (Block where first line starting with a command \textbf, \textit, etc does not wrap) still remains.

cmhughes commented 7 months ago

Apologies for the delay

On Mon, 8 Jan 2024, 15:30 Christian, @.***> wrote:

Update: I worked around issue 1) by adding the following configuration:

...modifyLineBreaks: commands: label: CommandStartsOnOwnLine: 1 ...

The second issue (Block where first line starting with a command \textbf, \textit, etc does not wrap) still remains.

— Reply to this email directly, view it on GitHub https://github.com/cmhughes/latexindent.pl/issues/506#issuecomment-1881232950, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ7CYCKCVD2BJYTHNNQOITYNQGIPAVCNFSM6AAAAABBOJG6I6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOBRGIZTEOJVGA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

cmhughes commented 7 months ago

If we use the settings

modifyLineBreaks:
  commands:
    label:
      CommandStartsOnOwnLine: 1
  textWrapOptions:
    columns: 60
    blocksBeginWith:
      other: |-
        (?x)
        \\acp
        |
        \\citeauth

then we receive

\section{Heading-1}
\label{heading-1}
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua.

\acp{acr} ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur.

\citeauthr{author1} Excepeur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id
est laborum.

I hope this helps, and sorry for the delay.

shypard commented 7 months ago

Alright, that works! Thanks! :)