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

`modifyLineBreaks` with `when: after` and `blocksFollow.other` introduces extra indentation after `\end` #502

Closed kwshi closed 8 months ago

kwshi commented 8 months ago

Please provide the following when posting an issue:

original .tex code

\begin{myenv}
  yo it's your boy here kwshi back at it with yet another example to break latexindent
\end{myenv}
it's been a good couple months hasn't it how you been my friend i've been starting to miss you having not been on here filing issues for so long that i was so excited when latexindent started acting up again, gives me a good excuse to come chat with you

yaml settings (taken roughly from https://latexindentpl.readthedocs.io/en/latest/sec-the-m-switch.html#lst-tw-bf-myenv-yaml)

modifyLineBreaks:
  textWrapOptions:
    columns: 60
    when: "after"
    blocksFollow:
      other: |
        (?x)
        \\begin\{myenv\}
        |
        \\end\{myenv\}

actual/given output

\begin{myenv}
    yo it's your boy here kwshi back at it with yet another
    example to break latexindent
\end{myenv}
it's been a good couple months hasn't it how you
           been my friend i've been starting to miss you
           having not been on here filing issues for so
           long that i was so excited when latexindent
           started acting up again, gives me a good excuse
           to come chat with you

desired or expected output

\begin{myenv}
    yo it's your boy here kwshi back at it with yet another
    example to break latexindent
\end{myenv}
it's been a good couple months hasn't it how you been my
friend i've been starting to miss you having not been on
here filing issues for so long that i was so excited when
latexindent started acting up again, gives me a good excuse
to come chat with you

Issue doesn't occur using when: before. Curiously enough the issue with extra indentation also doesn't occur within the environment (after \begin{myenv}); it also goes away if I introduce an extra blank line after \end{myenv}, or a blank comment (which is an OK workaround).

Probably related to #450 and #412.

Also, an observation that may come in handy for troubleshooting: the extra indentation lines up exactly with where the \end{...} line ends. See this other example:

\begin{myfriendhowareyou}
    yo it's your boy here kwshi back at it with yet another
    example to break latexindent
\end{myfriendhowareyou}
it's been a good couple months
                       hasn't it how you been my friend
                       i've been starting to miss you
                       having not been on here filing
                       issues for so long that i was so
                       excited when latexindent started
                       acting up again, gives me a good
                       excuse to come chat with you

and notice how hasn't it how you ... is indented to exactly where {...areyou} ends two lines above it.

cmhughes commented 8 months ago

Apologies for the delay, I'm hoping to get to this soon

cmhughes commented 8 months ago

For my reference, start here:

https://github.com/cmhughes/latexindent.pl/blob/bef6a5181bcb0275c46f3cbc9e0e73d6f1e09623/LatexIndent/Wrap.pm#L356

cmhughes commented 8 months ago

Thanks for this.

As of https://github.com/cmhughes/latexindent.pl/commit/38cf7c307be306e355525966656ed1d33e7864ec if we start with

defaultIndent: "    "
modifyLineBreaks:
  textWrapOptions:
    columns: 60
    when: "after"
    blocksFollow:
      other: |
        (?x)
        \\begin\{myenv\}
        |
        \\end\{myenv\}

then we receive

\begin{myenv}
    yo it's your boy here kwshi back at it with yet another
    example to break latexindent
\end{myenv}
it's been a good couple months hasn't it how you been my
friend i've been starting to miss you having not been on
here filing issues for so long that i was so excited when
latexindent started acting up again, gives me a good excuse
to come chat with you
----|----|----|----|----|----|----|----|----|----|----|----|
   5   10   15   20   25   30   35   40   45   50   55   60

I'll get this released soon. Thanks again.

cmhughes commented 8 months ago

Released at https://github.com/cmhughes/latexindent.pl/releases/tag/V3.23.5, uploaded to ctan. Thanks again.