texlive[66624] trunk: latexindent (16mar23)

commits+karl at tug.org commits+karl at tug.org
Tue Mar 21 17:50:20 CET 2023


Revision: 66624
          http://tug.org/svn/texlive?view=revision&revision=66624
Author:   karl
Date:     2023-03-21 17:50:20 +0100 (Tue, 21 Mar 2023)
Log Message:
-----------
latexindent (16mar23)

Modified Paths:
--------------
    trunk/Build/source/texk/texlive/linked_scripts/latexindent/latexindent.pl
    trunk/Master/bin/windows/latexindent.exe
    trunk/Master/texmf-dist/doc/support/latexindent/README
    trunk/Master/texmf-dist/doc/support/latexindent/latexindent-yaml-schema.json
    trunk/Master/texmf-dist/doc/support/latexindent/latexindent.pdf
    trunk/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm
    trunk/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm
    trunk/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm
    trunk/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm
    trunk/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm
    trunk/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml
    trunk/Master/texmf-dist/scripts/latexindent/latexindent.pl

Modified: trunk/Build/source/texk/texlive/linked_scripts/latexindent/latexindent.pl
===================================================================
(Binary files differ)

Modified: trunk/Master/bin/windows/latexindent.exe
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/support/latexindent/README
===================================================================
--- trunk/Master/texmf-dist/doc/support/latexindent/README	2023-03-21 16:49:52 UTC (rev 66623)
+++ trunk/Master/texmf-dist/doc/support/latexindent/README	2023-03-21 16:50:20 UTC (rev 66624)
@@ -1,5 +1,5 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-    latexindent.pl, version 3.20.3, 2023-02-19
+    latexindent.pl, version 3.20.4, 2023-03-15
 
     PERL script to indent code within environments, and align delimited 
     environments in .tex files.

Modified: trunk/Master/texmf-dist/doc/support/latexindent/latexindent-yaml-schema.json
===================================================================
--- trunk/Master/texmf-dist/doc/support/latexindent/latexindent-yaml-schema.json	2023-03-21 16:49:52 UTC (rev 66623)
+++ trunk/Master/texmf-dist/doc/support/latexindent/latexindent-yaml-schema.json	2023-03-21 16:50:20 UTC (rev 66624)
@@ -2,7 +2,7 @@
     "$schema": "http://json-schema.org/schema",
     "$id": "latexindent-yaml-schema.json",
     "title": "latexindent.pl YAML schema",
