From 84b5e6586f4b098d4f93a04ecc3dbfaa183f9836 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 21 Mar 2020 21:20:37 +0000 Subject: latexindent (21mar20) git-svn-id: svn://tug.org/texlive/trunk@54454 c570f23f-e606-0410-a88d-b1316a301751 --- .../LatexIndent/AlignmentAtAmpersand.pm | 1401 +++++++++++++++----- .../scripts/latexindent/LatexIndent/Document.pm | 2 +- .../latexindent/LatexIndent/GetYamlSettings.pm | 4 + .../scripts/latexindent/LatexIndent/LogFile.pm | 8 +- .../scripts/latexindent/LatexIndent/Sentence.pm | 11 +- .../scripts/latexindent/LatexIndent/Version.pm | 4 +- .../scripts/latexindent/defaultSettings.yaml | 8 +- .../texmf-dist/scripts/latexindent/latexindent.pl | 2 +- 8 files changed, 1115 insertions(+), 325 deletions(-) (limited to 'Master/texmf-dist/scripts') diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm index 8b8e387d095..95f2389e806 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm @@ -20,15 +20,20 @@ use utf8; use Unicode::GCString; use Data::Dumper; use Exporter qw/import/; -use List::Util qw(max); +use List::Util qw/max min sum/; use LatexIndent::TrailingComments qw/$trailingCommentRegExp/; 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/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 -our @EXPORT_OK = qw/align_at_ampersand find_aligned_block double_back_slash_else/; +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 $alignmentBlockCounter; +our @cellStorage; # two-dimensional storage array containing the cell information +our @formattedBody; # array for the new body +our @minMultiColSpan; +our @maxColumnWidth; +our @maxDelimiterWidth; sub find_aligned_block{ my $self = shift; @@ -127,27 +132,60 @@ sub align_at_ampersand{ my $self = shift; return if(${$self}{bodyLineBreaks}==0); - # calculate the maximum number of ampersands in a row in the body my $maximumNumberOfAmpersands = 0; - foreach(split("\n",${$self}{body})){ - my $numberOfAmpersands = () = $_ =~ /(?$maximumNumberOfAmpersands); - } - # create an array of zeros - my @maximumColumnWidth = (0) x ($maximumNumberOfAmpersands+1); - my @maximumColumnWidthMC = (0) x ($maximumNumberOfAmpersands+1); + # clear the global arrays + @formattedBody = (); + @cellStorage = (); + @minMultiColSpan = (); + @maxColumnWidth = (); + @maxDelimiterWidth = (); + + # maximum column widths + my @maximumColumnWidths; - # array for the new body - my @formattedBody; + my $rowCounter = -1; + my $columnCounter = -1; - # now loop back through the body, and store the maximum column size + $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++; + + # default is to measure this row, but it can be switched off by the dont_measure routine + ${$self}{measureRow} = 1; + + # call the dont_measure routine + $self->dont_measure(mode=>"row",row=>$_) if ${$self}{dontMeasure}; + # remove \\ and anything following it - my $endPiece; + my $endPiece = q(); if($_ =~ m/(\\\\.*)/){ - $_ =~ s/(\\\\.*)//; - $endPiece = $1; + if(${$self}{alignFinalDoubleBackSlash} ){ + # for example, if we want: + # + # Name & \shortstack{Hi \\ Lo} \\