summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/latexindent
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2021-07-24 20:49:14 +0000
committerKarl Berry <karl@freefriends.org>2021-07-24 20:49:14 +0000
commited17b4b97e16c81b6869381411a74466acc81a23 (patch)
treef0871d251227472de31d3d3d8ef72234f0eb9d4d /Master/texmf-dist/scripts/latexindent
parentf0de3338cfffa669b4bfa9f7b24d887637265089 (diff)
latexindent (24jul21)
git-svn-id: svn://tug.org/texlive/trunk@60045 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/latexindent')
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm244
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm26
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm4
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm5
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/HiddenChildren.pm79
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm4
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm13
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm59
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm4
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/defaultSettings.yaml4
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/latexindent.pl2
11 files changed, 387 insertions, 57 deletions
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} % <!--- Hidden child
+# BBB & CCC \\ % <!--- Hidden child
+# E & F % <!--- Hidden child
+# \end{array} \\ % <!--- Hidden child
+#
+# Z & =\begin{array}{cc} % <!--- Hidden child
+# Y & X \\ % <!--- Hidden child
+# W & V % <!--- Hidden child
+# \end{array} % <!--- Hidden child
+# \end{align}
+#
+
+# PURPOSE:
+#
+# measure CELL width that has hidden children
+#
+# A & =\begin{array}{cc}
+# BBB & CCC \\
+# E & F
+# \end{array} \\
+#
+# ^^^^^^^^^^^^^^^^^^
+# ||||||||||||||||||
+#
+# Cell
+#
+sub hidden_child_cell_row_width{
+ my $self = shift;
+
+ my ($tmpCellEntry, $rowCounter, $columnCounter) = @_;
+
+ for my $hiddenChildToMeasure (@{${$self}{measureHiddenChildren}}){
+ if($tmpCellEntry =~m/.*?$hiddenChildToMeasure/s and defined $familyTree{$hiddenChildToMeasure}{bodyForMeasure}){
+ $tmpCellEntry =~ s/$hiddenChildToMeasure/$familyTree{$hiddenChildToMeasure}{bodyForMeasure}/s;
+ }
+ }
+
+ if ($tmpCellEntry =~ m/$tokens{verbatim}/){
+ #
+ # verbatim example:
+ #
+ # \begin{tabular}{ll}
+ # Testing & Line 1 \\
+ # Testing & Line 2 \\
+ # Testing & Line 3 \verb|X| \\
+ # Testing & Line 4 \\
+ # \end{tabular}
+ while( my ($verbatimID,$child)= each %verbatimStorage){
+ if($tmpCellEntry =~m/.*?$verbatimID/s){
+ $tmpCellEntry =~ s/$verbatimID/${$child}{begin}${$child}{body}${$child}{end}/s;
+ }
+ }
+ }
+ my $bodyLineBreaks = 0;
+ $bodyLineBreaks++ while($tmpCellEntry =~ m/\R/sg);
+ if($bodyLineBreaks>0){
+ my $maxRowWidthWithinCell = 0;
+ foreach(split("\n",$tmpCellEntry)){
+ my $currentRowWidth = Unicode::GCString->new($_)->columns();
+ $maxRowWidthWithinCell = $currentRowWidth if ($currentRowWidth > $maxRowWidthWithinCell );
+ }
+ ${$cellStorage[$rowCounter][$columnCounter]}{width} = $maxRowWidthWithinCell;
+ } else {
+ ${$cellStorage[$rowCounter][$columnCounter]}{width} = Unicode::GCString->new($tmpCellEntry)->columns();
+ }
+}
+
+# PURPOSE:
+#
+# measure ROW width that has hidden children
+#
+# A & =\begin{array}{cc}
+# BBB & CCC \\
+# E & F
+# \end{array} \\
+#
+# ^^^^^^^^^^^^^^^^^^^^^^
+# ||||||||||||||||||||||
+#
+# row
+#
+sub hidden_child_row_width{
+ my $self = shift;
+
+ my ($tmpRow,$rowCount,$rowWidth) = @_;
+
+ # some alignment blocks have the 'begin' statement on the opening line:
+ #
+ # this bit
+ # ||||||||||||||
+ # ``````````````
+ # \begin{align*}1 & 2 \\
+ # 3 & 4 \\
+ # 5 & 6
+ # \end{align*}
+ #
+ my $lengthOfBegin = 0;
+ if (!${${$self}{linebreaksAtEnd}}{begin}
+ and ${$cellStorage[0][0]}{type} eq "X"
+ and ${$cellStorage[0][0]}{measureThis}){
+
+ my $beginToMeasure = ${$self}{begin};
+ if( (${$self}{begin} eq '{' | ${$self}{begin} eq '[') and ${$self}{parentBegin}){
+ $beginToMeasure = ${$self}{parentBegin}."{";
+ }
+ $lengthOfBegin = Unicode::GCString->new($beginToMeasure)->columns();
+ $tmpRow = $beginToMeasure.$tmpRow if $rowCount == 0;
+ }
+
+ if ($tmpRow =~m/.*?$tokens{beginOfToken}/s){
+
+ $tmpRow = ("."x$lengthOfBegin).$tmpRow;
+
+ for my $hiddenChildToMeasure (@{${$self}{measureHiddenChildren}}){
+ if($tmpRow=~m/(^.*)?$hiddenChildToMeasure/m and defined $familyTree{$hiddenChildToMeasure}{bodyForMeasure}){
+ my $partBeforeId = $1;
+ my $lengthPartBeforeId = Unicode::GCString->new($partBeforeId)->columns();
+
+ foreach (@{$familyTree{$hiddenChildToMeasure}{ancestors}}){
+ if (${$_}{ancestorID} eq ${$self}{id}){
+ if($lengthOfBegin>0){
+ ${$_}{ancestorIndentation} = (" " x ($lengthPartBeforeId));
+ } else {
+ ${$_}{ancestorIndentation} = ${$_}{ancestorIndentation}.(" " x ($lengthPartBeforeId));
+ }
+ }
+ }
+ my $tmpBodyToMeasure = join( "\n".("."x($lengthPartBeforeId)),
+ split("\n",$familyTree{$hiddenChildToMeasure}{bodyForMeasure}));
+
+ # remove trailing \\
+ $tmpBodyToMeasure =~ s/(\\\\\h*$)//mg;
+
+ $tmpRow =~ s/$hiddenChildToMeasure/$tmpBodyToMeasure/s;
+ }
+ }
+
+ if ($tmpRow =~ m/$tokens{verbatim}/){
+ #
+ # verbatim example:
+ #
+ # \begin{tabular}{ll}
+ # Testing & Line 1 \\
+ # Testing & Line 2 \\
+ # Testing & Line 3 \verb|X| \\
+ # Testing & Line 4 \\
+ # \end{tabular}
+ while( my ($verbatimID,$child)= each %verbatimStorage){
+ if($tmpRow =~m/.*?$verbatimID/s){
+ $tmpRow =~ s/$verbatimID/${$child}{begin}${$child}{body}${$child}{end}/s;
+ }
+ }
+ }
+
+ my $bodyLineBreaks = 0;
+ $bodyLineBreaks++ while($tmpRow =~ m/\R/sg);
+ if($bodyLineBreaks>0){
+ my $maxRowWidth = 0;
+
+ foreach(split("\n",$tmpRow)){
+ my $currentRowWidth = Unicode::GCString->new($_)->columns();
+ $maxRowWidth = $currentRowWidth if ($currentRowWidth > $maxRowWidth );
+ }
+ $rowWidth = $maxRowWidth;
+ } else {
+ $rowWidth = Unicode::GCString->new($tmpRow)->columns();
+ }
+ } elsif (!${${$self}{linebreaksAtEnd}}{begin}
+ and ${$cellStorage[0][0]}{type} eq "X"
+ and ${$cellStorage[0][0]}{measureThis}){
+ $rowWidth = Unicode::GCString->new($tmpRow)->columns();
+ }
+
+ # possibly draw ruler to log file
+ &draw_ruler_to_logfile($tmpRow,$rowWidth) if ($is_t_switch_active);
+ return $rowWidth;
+}
+
+sub draw_ruler_to_logfile{
+ # draw a ruler to the log file, useful for debugging
+ #
+ # example:
+ #
+ # ----|----|----|----|----|----|----|----|----|----|----|----|----|----|
+ # 5 10 15 20 25 30 35 40 45 50 55 60 65 70
+ #
+
+ my ($tmpRow,$maxRowWidth) = @_;
+ $logger->trace("*tmpRow:");
+
+ foreach(split("\n",$tmpRow)){
+ my $currentRowWidth = Unicode::GCString->new($_)->columns();
+ $logger->trace("$_ \t(length: $currentRowWidth)");
+ }
+
+ my $rulerMax = int($maxRowWidth/10 +1.5 )*10;
+ $logger->trace(("----|"x(int($rulerMax/5))));
+
+ my $ruler = q();
+ for (my $i=1;$i<=$rulerMax/5;$i++){ $ruler .= " ".$i*5 };
+ $logger->trace($ruler);
+
+}
1;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm
index b6e609edc07..85a05579503 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm
@@ -29,18 +29,18 @@ use LatexIndent::GetYamlSettings qw/yaml_read_settings yaml_modify_line_breaks_s
use LatexIndent::FileExtension qw/file_extension_check/;
use LatexIndent::BackUpFileProcedure qw/create_back_up_file/;
use LatexIndent::BlankLines qw/protect_blank_lines unprotect_blank_lines condense_blank_lines/;
-use LatexIndent::ModifyLineBreaks qw/modify_line_breaks_body modify_line_breaks_end remove_line_breaks_begin adjust_line_breaks_end_parent text_wrap remove_paragraph_line_breaks construct_paragraph_reg_exp text_wrap_remove_paragraph_line_breaks verbatim_modify_line_breaks/;
+use LatexIndent::ModifyLineBreaks qw/modify_line_breaks_body modify_line_breaks_end modify_line_breaks_end_after remove_line_breaks_begin adjust_line_breaks_end_parent text_wrap remove_paragraph_line_breaks construct_paragraph_reg_exp text_wrap_remove_paragraph_line_breaks verbatim_modify_line_breaks/;
use LatexIndent::Sentence qw/one_sentence_per_line/;
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/;
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/;
-use LatexIndent::AlignmentAtAmpersand 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/;
+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/;
+use LatexIndent::AlignmentAtAmpersand 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 /;
use LatexIndent::DoubleBackSlash qw/dodge_double_backslash un_dodge_double_backslash/;
# code blocks
-use LatexIndent::Verbatim qw/put_verbatim_back_in find_verbatim_environments find_noindent_block find_verbatim_commands find_verbatim_special verbatim_common_tasks/;
+use LatexIndent::Verbatim qw/put_verbatim_back_in find_verbatim_environments find_noindent_block find_verbatim_commands find_verbatim_special verbatim_common_tasks %verbatimStorage/;
use LatexIndent::Environment qw/find_environments $environmentBasicRegExp construct_environments_regexp/;
use LatexIndent::IfElseFi qw/find_ifelsefi construct_ifelsefi_regexp $ifElseFiBasicRegExp/;
use LatexIndent::Else qw/check_for_else_statement/;
@@ -95,6 +95,8 @@ sub operate_on_file{
$self->remove_trailing_comments;
$self->find_verbatim_environments;
$self->find_verbatim_special;
+ $logger->trace("*Verbatim storage:") if $is_tt_switch_active;
+ $logger->trace(Dumper(\%verbatimStorage)) if $is_tt_switch_active;
$self->verbatim_modify_line_breaks if $is_m_switch_active;
$self->make_replacements(when=>"before") if $is_rv_switch_active;
$self->text_wrap if ($is_m_switch_active and !${$masterSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis} and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}>1);
@@ -311,10 +313,14 @@ sub get_settings_and_store_new_object{
# store children in special hash
push(@{${$self}{children}},$latexIndentObject);
+ # possible alignment preparation for hidden children
+ $self->hidden_children_preparation_for_alignment($latexIndentObject) if(${$latexIndentObject}{lookForAlignDelims} and ${$latexIndentObject}{measureHiddenChildren});
+
# possible decoration in log file
$logger->trace(${$masterSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}) if ${$masterSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace};
}
+
sub tasks_common_to_each_object{
my $self = shift;
@@ -358,7 +364,8 @@ sub tasks_common_to_each_object{
# text wrapping can make the ID split across lines
${$self}{idRegExp} = ${$self}{id};
- if($is_m_switch_active){
+ if($is_m_switch_active
+ and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{huge} ne "overflow"){
my $IDwithLineBreaks = join("\\R?\\h*",split(//,${$self}{id}));
${$self}{idRegExp} = qr/$IDwithLineBreaks/s;
}
@@ -371,16 +378,21 @@ sub tasks_common_to_each_object{
$self->adjust_replacement_text_line_breaks_at_end;
# modify line breaks on body and end statements
- $self->modify_line_breaks_body if ($is_m_switch_active and defined ${$self}{BodyStartsOnOwnLine});
+ $self->modify_line_breaks_body if ($is_m_switch_active and defined ${$self}{BodyStartsOnOwnLine} and ${$self}{BodyStartsOnOwnLine}!=0);
# modify line breaks end statements
- $self->modify_line_breaks_end if $is_m_switch_active;
+ $self->modify_line_breaks_end if ($is_m_switch_active and defined ${$self}{EndStartsOnOwnLine} and ${$self}{EndStartsOnOwnLine}!=0);
+ $self->modify_line_breaks_end_after if ($is_m_switch_active and defined ${$self}{EndFinishesWithLineBreak} and ${$self}{EndFinishesWithLineBreak}!=0);
# check the body for current children
$self->check_for_hidden_children if ${$self}{body} =~ m/$tokens{beginOfToken}/;
# double back slash poly-switch check
$self->double_back_slash_else if ($is_m_switch_active and ${$self}{lookForAlignDelims});
+
+ # some objects can format their body to align at the & character
+ $self->align_at_ampersand if (${$self}{lookForAlignDelims} and !${$self}{measureHiddenChildren});
+
return;
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm
index 26d8014f5a4..a213d7b247c 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm
@@ -121,6 +121,10 @@ sub yaml_get_indentation_information{
return q();
}
+sub check_for_hidden_children{
+ return q();
+}
+
sub create_unique_id{
my $self = shift;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm
index d870f16c417..ff7b0eeb18c 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm
@@ -24,6 +24,7 @@ use LatexIndent::Environment qw/$environmentBasicRegExp/;
use LatexIndent::IfElseFi qw/$ifElseFiBasicRegExp/;
use LatexIndent::Special qw/$specialBeginAndBracesBracketsBasicRegExp/;
use LatexIndent::Heading qw/$allHeadingsRegexp/;
+use LatexIndent::Verbatim qw/%verbatimStorage/;
use Data::Dumper;
use Exporter qw/import/;
our @EXPORT_OK = qw/find_file_contents_environments_and_preamble/;
@@ -179,7 +180,7 @@ sub find_file_contents_environments_and_preamble{
# indentPreamble set to 0
$logger->trace("NOT storing ${$preamble}{id} for indentation -- will store as VERBATIM object (because indentPreamble:0)") if $is_t_switch_active;
$preamble->unprotect_blank_lines;
- ${$self}{verbatim}{${$preamble}{id}} = $preamble;
+ $verbatimStorage{${$preamble}{id}} = $preamble;
}
} else {
${$self}{preamblePresent} = 0;
@@ -198,7 +199,7 @@ sub find_file_contents_environments_and_preamble{
} else {
# indentPreamble set to 0
$logger->trace("Storing ${$_}{id} as a VERBATIM object (indentPreamble is 0)") if $is_t_switch_active;
- ${$self}{verbatim}{${$_}{id}}=$_;
+ $verbatimStorage{${$_}{id}} = $_;
}
} else {
$logger->trace("storing ${$_}{id} for indentation (${$_}{name} found outside of preamble)") if $is_t_switch_active;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/HiddenChildren.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/HiddenChildren.pm
index 878939fd41a..a402a7cbce9 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/HiddenChildren.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/HiddenChildren.pm
@@ -21,7 +21,7 @@ use LatexIndent::Tokens qw/%tokens/;
use LatexIndent::LogFile qw/$logger/;
use Data::Dumper;
use Exporter qw/import/;
-our @EXPORT_OK = qw/find_surrounding_indentation_for_children update_family_tree get_family_tree check_for_hidden_children %familyTree/;
+our @EXPORT_OK = qw/find_surrounding_indentation_for_children update_family_tree get_family_tree check_for_hidden_children %familyTree hidden_children_preparation_for_alignment unpack_children_into_body/;
# hiddenChildren can be stored in a global array, it doesn't matter what level they're at
our %familyTree;
@@ -173,13 +173,15 @@ sub check_for_hidden_children{
}
# log file
- $logger->trace("*Hidden children check") if $is_t_switch_active;
+ $logger->trace("*Hidden children check for ${$self}{name}") if $is_t_switch_active;
$logger->trace(join("|",@matched)) if $is_t_switch_active;
my $naturalAncestors = ${$self}{naturalAncestors};
# loop through the hidden children
foreach my $match (@matched){
+ next if $match =~ m/$tokens{verbatim}/;
+
# update the family tree with ancestors of self
if(${$self}{ancestors}){
foreach(@{${$self}{ancestors}}){
@@ -197,9 +199,82 @@ sub check_for_hidden_children{
my $type = ($naturalAncestors =~ m/${$self}{id}/ ) ? "natural" : "adopted";
$logger->trace("Adding ${$self}{id} to the $type family tree of hiddenChild $match") if($is_t_switch_active);
push(@{$familyTree{$match}{ancestors}},{ancestorID=>${$self}{id},ancestorIndentation=>${$self}{indentation},type=>$type});
+
+ if(${$self}{lookForAlignDelims}){
+ $logger->trace("$match needs measuring for ${$self}{name} (see lookForAlignDelims)") if($is_t_switch_active);
+ push(@{${$self}{measureHiddenChildren}},$match);
+ }
+ }
+ }
+
+}
+
+#
+# AlignmentAtAmpersand routine calculations are below
+#
+# PURPOSE:
+#
+# Consider the following example, which contains hidden children
+#
+# \begin{align}
+# A & =\begin{array}{cc} % <!--- Hidden child
+# BBB & CCC \\ % <!--- Hidden child
+# E & F % <!--- Hidden child
+# \end{array} \\ % <!--- Hidden child
+#
+# Z & =\begin{array}{cc} % <!--- Hidden child
+# Y & X \\ % <!--- Hidden child
+# W & V % <!--- Hidden child
+# \end{array} % <!--- Hidden child
+# \end{align}
+#
+# the approach that we adopt is:
+#
+# 1. for the *original* object (align in the above), we loop through
+# its hidden children (array in the above) and unpack their contents
+# for measuring
+#
+# see hidden_children_preparation_for_alignment
+# unpack_children_into_body
+#
+# 2. we store the unpacked body in the familyTree hash, using 'bodyForMeasure'
+#
+# see $familyTree{${$_}{id}}{bodyForMeasure} = $bodyForMeasure;
+#
+# 3. during the alignment routine, we use 'bodyForMeasure' for measuring the cells
+#
+sub hidden_children_preparation_for_alignment{
+
+ my $self = shift;
+ my $latexIndentObject = shift;
+ for my $hiddenChildToMeasure (@{${$latexIndentObject}{measureHiddenChildren}}){
+ for (@{${$self}{children}}){
+ if(${$_}{id} eq $hiddenChildToMeasure){
+
+ my $bodyForMeasure = ${$_}{begin}.${$_}{body}.${$_}{end};
+ for my $child (${$_}{children}){
+ $bodyForMeasure = &unpack_children_into_body(\@{$child},$bodyForMeasure);
+ }
+ $familyTree{${$_}{id}}{bodyForMeasure} = $bodyForMeasure;
+ }
}
}
+ return;
+}
+
+sub unpack_children_into_body{
+ my $child = shift;
+ my $body = shift;
+ for my $individualChild (@{$child}){
+ $body =~ s/${$individualChild}{id}/${$individualChild}{begin}${$individualChild}{body}${$individualChild}{end}/s;
+ if(${$individualChild}{children}){
+ for my $nextlevelchild (${$individualChild}{children}){
+ $body = &unpack_children_into_body(\@{$nextlevelchild},$body);
+ }
+ }
+ }
+ return $body;
}
1;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm
index ffb4d3f7375..bf1216d5b1b 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm
@@ -118,7 +118,7 @@ sub indent_body{
$self->check_for_blank_lines_at_beginning if $is_m_switch_active;
# some objects can format their body to align at the & character
- $self->align_at_ampersand if ${$self}{lookForAlignDelims};
+ $self->align_at_ampersand if (${$self}{lookForAlignDelims} and !${$self}{dontMeasure});
# grab the indentation of the object
# NOTE: we need this here, as ${$self}{indentation} can be updated by the align_at_ampersand routine,
@@ -324,7 +324,7 @@ sub indent_children_recursively{
:q();
# line break checks before <begin statement>
- if(defined ${$child}{BeginStartsOnOwnLine}){
+ if(defined ${$child}{BeginStartsOnOwnLine} and ${$child}{BeginStartsOnOwnLine} !=0 ){
my $BeginStringLogFile = ${$child}{aliases}{BeginStartsOnOwnLine}||"BeginStartsOnOwnLine";
#
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm
index 8b00c52272c..1b3f9486459 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm
@@ -24,7 +24,8 @@ use LatexIndent::TrailingComments qw/$trailingCommentRegExp/;
use LatexIndent::Switches qw/$is_m_switch_active $is_t_switch_active $is_tt_switch_active/;
use LatexIndent::Item qw/$listOfItems/;
use LatexIndent::LogFile qw/$logger/;
-our @EXPORT_OK = qw/modify_line_breaks_body modify_line_breaks_end adjust_line_breaks_end_parent remove_line_breaks_begin text_wrap remove_paragraph_line_breaks construct_paragraph_reg_exp text_wrap_remove_paragraph_line_breaks verbatim_modify_line_breaks/;
+use LatexIndent::Verbatim qw/%verbatimStorage/;
+our @EXPORT_OK = qw/modify_line_breaks_body modify_line_breaks_end modify_line_breaks_end_after adjust_line_breaks_end_parent remove_line_breaks_begin text_wrap remove_paragraph_line_breaks construct_paragraph_reg_exp text_wrap_remove_paragraph_line_breaks verbatim_modify_line_breaks/;
our $paragraphRegExp = q();
sub modify_line_breaks_body{
@@ -105,7 +106,7 @@ sub modify_line_breaks_end{
# switch EndStartsOnOwnLine back to 4
#
- my @polySwitchValues =(defined ${$self}{EndStartsOnOwnLine} and ${$self}{EndStartsOnOwnLine}==4) ?(-1,3):(${$self}{EndStartsOnOwnLine});
+ my @polySwitchValues =(${$self}{EndStartsOnOwnLine}==4) ?(-1,3):(${$self}{EndStartsOnOwnLine});
foreach(@polySwitchValues){
# possibly modify line break *before* \end{statement}
if(defined ${$self}{EndStartsOnOwnLine}){
@@ -153,6 +154,10 @@ sub modify_line_breaks_end{
}
}
+ }
+
+sub modify_line_breaks_end_after{
+ my $self = shift;
#
# Blank line poly-switch notes (==4)
#
@@ -161,7 +166,7 @@ sub modify_line_breaks_end{
# temporarily change EndFinishesWithLineBreak to 3, make adjustments
# switch EndFinishesWithLineBreak back to 4
#
- @polySwitchValues =(defined ${$self}{EndFinishesWithLineBreak} and ${$self}{EndFinishesWithLineBreak}==4) ?(-1,3):(${$self}{EndFinishesWithLineBreak});
+ my @polySwitchValues =(${$self}{EndFinishesWithLineBreak}==4) ?(-1,3):(${$self}{EndFinishesWithLineBreak});
foreach(@polySwitchValues){
last if !(defined $_);
${$self}{linebreaksAtEnd}{end} = 0 if($_==3 and (defined ${$self}{EndFinishesWithLineBreak} and ${$self}{EndFinishesWithLineBreak}==4));
@@ -242,7 +247,7 @@ sub verbatim_modify_line_breaks{
# verbatim modify line breaks are a bit special, as they happen before
# any of the main processes have been done
my $self = shift;
- while ( my ($key,$child)= each %{${$self}{verbatim}}){
+ while ( my ($key,$child)= each %verbatimStorage){
if(defined ${$child}{BeginStartsOnOwnLine}){
my $BeginStringLogFile = ${$child}{aliases}{BeginStartsOnOwnLine};
$logger->trace("*$BeginStringLogFile is ${$child}{BeginStartsOnOwnLine} for ${$child}{name}") if $is_t_switch_active ;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm
index 1657f415212..2d8fe0e2d8a 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm
@@ -22,9 +22,10 @@ use LatexIndent::Tokens qw/%tokens/;
use LatexIndent::GetYamlSettings qw/%masterSettings/;
use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active $is_m_switch_active/;
use LatexIndent::LogFile qw/$logger/;
-our @EXPORT_OK = qw/put_verbatim_back_in find_verbatim_environments find_noindent_block find_verbatim_commands find_verbatim_special verbatim_common_tasks/;
+our @EXPORT_OK = qw/put_verbatim_back_in find_verbatim_environments find_noindent_block find_verbatim_commands find_verbatim_special verbatim_common_tasks %verbatimStorage/;
our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321
our $verbatimCounter;
+our %verbatimStorage;
sub find_noindent_block{
my $self = shift;
@@ -111,7 +112,7 @@ sub find_noindent_block{
$noIndentBlockObj->create_unique_id;
# verbatim children go in special hash
- ${$self}{verbatim}{${$noIndentBlockObj}{id}}=$noIndentBlockObj;
+ $verbatimStorage{${$noIndentBlockObj}{id}}=$noIndentBlockObj;
# log file output
$logger->trace("NOINDENTBLOCK found: $noIndentBlock") if $is_t_switch_active;
@@ -180,7 +181,7 @@ sub find_verbatim_environments{
$verbatimBlock->verbatim_common_tasks;
# verbatim children go in special hash
- ${$self}{verbatim}{${$verbatimBlock}{id}}=$verbatimBlock;
+ $verbatimStorage{${$verbatimBlock}{id}}=$verbatimBlock;
# log file output
$logger->trace("*VERBATIM environment found: $verbEnv") if $is_t_switch_active;
@@ -269,7 +270,7 @@ sub find_verbatim_commands{
$logger->trace(Dumper($verbatimCommand),'ttrace') if($is_tt_switch_active);
# verbatim children go in special hash
- ${$self}{verbatim}{${$verbatimCommand}{id}}=$verbatimCommand;
+ $verbatimStorage{${$verbatimCommand}{id}}=$verbatimCommand;
# log file output
$logger->trace("*VERBATIM command found: $verbCommand") if $is_t_switch_active;
@@ -338,7 +339,7 @@ sub find_verbatim_special{
$verbatimBlock->verbatim_common_tasks;
# verbatim children go in special hash
- ${$self}{verbatim}{${$verbatimBlock}{id}}=$verbatimBlock;
+ $verbatimStorage{${$verbatimBlock}{id}}=$verbatimBlock;
# log file output
$logger->trace("*VERBATIM special found: $specialName") if $is_t_switch_active;
@@ -359,29 +360,21 @@ sub put_verbatim_back_in {
my $self = shift;
my %input = @_;
- # if there are no verbatim children, return
- return unless(${$self}{verbatim});
-
my $verbatimCount=0;
my $toMatch = q();
if($input{match} eq "everything-except-commands"){
$toMatch = "noindentblockenvironmentspecial";
-
- # count the number of non-command verbatim objects
- while( my ($key,$child)= each %{${$self}{verbatim}}){
- ${$child}{type} = "environment" if !(defined ${$child}{type});
- $verbatimCount++ if($toMatch =~ m/${$child}{type}/);
- }
- return unless($verbatimCount>0);
} else {
$toMatch = "command";
- # count the number of command verbatim objects
- while( my ($key,$child)= each %{${$self}{verbatim}}){
- ${$child}{type} = "environment" if !(defined ${$child}{type});
- $verbatimCount++ if($toMatch =~ m/${$child}{type}/);
- }
- return unless($verbatimCount>0);
}
+
+ # count the number of non-command verbatim objects
+ while( my ($key,$child)= each %verbatimStorage){
+ ${$child}{type} = "environment" if !(defined ${$child}{type});
+ $verbatimCount++ if($toMatch =~ m/${$child}{type}/);
+ }
+
+ return unless($verbatimCount>0);
# search for environments/commands
$logger->trace('*Putting verbatim back in') if $is_t_switch_active;
@@ -391,31 +384,34 @@ sub put_verbatim_back_in {
# loop through document children hash
my $verbatimFound=0;
while($verbatimFound < $verbatimCount){
- while( my ($key,$child)= each %{${$self}{verbatim}}){
+ while( my ($verbatimID,$child)= each %verbatimStorage){
if($toMatch =~ m/${$child}{type}/){
- if(${$self}{body} =~ m/${$child}{id}/mx){
+ if(${$self}{body} =~ m/$verbatimID/mx){
# possibly remove trailing line break
if(defined ${$child}{EndFinishesWithLineBreak}
and ${$child}{EndFinishesWithLineBreak}==-1
- and ${$self}{body} =~ m/${$child}{id}\h*\R/s){
+ and ${$self}{body} =~ m/$verbatimID\h*\R/s){
$logger->trace("m-switch active, removing trailing line breaks from ${$child}{name}") if $is_t_switch_active;
- ${$self}{body} =~ s/${$child}{id}(\h*)?(\R|\h)*/${$child}{id} /s;
+ ${$self}{body} =~ s/$verbatimID(\h*)?(\R|\h)*/$verbatimID /s;
}
# replace ids with body
- ${$self}{body} =~ s/${$child}{id}/${$child}{begin}${$child}{body}${$child}{end}/s;
+ ${$self}{body} =~ s/$verbatimID/${$child}{begin}${$child}{body}${$child}{end}/s;
# log file info
$logger->trace('Body now looks like:') if $is_tt_switch_active;
$logger->trace(${$self}{body},'ttrace') if($is_tt_switch_active);
# delete the child so it won't be operated upon again
- delete ${$self}{verbatim}{${$child}{id}};
+ delete $verbatimStorage{$verbatimID};
$verbatimFound++;
- } elsif ($is_m_switch_active and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}>1 and ${$self}{body} !~ m/${$child}{id}/){
- $logger->trace("${$child}{id} not found in body using /m matching, it may have been split across line (see modifyLineBreaks: textWrapOptions)") if($is_t_switch_active);
+ } elsif ($is_m_switch_active
+ and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}>1
+ and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{huge} ne "overflow"
+ and ${$self}{body} !~ m/${$child}{id}/){
+ $logger->trace("$verbatimID not found in body using /m matching, it may have been split across line (see modifyLineBreaks: textWrapOptions)") if($is_t_switch_active);
# search for a version of the verbatim ID that may have line breaks
- my $verbatimIDwithLineBreaks = join("\\R?",split(//,${$child}{id}));
+ my $verbatimIDwithLineBreaks = join("\\R?",split(//,$verbatimID));
my $verbatimIDwithLineBreaksRegExp = qr/$verbatimIDwithLineBreaks/s;
# replace the line-broken verbatim ID with a non-broken verbatim ID
@@ -452,7 +448,8 @@ sub verbatim_common_tasks{
$self->adjust_replacement_text_line_breaks_at_end;
# modify line breaks end statements
- $self->modify_line_breaks_end if $is_m_switch_active;
+ $self->modify_line_breaks_end if ($is_m_switch_active and defined ${$self}{EndStartsOnOwnLine} and ${$self}{EndStartsOnOwnLine}!=0);
+ $self->modify_line_breaks_end_after if ($is_m_switch_active and defined ${$self}{EndFinishesWithLineBreak} and ${$self}{EndFinishesWithLineBreak}!=0);
}
sub create_unique_id{
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm
index eb1b1226dce..41ff54c12be 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm
@@ -19,6 +19,6 @@ use warnings;
use Exporter qw/import/;
our @EXPORT_OK = qw/$versionNumber $versionDate/;
-our $versionNumber = '3.10';
-our $versionDate = '2021-06-19';
+our $versionNumber = '3.10.1';
+our $versionDate = '2021-07-23';
1
diff --git a/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml b/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml
index 1d4c3704840..94a3a9f4c61 100755
--- a/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml
+++ b/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml
@@ -1,4 +1,4 @@
-# defaultSettings.yaml for latexindent.pl, version 3.10, 2021-06-19
+# defaultSettings.yaml for latexindent.pl, version 3.10.1, 2021-07-23
# a script that aims to
# beautify .tex, .sty, .cls files
#
@@ -509,7 +509,7 @@ modifyLineBreaks:
other: 0
textWrapOptions:
columns: 0
- # huge: overflow # forbid mid-word line breaks
+ huge: overflow # forbid mid-word line breaks
separator: ""
perCodeBlockBasis: 0
all: 0
diff --git a/Master/texmf-dist/scripts/latexindent/latexindent.pl b/Master/texmf-dist/scripts/latexindent/latexindent.pl
index 838b15f9dd8..7813b3a6575 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.10, 2021-06-19
+# latexindent.pl, version 3.10.1, 2021-07-23
#
# 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