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

Funny latexindent behavior (results are not stable) #341

Closed sjaeckel closed 2 years ago

sjaeckel commented 2 years ago

First I wanted to say thanks for creating&maintaining such a nice and useful tool!

Environment

original .tex code: https://github.com/libtom/libtommath/blob/funny-latexindent/doc/bn.tex

yaml settings: https://github.com/libtom/libtommath/blob/funny-latexindent/doc/.latexindent.yaml

invocation: https://github.com/libtom/libtommath/blob/funny-latexindent/doc/makefile#L47

$ latexindent --version
3.13.4, 2021-12-2

[Edit:] FTR I've also tried the latest version from main which has the same behavior

Funny things 1

When formatting those sources with this yaml file the result is not stable :)

$ git clone https://github.com/libtom/libtommath -b funny-latexindent
$ cd libtommath/doc
$ for n in {1..10}; do make pretty && PAGER= git diff --shortstat && git add bn.tex ; done
latexindent -s -w -m -l=.latexindent.yaml bn.tex
 1 file changed, 485 insertions(+), 387 deletions(-)
latexindent -s -w -m -l=.latexindent.yaml bn.tex
 1 file changed, 19 insertions(+), 18 deletions(-)
latexindent -s -w -m -l=.latexindent.yaml bn.tex
 1 file changed, 16 insertions(+), 15 deletions(-)
latexindent -s -w -m -l=.latexindent.yaml bn.tex
 1 file changed, 17 insertions(+), 17 deletions(-)
latexindent -s -w -m -l=.latexindent.yaml bn.tex
 1 file changed, 19 insertions(+), 20 deletions(-)
latexindent -s -w -m -l=.latexindent.yaml bn.tex
 1 file changed, 9 insertions(+), 9 deletions(-)
latexindent -s -w -m -l=.latexindent.yaml bn.tex
 1 file changed, 11 insertions(+), 10 deletions(-)
latexindent -s -w -m -l=.latexindent.yaml bn.tex
 1 file changed, 12 insertions(+), 12 deletions(-)
latexindent -s -w -m -l=.latexindent.yaml bn.tex
 1 file changed, 13 insertions(+), 12 deletions(-)
latexindent -s -w -m -l=.latexindent.yaml bn.tex
 1 file changed, 12 insertions(+), 12 deletions(-)

I started off by calling latexindent twice as can be seen in the commented-out part of the makefile. Then I found #103 which seemed pretty similar to what I wanted to achieve. Now I'm in this state and I guessed you could be interested in this case :)

Funny things 2

Also I'm a bit suprised by the behavior how some things are sometimes replaced.

e.g. if I change the modifyLineBreaks part of the yaml to

modifyLineBreaks:
    textWrapOptions:
        columns: 100
        all: 1

and run both commands

latexindent -s -w -m -l=.latexindent.yaml -y="modifyLineBreaks: removeParagraphLineBreaks: all: 1" bn.tex
latexindent -s -w -m -l=.latexindent.yaml bn.tex

the first change in the file is

@@ -104,3 +104,3 @@ LibTomMath is meant to be very ``GCC friendly'' as it comes with a makefile well
 However, the library will also build in MSVC, Borland C out of the box.  For any other ISO C
-compiler a makefile will have to be made by the end developer.  Please consider to commit such a
+compiler a makefile will have to be made by the end developer.   Please consider to commit such a
 makefile to the LibTomMath developers, currently residing at

i.e. replacing "two spaces" by "a tab plus two spaces". If I run the both commands once more it's "a tab plus four spaces" ... and so on

Questions

Maybe I'm doing something wrong or not as intended? or did I stumble over some bug(s)?

I'd simply like to use your tool to format said tex file and have a consistent style :)

Thanks already in advance for your time and help!

cmhughes commented 2 years ago

Thanks for this.

It would help me a lot if you can use the issue template to provide a small, minimal example that I can look at.

The fewer the number of files, the easier it is.