-    "description": "latexindent.pl YAML schema helper, V3.20.3 2023-02-19",
+    "description": "latexindent.pl YAML schema helper, V3.20.4 2023-03-15",
     "type": "object",
     "properties": {
       "fileExtensionPreference": {

Modified: trunk/Master/texmf-dist/doc/support/latexindent/latexindent.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm
===================================================================
--- trunk/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm	2023-03-21 16:49:52 UTC (rev 66623)
+++ trunk/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm	2023-03-21 16:50:20 UTC (rev 66624)
@@ -155,9 +155,9 @@
 
     $logger->trace("*dontMeasure routine, row mode") if ( ${$self}{dontMeasure} and $is_t_switch_active );
 
+    #
     # initial loop for column storage and measuring
-    # initial loop for column storage and measuring
-    # initial loop for column storage and measuring
+    #
     foreach ( split( "\n", ${$self}{body} ) ) {
         $rowCounter++;
 
@@ -387,9 +387,9 @@
     # main formatting loop
     $self->main_formatting;
 
+    #
     # final \\ loop
-    # final \\ loop
-    # final \\ loop
+    #
     foreach (@formattedBody) {
 
         # reset the padding
@@ -511,9 +511,9 @@
 
     ${$self}{maximumRowWidth} = 0;
 
+    #
     # objective (1): padding
-    # objective (1): padding
-    # objective (1): padding
+    #
 
     $logger->trace("*formatted rows for: ${$self}{name}") if ($is_t_switch_active);
 
@@ -536,9 +536,9 @@
             # the placement of the padding is dependent on the value of justification
             if ( ${$self}{justification} eq "left" ) {
 
+                #
                 # LEFT:
-                # LEFT:
-                # LEFT:
+                #
                 #   <cell entry> <individual padding> <group padding> ...
                 $tmpRow .= ${$cell}{entry};
                 $tmpRow .= " " x ${$cell}{individualPadding};
@@ -545,9 +545,9 @@
                 $tmpRow .= " " x ${$cell}{groupPadding};
             }
             else {
+                #
                 # RIGHT:
-                # RIGHT:
-                # RIGHT:
+                #
                 #   <group padding> <individual padding> <cell entry> ...
                 $tmpRow .= " " x ${$cell}{groupPadding};
                 $tmpRow .= " " x ${$cell}{individualPadding};
@@ -583,9 +583,9 @@
         # store this formatted row
         ${ $formattedBody[$rowCount] }{row} = $tmpRow;
 
+        #
         # objective (2): calculate row width and update maximumRowWidth
-        # objective (2): calculate row width and update maximumRowWidth
-        # objective (2): calculate row width and update maximumRowWidth
+        #
         my $rowWidth = &get_column_width($tmpRow);
 
         # possibly update rowWidth if there are hidden children; see test-cases/alignment/hidden-child1.tex and friends
@@ -784,9 +784,9 @@
     # we count the maximum number of columns
     my $maximumNumberOfColumns = 0;
 
+    #
     # maximum column width loop
-    # maximum column width loop
-    # maximum column width loop
+    #
 
     $logger->trace("*dontMeasure routine, cell mode") if ( ${$self}{dontMeasure} and $is_t_switch_active );
 
@@ -871,9 +871,9 @@
         $maximumNumberOfColumns = $j if ( $j > $maximumNumberOfColumns );
     }
 
+    #
     # individual padding and gap filling loop
-    # individual padding and gap filling loop
-    # individual padding and gap filling loop
+    #
 
     # row loop
     foreach my $row (@cellStorage) {
@@ -1100,9 +1100,9 @@
             # and groupPadding accordingly
             my $justificationOffset = ( ${$self}{justification} eq "left" ? $j + $multiColumnSpan - 1 : $j );
 
+            #
             # phase (1)
-            # phase (1)
-            # phase (1)
+            #
 
             # *inner* row loop
             my $innerRowCount = -1;
@@ -1173,9 +1173,9 @@
 
             }
 
+            #
             # phase (2)
-            # phase (2)
-            # phase (2)
+            #
 
             # now that the maxGroupingWidth has been established, loop back
             # through and update groupingWidth for the appropriate cells
@@ -1208,9 +1208,9 @@
 
                 my $groupingWidth = ${ $cellStorage[$innerRowCount][$justificationOffset] }{groupingWidth};
 
+                #
                 # phase (3)
-                # phase (3)
-                # phase (3)
+                #
 
                 # there are two possible cases:
                 #
@@ -1457,7 +1457,20 @@
 
         # logfile information
         logName => "double-back-slash-block (for align at ampersand, see lookForAlignDelims)",
+
+        # we don't want to store these "\\" blocks as demonstrated in test-cases/alignment/issue-426.tex
+        storage => 0,
     );
+
+    # can return if no "\\" blocks were found
+    return unless defined ${$self}{children};
+
+    # now loop back through and put the "\\" blocks back in, accounting for all poly-switches
+    while ( ${ ${$self}{children}[-1] }{storage} == 0 ) {
+        my $child = ${$self}{children}[-1];
+        $self->replace_id_with_begin_body_end( $child, -1 );
+        last if scalar( @{ ${$self}{children} } ) == 0;
+    }
 }
 
 # possible hidden children, see test-cases/alignment/issue-162.tex and friends

Modified: trunk/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm
===================================================================
--- trunk/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm	2023-03-21 16:49:52 UTC (rev 66623)
+++ trunk/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm	2023-03-21 16:50:20 UTC (rev 66624)
@@ -42,7 +42,7 @@
     qw/remove_trailing_comments put_trailing_comments_back_in add_comment_symbol construct_trailing_comment_regexp/;
 use LatexIndent::HorizontalWhiteSpace qw/remove_trailing_whitespace remove_leading_space/;
 use LatexIndent::Indent
-    qw/indent wrap_up_statement determine_total_indentation indent_begin indent_body indent_end_statement final_indentation_check  get_surrounding_indentation indent_children_recursively check_for_blank_lines_at_beginning put_blank_lines_back_in_at_beginning add_surrounding_indentation_to_begin_statement post_indentation_check/;
+    qw/indent wrap_up_statement determine_total_indentation indent_begin indent_body indent_end_statement final_indentation_check  get_surrounding_indentation indent_children_recursively check_for_blank_lines_at_beginning put_blank_lines_back_in_at_beginning add_surrounding_indentation_to_begin_statement post_indentation_check replace_id_with_begin_body_end/;
 use LatexIndent::Tokens qw/token_check %tokens/;
 use LatexIndent::HiddenChildren
     qw/find_surrounding_indentation_for_children update_family_tree get_family_tree check_for_hidden_children hidden_children_preparation_for_alignment unpack_children_into_body/;

Modified: trunk/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm
===================================================================
--- trunk/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm	2023-03-21 16:49:52 UTC (rev 66623)
+++ trunk/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm	2023-03-21 16:50:20 UTC (rev 66624)
@@ -79,6 +79,7 @@
                                             # to detail for double back slash poly-switches 
                                             # (see test-cases alignment command-align.tex, for example)
                                             parent=>(${$self}{parent}?${$self}{parent}:"none"),
+                                            storage=>(defined $input{storage} ? $input{storage} : 1),
                                           );
 
                           # log file output
@@ -108,6 +109,9 @@
 sub tasks_particular_to_each_object {
     my $self = shift;
 
+    # some Else blocks shouldn't be stored (especially "\\" blocks), see test-cases/alignment/issue-426.tex
+    return if ${$self}{storage} == 0;
+
     # search for headings (important to do this before looking for commands!)
     $self->find_heading if ${$self}{body} =~ m/$allHeadingsRegexp/s;
 

Modified: trunk/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm
===================================================================
--- trunk/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm	2023-03-21 16:49:52 UTC (rev 66623)
+++ trunk/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm	2023-03-21 16:50:20 UTC (rev 66624)
@@ -26,7 +26,7 @@
 use Data::Dumper;
 use Exporter qw/import/;
 our @EXPORT_OK
-    = qw/indent wrap_up_statement determine_total_indentation indent_begin indent_body indent_end_statement final_indentation_check push_family_tree_to_indent get_surrounding_indentation indent_children_recursively check_for_blank_lines_at_beginning put_blank_lines_back_in_at_beginning add_surrounding_indentation_to_begin_statement post_indentation_check/;
+    = qw/indent wrap_up_statement determine_total_indentation indent_begin indent_body indent_end_statement final_indentation_check push_family_tree_to_indent get_surrounding_indentation indent_children_recursively check_for_blank_lines_at_beginning put_blank_lines_back_in_at_beginning add_surrounding_indentation_to_begin_statement post_indentation_check replace_id_with_begin_body_end/;
 our %familyTree;
 
 sub indent {
@@ -311,170 +311,181 @@
         # we work through the array *in order*
         foreach my $child ( @{ ${$self}{children} } ) {
             $logger->trace("Searching ${$self}{name} for ${$child}{id}...") if $is_t_switch_active;
-            if ( ${$self}{body} =~ m/${$child}{idRegExp}/s ) {
 
-                # we only care if id is first non-white space character
-                # and if followed by line break
-                # if m switch is active
-                my $IDFirstNonWhiteSpaceCharacter    = 0;
-                my $IDFollowedImmediatelyByLineBreak = 0;
+            my $restartLoop = $self->replace_id_with_begin_body_end( $child, $index );
+            last if $restartLoop;
 
-                # update the above two, if necessary
-                if ($is_m_switch_active) {
-                    $IDFirstNonWhiteSpaceCharacter = (
-                               ${$self}{body} =~ m/^${$child}{idRegExp}/m
-                            or ${$self}{body} =~ m/^\h\h*${$child}{idRegExp}/m
-                    ) ? 1 : 0;
-                    $IDFollowedImmediatelyByLineBreak = ( ${$self}{body} =~ m/${$child}{idRegExp}\h*\R+/m ) ? 1 : 0;
-                    ${$child}{IDFollowedImmediatelyByLineBreak} = $IDFollowedImmediatelyByLineBreak;
-                }
+            # increment the loop counter
+            $index++;
+        }
+    }
 
-                # log file info
-                $logger->trace("${$child}{id} found!")                              if ($is_t_switch_active);
-                $logger->trace("*Indenting  ${$child}{name} (id: ${$child}{id})")   if $is_t_switch_active;
-                $logger->trace("looking up indentation scheme for ${$child}{name}") if ($is_t_switch_active);
+    # logfile info
+    $logger->trace("${$self}{name} has this many children:") if $is_tt_switch_active;
+    $logger->trace( scalar @{ ${$self}{children} } )         if $is_tt_switch_active;
+    $logger->trace("Post-processed body (${$self}{name}):")  if ($is_tt_switch_active);
+    $logger->trace( ${$self}{body} )                         if ($is_tt_switch_active);
 
-                # line break checks *after* <end statement>
-                if (    defined ${$child}{EndFinishesWithLineBreak}
-                    and ${$child}{EndFinishesWithLineBreak} == -1
-                    and $IDFollowedImmediatelyByLineBreak )
-                {
-                    # remove line break *after* <end statement>, if appropriate
-                    my $EndStringLogFile = ${$child}{aliases}{EndFinishesWithLineBreak} || "EndFinishesWithLineBreak";
-                    $logger->trace("Removing linebreak after ${$child}{end} (see $EndStringLogFile)")
-                        if $is_t_switch_active;
-                    ${$self}{body} =~ s/${$child}{idRegExp}(\h*)?(\R|\h)*/${$child}{id}$1/s;
-                    ${$child}{linebreaksAtEnd}{end} = 0;
-                }
+}
 
-                # perform indentation
-                $child->indent;
+sub replace_id_with_begin_body_end {
 
-                # surrounding indentation is now up to date
-                my $surroundingIndentation
-                    = ( ${$child}{surroundingIndentation} and ${$child}{hiddenChildYesNo} )
-                    ? (
-                    ref( ${$child}{surroundingIndentation} ) eq 'SCALAR'
-                    ? ${ ${$child}{surroundingIndentation} }
-                    : ${$child}{surroundingIndentation}
-                    )
-                    : q();
+    my $self = shift;
+    my ( $child, $index ) = (@_);
 
-                # line break checks before <begin statement>
-                if ( defined ${$child}{BeginStartsOnOwnLine} and ${$child}{BeginStartsOnOwnLine} != 0 ) {
-                    my $BeginStringLogFile = ${$child}{aliases}{BeginStartsOnOwnLine} || "BeginStartsOnOwnLine";
+    if ( ${$self}{body} =~ m/${$child}{idRegExp}/s ) {
 
-                    #
-                    # Blank line poly-switch notes (==4)
-                    #
-                    # when BeginStartsOnOwnLine=4 we adopt the following approach:
-                    #   temporarily change BeginStartsOnOwnLine to -1, make adjustments
-                    #   temporarily change BeginStartsOnOwnLine to 3, make adjustments
-                    #
-                    # we use an array, @polySwitchValues to facilitate this
-                    my @polySwitchValues
-                        = ( ${$child}{BeginStartsOnOwnLine} == 4 ) ? ( -1, 3 ) : ( ${$child}{BeginStartsOnOwnLine} );
+        # we only care if id is first non-white space character
+        # and if followed by line break
+        # if m switch is active
+        my $IDFirstNonWhiteSpaceCharacter    = 0;
+        my $IDFollowedImmediatelyByLineBreak = 0;
 
-                    foreach (@polySwitchValues) {
+        # update the above two, if necessary
+        if ($is_m_switch_active) {
+            $IDFirstNonWhiteSpaceCharacter = (
+                       ${$self}{body} =~ m/^${$child}{idRegExp}/m
+                    or ${$self}{body} =~ m/^\h\h*${$child}{idRegExp}/m
+            ) ? 1 : 0;
+            $IDFollowedImmediatelyByLineBreak = ( ${$self}{body} =~ m/${$child}{idRegExp}\h*\R+/m ) ? 1 : 0;
+            ${$child}{IDFollowedImmediatelyByLineBreak} = $IDFollowedImmediatelyByLineBreak;
+        }
 
-                        # if BeginStartsOnOwnLine is 4, then we hack
-                        #       $IDFirstNonWhiteSpaceCharacter
-                        # to be 0 on the second time through (poly-switch set to 3)
-                        $IDFirstNonWhiteSpaceCharacter = 0 if ( ${$child}{BeginStartsOnOwnLine} == 4 and $_ == 3 );
+        # log file info
+        $logger->trace("${$child}{id} found!")                              if ($is_t_switch_active);
+        $logger->trace("*Indenting  ${$child}{name} (id: ${$child}{id})")   if $is_t_switch_active;
+        $logger->trace("looking up indentation scheme for ${$child}{name}") if ($is_t_switch_active);
 
-                        # if the child ID is not the first character and BeginStartsOnOwnLine>=1
-                        # then we will need to add a line break (==1), a comment (==2) or another blank line (==3)
-                        if ( $_ >= 1 and !$IDFirstNonWhiteSpaceCharacter ) {
+        # line break checks *after* <end statement>
+        if (    defined ${$child}{EndFinishesWithLineBreak}
+            and ${$child}{EndFinishesWithLineBreak} == -1
+            and $IDFollowedImmediatelyByLineBreak )
+        {
+            # remove line break *after* <end statement>, if appropriate
+            my $EndStringLogFile = ${$child}{aliases}{EndFinishesWithLineBreak} || "EndFinishesWithLineBreak";
+            $logger->trace("Removing linebreak after ${$child}{end} (see $EndStringLogFile)")
+                if $is_t_switch_active;
+            ${$self}{body} =~ s/${$child}{idRegExp}(\h*)?(\R|\h)*/${$child}{id}$1/s;
+            ${$child}{linebreaksAtEnd}{end} = 0;
+        }
 
-                            # by default, assume that no trailing comment token is needed
-                            my $trailingCharacterToken = q();
-                            if ( $_ == 2 ) {
-                                $logger->trace(
-                                    "Removing space immediately before ${$child}{id}, in preparation for adding % ($BeginStringLogFile == 2)"
-                                ) if $is_t_switch_active;
-                                ${$self}{body} =~ s/\h*${$child}{idRegExp}/${$child}{id}/s;
-                                $logger->trace(
-                                    "Adding a % at the end of the line that ${$child}{begin} is on, then a linebreak ($BeginStringLogFile == 2)"
-                                ) if $is_t_switch_active;
-                                $trailingCharacterToken = "%" . $self->add_comment_symbol;
-                            }
-                            elsif ( $_ == 3 ) {
-                                $logger->trace(
-                                    "Adding a blank line at the end of the line that ${$child}{begin} is on, then a linebreak ($BeginStringLogFile == 3)"
-                                ) if $is_t_switch_active;
-                                $trailingCharacterToken = "\n"
-                                    . (
-                                    ${ $mainSettings{modifyLineBreaks} }{preserveBlankLines}
-                                    ? $tokens{blanklines}
-                                    : q()
-                                    );
-                            }
-                            else {
-                                $logger->trace(
-                                    "Adding a linebreak at the beginning of ${$child}{begin} (see $BeginStringLogFile)")
-                                    if $is_t_switch_active;
-                            }
+        # perform indentation
+        $child->indent;
 
-                            # the trailing comment/linebreak magic
-                            ${$child}{begin} = "$trailingCharacterToken\n" . ${$child}{begin};
-                            $child->add_surrounding_indentation_to_begin_statement;
+        # surrounding indentation is now up to date
+        my $surroundingIndentation
+            = ( ${$child}{surroundingIndentation} and ${$child}{hiddenChildYesNo} )
+            ? (
+            ref( ${$child}{surroundingIndentation} ) eq 'SCALAR'
+            ? ${ ${$child}{surroundingIndentation} }
+            : ${$child}{surroundingIndentation}
+            )
+            : q();
 
-                            # remove surrounding indentation ahead of %
-                            ${$child}{begin} =~ s/^(\h*)%/%/ if ( $_ == 2 );
-                        }
-                        elsif ( $_ == -1 and $IDFirstNonWhiteSpaceCharacter ) {
+        # line break checks before <begin statement>
+        if ( defined ${$child}{BeginStartsOnOwnLine} and ${$child}{BeginStartsOnOwnLine} != 0 ) {
+            my $BeginStringLogFile = ${$child}{aliases}{BeginStartsOnOwnLine} || "BeginStartsOnOwnLine";
 
-                            # finally, if BeginStartsOnOwnLine == -1 then we might need to *remove* a blank line(s)
-                            # important to check we don't move the begin statement next to a blank-line-token
-                            my $blankLineToken = $tokens{blanklines};
-                            if ( ${$self}{body} !~ m/$blankLineToken\R*\h*${$child}{idRegExp}/s ) {
-                                $logger->trace(
-                                    "Removing linebreak before ${$child}{begin} (see $BeginStringLogFile in ${$child}{modifyLineBreaksYamlName} YAML)"
-                                ) if $is_t_switch_active;
-                                ${$self}{body} =~ s/(\h*)(?:\R*|\h*)+${$child}{idRegExp}/$1${$child}{id}/s;
-                            }
-                            else {
-                                $logger->trace(
-                                    "Not removing linebreak ahead of ${$child}{begin}, as blank-line-token present (see preserveBlankLines)"
-                                ) if $is_t_switch_active;
-                            }
-                        }
+            #
+            # Blank line poly-switch notes (==4)
+            #
+            # when BeginStartsOnOwnLine=4 we adopt the following approach:
+            #   temporarily change BeginStartsOnOwnLine to -1, make adjustments
+            #   temporarily change BeginStartsOnOwnLine to 3, make adjustments
+            #
+            # we use an array, @polySwitchValues to facilitate this
+            my @polySwitchValues
+                = ( ${$child}{BeginStartsOnOwnLine} == 4 ) ? ( -1, 3 ) : ( ${$child}{BeginStartsOnOwnLine} );
+
+            foreach (@polySwitchValues) {
+
+                # if BeginStartsOnOwnLine is 4, then we hack
+                #       $IDFirstNonWhiteSpaceCharacter
+                # to be 0 on the second time through (poly-switch set to 3)
+                $IDFirstNonWhiteSpaceCharacter = 0 if ( ${$child}{BeginStartsOnOwnLine} == 4 and $_ == 3 );
+
+                # if the child ID is not the first character and BeginStartsOnOwnLine>=1
+                # then we will need to add a line break (==1), a comment (==2) or another blank line (==3)
+                if ( $_ >= 1 and !$IDFirstNonWhiteSpaceCharacter ) {
+
+                    # by default, assume that no trailing comment token is needed
+                    my $trailingCharacterToken = q();
+                    if ( $_ == 2 ) {
+                        $logger->trace(
+                            "Removing space immediately before ${$child}{id}, in preparation for adding % ($BeginStringLogFile == 2)"
+                        ) if $is_t_switch_active;
+                        ${$self}{body} =~ s/\h*${$child}{idRegExp}/${$child}{id}/s;
+                        $logger->trace(
+                            "Adding a % at the end of the line that ${$child}{begin} is on, then a linebreak ($BeginStringLogFile == 2)"
+                        ) if $is_t_switch_active;
+                        $trailingCharacterToken = "%" . $self->add_comment_symbol;
                     }
+                    elsif ( $_ == 3 ) {
+                        $logger->trace(
+                            "Adding a blank line at the end of the line that ${$child}{begin} is on, then a linebreak ($BeginStringLogFile == 3)"
+                        ) if $is_t_switch_active;
+                        $trailingCharacterToken = "\n"
+                            . (
+                            ${ $mainSettings{modifyLineBreaks} }{preserveBlankLines}
+                            ? $tokens{blanklines}
+                            : q()
+                            );
+                    }
+                    else {
+                        $logger->trace(
+                            "Adding a linebreak at the beginning of ${$child}{begin} (see $BeginStringLogFile)")
+                            if $is_t_switch_active;
+                    }
+
+                    # the trailing comment/linebreak magic
+                    ${$child}{begin} = "$trailingCharacterToken\n" . ${$child}{begin};
+                    $child->add_surrounding_indentation_to_begin_statement;
+
+                    # remove surrounding indentation ahead of %
+                    ${$child}{begin} =~ s/^(\h*)%/%/ if ( $_ == 2 );
                 }
+                elsif ( $_ == -1 and $IDFirstNonWhiteSpaceCharacter ) {
 
-                $logger->trace( Dumper( \%{$child} ) ) if ($is_tt_switch_active);
+                    # finally, if BeginStartsOnOwnLine == -1 then we might need to *remove* a blank line(s)
+                    # important to check we don't move the begin statement next to a blank-line-token
+                    my $blankLineToken = $tokens{blanklines};
+                    if ( ${$self}{body} !~ m/$blankLineToken\R*\h*${$child}{idRegExp}/s ) {
+                        $logger->trace(
+                            "Removing linebreak before ${$child}{begin} (see $BeginStringLogFile in ${$child}{modifyLineBreaksYamlName} YAML)"
+                        ) if $is_t_switch_active;
+                        ${$self}{body} =~ s/(\h*)(?:\R*|\h*)+${$child}{idRegExp}/$1${$child}{id}/s;
+                    }
+                    else {
+                        $logger->trace(
+                            "Not removing linebreak ahead of ${$child}{begin}, as blank-line-token present (see preserveBlankLines)"
+                        ) if $is_t_switch_active;
+                    }
+                }
+            }
+        }
 
-                # replace ids with body
-                ${$self}{body} =~ s/${$child}{idRegExp}/${$child}{begin}${$child}{body}${$child}{end}/;
+        $logger->trace( Dumper( \%{$child} ) ) if ($is_tt_switch_active);
 
-                # log file info
-                $logger->trace("Body (${$self}{name}) now looks like:") if $is_tt_switch_active;
-                $logger->trace( ${$self}{body} ) if ($is_tt_switch_active);
+        # replace ids with body
+        ${$self}{body} =~ s/${$child}{idRegExp}/${$child}{begin}${$child}{body}${$child}{end}/;
 
+        # log file info
+        $logger->trace("Body (${$self}{name}) now looks like:") if $is_tt_switch_active;
+        $logger->trace( ${$self}{body} ) if ($is_tt_switch_active);
+
 # remove element from array: http://stackoverflow.com/questions/174292/what-is-the-best-way-to-delete-a-value-from-an-array-in-perl
-                splice( @{ ${$self}{children} }, $index, 1 );
+        splice( @{ ${$self}{children} }, $index, 1 );
 
-                # output to the log file
-                $logger->trace("deleted child key ${$child}{name} (parent is: ${$self}{name})") if $is_t_switch_active;
+        # output to the log file
+        $logger->trace("deleted child key ${$child}{name} (parent is: ${$self}{name})") if $is_t_switch_active;
 
-                # restart the loop, as the size of the array has changed
-                last;
-            }
-            else {
-                $logger->trace("${$child}{id} not found") if ($is_t_switch_active);
-            }
-
-            # increment the loop counter
-            $index++;
-        }
+        # restart the loop, as the size of the array has changed
+        return 1;
     }
-
-    # logfile info
-    $logger->trace("${$self}{name} has this many children:") if $is_tt_switch_active;
-    $logger->trace( scalar @{ ${$self}{children} } )         if $is_tt_switch_active;
-    $logger->trace("Post-processed body (${$self}{name}):")  if ($is_tt_switch_active);
-    $logger->trace( ${$self}{body} )                         if ($is_tt_switch_active);
-
+    else {
+        $logger->trace("${$child}{id} not found") if ($is_t_switch_active);
+        return 0;
+    }
 }
 
 sub add_surrounding_indentation_to_begin_statement {

Modified: trunk/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm
===================================================================
--- trunk/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm	2023-03-21 16:49:52 UTC (rev 66623)
+++ trunk/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm	2023-03-21 16:50:20 UTC (rev 66624)
@@ -20,6 +20,6 @@
 use Exporter qw/import/;
 our @EXPORT_OK = qw/$versionNumber $versionDate/;
 
-our $versionNumber = '3.20.3';
-our $versionDate   = '2023-02-19';
+our $versionNumber = '3.20.4';
+our $versionDate   = '2023-03-15';
 1

Modified: trunk/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml
===================================================================
--- trunk/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml	2023-03-21 16:49:52 UTC (rev 66623)
+++ trunk/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml	2023-03-21 16:50:20 UTC (rev 66624)
@@ -1,5 +1,5 @@
 #
-# latexindent.pl, version 3.20.3, 2023-02-19
+# latexindent.pl, version 3.20.4, 2023-03-15
 #
 # defaultSettings.yaml, the default settings for latexindent.pl
 # 

Modified: trunk/Master/texmf-dist/scripts/latexindent/latexindent.pl
===================================================================
(Binary files differ)



More information about the tex-live-commits mailing list.