diff options
author | Karl Berry <karl@freefriends.org> | 2023-03-21 16:50:20 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2023-03-21 16:50:20 +0000 |
commit | 202d3947901d95e557d9b585a5cff3b944175d70 (patch) | |
tree | 1ec060f776057502c05506394a2336693258c760 /Master | |
parent | f0a29d4961d8dd3d6dd1e3343f04055c83808134 (diff) |
latexindent (16mar23)
git-svn-id: svn://tug.org/texlive/trunk@66624 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
-rwxr-xr-x | Master/bin/windows/latexindent.exe | bin | 8703074 -> 8703363 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/support/latexindent/README | 2 | ||||
-rw-r--r-- | Master/texmf-dist/doc/support/latexindent/latexindent-yaml-schema.json | 2 | ||||
-rw-r--r-- | Master/texmf-dist/doc/support/latexindent/latexindent.pdf | bin | 1242139 -> 1243932 bytes | |||
-rw-r--r-- | Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm | 57 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm | 2 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm | 4 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm | 315 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm | 4 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/latexindent/defaultSettings.yaml | 2 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/latexindent/latexindent.pl | 2 |
11 files changed, 209 insertions, 181 deletions
diff --git a/Master/bin/windows/latexindent.exe b/Master/bin/windows/latexindent.exe Binary files differindex 592b864ba7c..69734d58d12 100755 --- a/Master/bin/windows/latexindent.exe +++ b/Master/bin/windows/latexindent.exe diff --git a/Master/texmf-dist/doc/support/latexindent/README b/Master/texmf-dist/doc/support/latexindent/README index a4db41d8d4c..1a2f1058d3e 100644 --- a/Master/texmf-dist/doc/support/latexindent/README +++ b/Master/texmf-dist/doc/support/latexindent/README @@ -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. diff --git a/Master/texmf-dist/doc/support/latexindent/latexindent-yaml-schema.json b/Master/texmf-dist/doc/support/latexindent/latexindent-yaml-schema.json index e9c855cf4e0..3c21407f7aa 100644 --- a/Master/texmf-dist/doc/support/latexindent/latexindent-yaml-schema.json +++ b/Master/texmf-dist/doc/support/latexindent/latexindent-yaml-schema.json @@ -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": { diff --git a/Master/texmf-dist/doc/support/latexindent/latexindent.pdf b/Master/texmf-dist/doc/support/latexindent/latexindent.pdf Binary files differindex 034b04b519c..7bf086b16db 100644 --- a/Master/texmf-dist/doc/support/latexindent/latexindent.pdf +++ b/Master/texmf-dist/doc/support/latexindent/latexindent.pdf diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm index 0cdfad7dd8f..6d3b076c6b3 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm @@ -155,9 +155,9 @@ sub align_at_ampersand { $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 @@ sub align_at_ampersand { # main formatting loop $self->main_formatting; + # # final \\ loop - # final \\ loop - # final \\ loop + # foreach (@formattedBody) { # reset the padding @@ -511,9 +511,9 @@ sub main_formatting { ${$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,18 +536,18 @@ sub main_formatting { # 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}; $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 @@ sub main_formatting { # 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 @@ sub individual_padding { # 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 @@ sub individual_padding { $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 @@ sub multicolumn_padding { # 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 @@ sub multicolumn_padding { } + # # 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 @@ sub multicolumn_padding { my $groupingWidth = ${ $cellStorage[$innerRowCount][$justificationOffset] }{groupingWidth}; + # # phase (3) - # phase (3) - # phase (3) + # # there are two possible cases: # @@ -1457,7 +1457,20 @@ sub double_back_slash_else { # 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 diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm index 8982509445d..d365388679c 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm @@ -42,7 +42,7 @@ use LatexIndent::TrailingComments 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/; diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm index da6005e7a6a..62a14a677bf 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm @@ -79,6 +79,7 @@ sub check_for_else_statement { # 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 remove_line_breaks_begin { 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; diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm index 51f5906cb3b..23968069b0c 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm @@ -26,7 +26,7 @@ use Text::Tabs; 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,158 +311,9 @@ sub indent_children_recursively { # 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; - - # 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; - } - - # 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); - - # 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; - - # surrounding indentation is now up to date - my $surroundingIndentation - = ( ${$child}{surroundingIndentation} and ${$child}{hiddenChildYesNo} ) - ? ( - ref( ${$child}{surroundingIndentation} ) eq 'SCALAR' - ? ${ ${$child}{surroundingIndentation} } - : ${$child}{surroundingIndentation} - ) - : q(); - - # line break checks before <begin statement> - if ( defined ${$child}{BeginStartsOnOwnLine} and ${$child}{BeginStartsOnOwnLine} != 0 ) { - my $BeginStringLogFile = ${$child}{aliases}{BeginStartsOnOwnLine} || "BeginStartsOnOwnLine"; - - # - # 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 ) { - - # 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; - } - } - } - } - $logger->trace( Dumper( \%{$child} ) ) 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 ); - - # 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); - } + my $restartLoop = $self->replace_id_with_begin_body_end( $child, $index ); + last if $restartLoop; # increment the loop counter $index++; @@ -477,6 +328,166 @@ sub indent_children_recursively { } +sub replace_id_with_begin_body_end { + + my $self = shift; + my ( $child, $index ) = (@_); + + 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; + + # 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; + } + + # 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); + + # 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; + + # surrounding indentation is now up to date + my $surroundingIndentation + = ( ${$child}{surroundingIndentation} and ${$child}{hiddenChildYesNo} ) + ? ( + ref( ${$child}{surroundingIndentation} ) eq 'SCALAR' + ? ${ ${$child}{surroundingIndentation} } + : ${$child}{surroundingIndentation} + ) + : q(); + + # line break checks before <begin statement> + if ( defined ${$child}{BeginStartsOnOwnLine} and ${$child}{BeginStartsOnOwnLine} != 0 ) { + my $BeginStringLogFile = ${$child}{aliases}{BeginStartsOnOwnLine} || "BeginStartsOnOwnLine"; + + # + # 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 ) { + + # 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; + } + } + } + } + + $logger->trace( Dumper( \%{$child} ) ) 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 ); + + # 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 + return 1; + } + else { + $logger->trace("${$child}{id} not found") if ($is_t_switch_active); + return 0; + } +} + sub add_surrounding_indentation_to_begin_statement { # almost all of the objects add surrounding indentation to the 'begin' statements, diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm index f068880de8b..e05f59d6f98 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm @@ -20,6 +20,6 @@ use warnings; 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 diff --git a/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml b/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml index a5f45fd0804..2dc3f22667e 100755 --- a/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml +++ b/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml @@ -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 # diff --git a/Master/texmf-dist/scripts/latexindent/latexindent.pl b/Master/texmf-dist/scripts/latexindent/latexindent.pl index 32b94b3f4bc..4553e6dd7bb 100755 --- a/Master/texmf-dist/scripts/latexindent/latexindent.pl +++ b/Master/texmf-dist/scripts/latexindent/latexindent.pl @@ -1,5 +1,5 @@ #!/usr/bin/env perl -# latexindent.pl, version 3.20.3, 2023-02-19 +# latexindent.pl, version 3.20.4, 2023-03-15 # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by |