On Wed, 16 Feb 2022, 13:42 Steffen Jaeckel, @.***> wrote:

First I wanted to say thanks creating&maintaining such a nice and useful tool! Environment

original .tex code: https://github.com/libtom/libtommath/blob/funny-latexindent/doc/bn.tex

yaml settings: https://github.com/libtom/libtommath/blob/funny-latexindent/doc/.latexindent.yaml

invocation: https://github.com/libtom/libtommath/blob/funny-latexindent/doc/makefile#L47

$ latexindent --version 3.13.4, 2021-12-2

Funny things 1

When formatting those sources with this yaml file the result is not stable :)

$ git clone https://github.com/libtom/libtommath -b funny-latexindent $ cd libtommath/doc $ for n in {1..10}; do make pretty && PAGER= git diff --shortstat && git add bn.tex ; done latexindent -s -w -m -l=.latexindent.yaml bn.tex 1 file changed, 485 insertions(+), 387 deletions(-) latexindent -s -w -m -l=.latexindent.yaml bn.tex 1 file changed, 19 insertions(+), 18 deletions(-) latexindent -s -w -m -l=.latexindent.yaml bn.tex 1 file changed, 16 insertions(+), 15 deletions(-) latexindent -s -w -m -l=.latexindent.yaml bn.tex 1 file changed, 17 insertions(+), 17 deletions(-) latexindent -s -w -m -l=.latexindent.yaml bn.tex 1 file changed, 19 insertions(+), 20 deletions(-) latexindent -s -w -m -l=.latexindent.yaml bn.tex 1 file changed, 9 insertions(+), 9 deletions(-) latexindent -s -w -m -l=.latexindent.yaml bn.tex 1 file changed, 11 insertions(+), 10 deletions(-) latexindent -s -w -m -l=.latexindent.yaml bn.tex 1 file changed, 12 insertions(+), 12 deletions(-) latexindent -s -w -m -l=.latexindent.yaml bn.tex 1 file changed, 13 insertions(+), 12 deletions(-) latexindent -s -w -m -l=.latexindent.yaml bn.tex 1 file changed, 12 insertions(+), 12 deletions(-)

I started off by calling latexindent twice as can be seen in the commented-out part of the makefile. Then I found #103 https://github.com/cmhughes/latexindent.pl/issues/103 which seemed pretty similar to what I wanted to achieve. Now I'm in this state and I guessed you could be interested in this case :) Funny things 2

Also I'm a bit suprised by the behavior how some things are sometimes replaced.

e.g. if I change the modifyLineBreaks part of the yaml to

modifyLineBreaks: textWrapOptions: columns: 100 all: 1

and run both commands

latexindent -s -w -m -l=.latexindent.yaml -y="modifyLineBreaks: removeParagraphLineBreaks: all: 1" bn.tex latexindent -s -w -m -l=.latexindent.yaml bn.tex

the first change in the file is

@@ -104,3 +104,3 @@ LibTomMath is meant to be very ``GCC friendly'' as it comes with a makefile well However, the library will also build in MSVC, Borland C out of the box. For any other ISO C -compiler a makefile will have to be made by the end developer. Please consider to commit such a +compiler a makefile will have to be made by the end developer. Please consider to commit such a makefile to the LibTomMath developers, currently residing at

i.e. replacing "two spaces" by "a tab plus two spaces". If I run the both commands once more it's "a tab plus four spaces" ... and so on Questions

Maybe I'm doing something wrong or not as intended? or did I stumble over some bug(s)?

I'd simply like to use your tool to format said tex file and have a consistent style :)

Thanks already in advance for your time and help!

— Reply to this email directly, view it on GitHub https://github.com/cmhughes/latexindent.pl/issues/341, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ7CYFWXJSNGRERAI3FWDLU3OSTRANCNFSM5ORUVHLQ . 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 are subscribed to this thread.Message ID: @.***>

sjaeckel commented 2 years ago

OK, "Funny things 2" can be reproduced via

test.tex:

