summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2023-05-01 20:28:03 +0000
committerKarl Berry <karl@freefriends.org>2023-05-01 20:28:03 +0000
commit659053701931390e42db760fd7831b91ae9f4638 (patch)
tree3b23458f21f33a1a844ba003ab343998147967fb /Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm
parent7765ec96d6b06b71d36d94607dbeecd5261f2453 (diff)
latexindent (1may23)
git-svn-id: svn://tug.org/texlive/trunk@66981 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm')
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm86
1 files changed, 83 insertions, 3 deletions
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm
index 6d3b076c6b3..16603094a97 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm
@@ -132,7 +132,9 @@ sub create_unique_id {
}
sub align_at_ampersand {
- my $self = shift;
+ my $self = shift;
+ my %input = @_;
+
return if ( ${$self}{bodyLineBreaks} == 0 );
# some blocks may contain verbatim to be measured
@@ -286,10 +288,26 @@ sub align_at_ampersand {
colSpan => ".",
delimiter => "",
delimiterLength => 0,
- measureThis => ( $numberOfAmpersands > 0 ? ${$self}{measureRow} : 0 )
+ measureThis => ( $numberOfAmpersands > 0 ? ${$self}{measureRow} : 0 ),
+ DBSpadding => 0,
}
);
+ #
+ # if content is to be aligned after \\
+ # (using alignContentAfterDoubleBackSlash) then we need to
+ # adjust the width of the first cell
+ #
+ if ( defined $input{beforeDBSlengths} and $columnCounter == 0 ) {
+ my $currentRowDBSlength = ${ $input{beforeDBSlengths} }[ $rowCounter + 1 ];
+ ${ $cellStorage[$rowCounter][$columnCounter] }{width}
+ += $currentRowDBSlength + ( $input{maxDBSlength} - $currentRowDBSlength );
+
+ ${ $cellStorage[$rowCounter][$columnCounter] }{DBSpadding}
+ = ( $input{maxDBSlength} - $currentRowDBSlength );
+
+ }
+
# possible hidden children, see https://github.com/cmhughes/latexindent.pl/issues/85
if ( ( ${$self}{measureHiddenChildren} or ${$self}{measureVerbatim} )
and $column =~ m/.*?$tokens{beginOfToken}/s )
@@ -329,6 +347,7 @@ sub align_at_ampersand {
colSpan => ".",
delimiter => "",
delimiterLength => 0,
+ DBSpadding => 0,
measureThis => 0
}
);
@@ -380,13 +399,24 @@ sub align_at_ampersand {
for (
"entry", "type", "colSpan", "width",
"measureThis", "maximumColumnWidth", "individualPadding", "groupPadding",
- "delimiter", "delimiterLength"
+ "delimiter", "delimiterLength", "DBSpadding"
);
}
# main formatting loop
$self->main_formatting;
+ if ( defined $input{measure_after_DBS} ) {
+
+ # delete the original body
+ ${$self}{body} = q();
+
+ # update the body
+ ${$self}{body} .= ${$_}{row} . "\n" for @formattedBody;
+
+ return;
+ }
+
#
# final \\ loop
#
@@ -447,6 +477,49 @@ sub align_at_ampersand {
}
}
+ #
+ # put original body and 'after DBS body' together
+ #
+ if ( ${$self}{alignContentAfterDoubleBackSlash} ) {
+
+ # check that spacesAfterDoubleBackSlash>=0
+ ${$self}{spacesAfterDoubleBackSlash} = max( ${$self}{spacesAfterDoubleBackSlash}, 0 );
+
+ my @beforeDBSlengths = q();
+ my @originalFormattedBody = @formattedBody;
+ my $afterDBSbody = q();
+ my $maxDBSlength = 0;
+ foreach (@originalFormattedBody) {
+ ${$_}{row} =~ s/(.*?)(${${$mainSettings{fineTuning}}{modifyLineBreaks}}{doubleBackSlash})\h*//s;
+ ${$_}{beforeDBS} = ( $1 ? $1 : q() );
+ ${$_}{DBS} = ( $2 ? $2 : q() );
+ ${$_}{DBS} .= " " x ( ${$self}{spacesAfterDoubleBackSlash} ) if ( ${$_}{DBS} ne '' );
+ $afterDBSbody .= ${$_}{row} . "\n";
+ push( @beforeDBSlengths, &get_column_width( ${$_}{beforeDBS} . ${$_}{DBS} ) );
+ $maxDBSlength = max( $maxDBSlength, &get_column_width( ${$_}{beforeDBS} . ${$_}{DBS} ) );
+ }
+
+ ${$self}{body} = $afterDBSbody;
+ $self->align_at_ampersand(
+ measure_after_DBS => 1,
+ beforeDBSlengths => \@beforeDBSlengths,
+ maxDBSlength => $maxDBSlength
+ );
+
+ # create new afterDBSbody
+ my @afterDBSbody = split( "\n", ${$self}{body} );
+
+ # combine ORIGINAL body and ENDPIECE body
+ my $index = -1;
+ foreach (@originalFormattedBody) {
+ $index++;
+ ${$_}{row} = ${$_}{beforeDBS} . ${$_}{DBS};
+ ${$_}{row} .= $afterDBSbody[$index];
+ }
+
+ @formattedBody = @originalFormattedBody;
+ }
+
# delete the original body
${$self}{body} = q();
@@ -533,6 +606,12 @@ sub main_formatting {
next;
}
+ # alignment *after* double back slash, see
+ #
+ # test-cases/alignment/issue-393.tex
+ #
+ $tmpRow .= " " x ${$cell}{DBSpadding};
+
# the placement of the padding is dependent on the value of justification
if ( ${$self}{justification} eq "left" ) {
@@ -899,6 +978,7 @@ sub individual_padding {
colSpan => ".",
delimiter => "",
delimiterLength => 0,
+ DBSpadding => 0,
}
);
}