From ed17b4b97e16c81b6869381411a74466acc81a23 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 24 Jul 2021 20:49:14 +0000 Subject: latexindent (24jul21) git-svn-id: svn://tug.org/texlive/trunk@60045 c570f23f-e606-0410-a88d-b1316a301751 --- .../LatexIndent/AlignmentAtAmpersand.pm | 244 ++++++++++++++++++++- .../scripts/latexindent/LatexIndent/Document.pm | 26 ++- .../scripts/latexindent/LatexIndent/Else.pm | 4 + .../latexindent/LatexIndent/FileContents.pm | 5 +- .../latexindent/LatexIndent/HiddenChildren.pm | 79 ++++++- .../scripts/latexindent/LatexIndent/Indent.pm | 4 +- .../latexindent/LatexIndent/ModifyLineBreaks.pm | 13 +- .../scripts/latexindent/LatexIndent/Verbatim.pm | 59 +++-- .../scripts/latexindent/LatexIndent/Version.pm | 4 +- .../scripts/latexindent/defaultSettings.yaml | 4 +- .../texmf-dist/scripts/latexindent/latexindent.pl | 2 +- 11 files changed, 387 insertions(+), 57 deletions(-) (limited to 'Master/texmf-dist/scripts/latexindent') diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm index 45307a90b61..479fb14a469 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm @@ -26,8 +26,10 @@ use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/; use LatexIndent::GetYamlSettings qw/%masterSettings/; use LatexIndent::Tokens qw/%tokens/; use LatexIndent::LogFile qw/$logger/; +use LatexIndent::HiddenChildren qw/%familyTree/; +use LatexIndent::Verbatim qw/%verbatimStorage/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 -our @EXPORT_OK = qw/align_at_ampersand find_aligned_block double_back_slash_else main_formatting individual_padding multicolumn_padding multicolumn_pre_check multicolumn_post_check dont_measure/; +our @EXPORT_OK = qw/align_at_ampersand find_aligned_block double_back_slash_else main_formatting individual_padding multicolumn_padding multicolumn_pre_check multicolumn_post_check dont_measure hidden_child_cell_row_width hidden_child_row_width /; our $alignmentBlockCounter; our @cellStorage; # two-dimensional storage array containing the cell information our @formattedBody; # array for the new body @@ -132,6 +134,9 @@ sub align_at_ampersand{ my $self = shift; return if(${$self}{bodyLineBreaks}==0); + # some blocks may contain verbatim to be measured + ${$self}{measureVerbatim} = (${$self}{body}=~m/$tokens{verbatim}/ ? 1 : 0); + my $maximumNumberOfAmpersands = 0; # clear the global arrays @@ -278,6 +283,12 @@ sub align_at_ampersand{ delimiterLength=>0, measureThis=> ($numberOfAmpersands>0 ? ${$self}{measureRow} : 0) }); + # possible hidden children, see https://github.com/cmhughes/latexindent.pl/issues/85 + if ( (${$self}{measureHiddenChildren} or ${$self}{measureVerbatim} ) + and $column =~m/.*?$tokens{beginOfToken}/s){ + $self->hidden_child_cell_row_width($column,$rowCounter,$columnCounter); + } + # store the maximum column width $maxColumnWidth[$columnCounter] = (defined $maxColumnWidth[$columnCounter] ? @@ -424,15 +435,16 @@ sub align_at_ampersand{ # \end{align*} # # see https://github.com/cmhughes/latexindent.pl/issues/223 for example + if (!${${$self}{linebreaksAtEnd}}{begin} and ${$cellStorage[0][0]}{type} eq "X" and ${$cellStorage[0][0]}{measureThis}){ - my $partToMeasure = ${$self}{begin}; + my $lengthOfBegin = ${$self}{begin}; if( (${$self}{begin} eq '{' | ${$self}{begin} eq '[') and ${$self}{parentBegin}){ - $partToMeasure = ${$self}{parentBegin}."{"; + $lengthOfBegin = ${$self}{parentBegin}."{"; } - ${$self}{indentation} = " " x Unicode::GCString->new($partToMeasure)->columns(); + ${$self}{indentation} = " " x Unicode::GCString->new($lengthOfBegin)->columns(); $logger->trace("Adjusting indentation of ${$self}{name} in AlignAtAmpersand routine") if($is_t_switch_active); } } @@ -530,6 +542,10 @@ sub main_formatting { # objective (2): calculate row width and update maximumRowWidth # objective (2): calculate row width and update maximumRowWidth my $rowWidth = Unicode::GCString->new($tmpRow)->columns(); + + # possibly update rowWidth if there are hidden children; see test-cases/alignment/hidden-child1.tex and friends + $rowWidth = $self->hidden_child_row_width($tmpRow,$rowCount,$rowWidth) if(${$self}{measureHiddenChildren} or ${$self}{measureVerbatim}); + ${$formattedBody[$rowCount]}{rowWidth} = $rowWidth; # update the maximum row width @@ -538,6 +554,19 @@ sub main_formatting { ${$self}{maximumRowWidth} = $rowWidth; } } + + # log file information + if($is_tt_switch_active and ${$self}{measureHiddenChildren}){ + $logger->info('*FamilyTree after align for ampersand'); + $logger->trace(Dumper(\%familyTree)) if($is_tt_switch_active); + + $rowCount = -1; + # row loop + foreach my $row (@cellStorage) { + $rowCount++; + $logger->trace("row $rowCount row width: ${$formattedBody[$rowCount]}{rowWidth}"); + } + } } sub dont_measure{ @@ -1344,4 +1373,211 @@ sub double_back_slash_else{ logName=>"double-back-slash-block (for align at ampersand, see lookForAlignDelims)", ); } + +# possible hidden children, see test-cases/alignment/issue-162.tex and friends +# +# \begin{align} +# A & =\begin{array}{cc} %