However, the library will also build in MSVC, Borland C out of the box.  For any other ISO C
compiler a makefile will have to be made by the end developer.  Please consider to commit such a

.latexindent.yaml:

# 2 spaces
defaultIndent: "  "
# verbatim environments- environments specified 
# in this hash table will not be changed at all!
verbatimEnvironments:
    verbatim: 1
    alltt: 1
# verbatim commands such as \verb! body !, \lstinline$something else$
verbatimCommands:
    verb: 1

#  no indent blocks (not necessarily verbatim 
#  environments) which are marked as %\begin{noindent}
#  or anything else that the user puts in this hash
#  table
noIndentBlock:
    noindent: 1

# remove trailing whitespace from all lines 
removeTrailingWhitespace:
    beforeProcessing: 0
    afterProcessing: 1

indentAfterItems:
    itemize: 1
    enumerate: 1
    description: 1
    list: 1

onlyOneBackUp: 1

modifyLineBreaks:
    textWrapOptions:
        columns: 100
        all: 1

and running

latexindent -s -w -m -l=.latexindent.yaml -y="modifyLineBreaks: removeParagraphLineBreaks: all: 1" test.tex
latexindent -s -w -m -l=.latexindent.yaml test.tex
cmhughes commented 2 years ago

OK, great, many thanks.

Development and testing is very slow at the moment. I'm pretty confident this will be the text wrapping routine causing the issue. Remove it and see if you still get the results.

I'm getting close to removing text wrapping as it causes too many problems.

cmhughes commented 2 years ago

Can you try the beforetextwrap switch demonstrated in https://latexindentpl.readthedocs.io/en/latest/sec-the-m-switch.html#lst-textwrap12-yaml

sjaeckel commented 2 years ago

Can you try the beforetextwrap switch demonstrated in https://latexindentpl.readthedocs.io/en/latest/sec-the-m-switch.html#lst-textwrap12-yaml

The behavior doesn't change when I add this to the modifyLineBreaks part

    removeParagraphLineBreaks:
        all: 1
        beforeTextWrap: 1

I'm getting close to removing text wrapping as it causes too many problems.

Isn't the text wrapping one of the most important features?

cmhughes commented 2 years ago

Depends on your point of view.

The primary focus of the project is indentation.

Text wrapping was a feature request, and it has caused nothing but problems ever since.

On Wed, 16 Feb 2022, 16:56 Steffen Jaeckel, @.***> wrote:

Can you try the beforetextwrap switch demonstrated in https://latexindentpl.readthedocs.io/en/latest/sec-the-m-switch.html#lst-textwrap12-yaml

The behavior doesn't change when I add this to the modifyLineBreaks part

removeParagraphLineBreaks:
    all: 1
    beforeTextWrap: 1

I'm getting close to removing text wrapping as it causes too many problems.

Isn't the text wrapping one of the most important features?

— Reply to this email directly, view it on GitHub https://github.com/cmhughes/latexindent.pl/issues/341#issuecomment-1041876066, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ7CYDWPVDURZEJZRDBYZTU3PJKHANCNFSM5ORUVHLQ . 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 commented.Message ID: @.***>

cmhughes commented 2 years ago

Apologies for the delay. You'll see that in https://github.com/cmhughes/latexindent.pl/issues/346 I'm hoping to overhaul the textWrap routine, and your issue will be one of the many tests that I include within it. I'm unsure as to the time frame, development is slow at the moment. My apologies.

cmhughes commented 2 years ago

As of https://github.com/cmhughes/latexindent.pl/issues/346 I have overhauled the text wrap part of latexindent.pl.

start file

However, the library will also build in MSVC, Borland C out of the box.  For any other ISO C
compiler a makefile will have to be made by the end developer.  Please consider to commit such a

settings

modifyLineBreaks:
    textWrapOptions:
        columns: 100

output

However, the library will also build in MSVC, Borland C out of the box. For any other ISO C
compiler a makefile will have to be made by the end developer. Please consider to commit such a

I'll get V3.16 released soon.