summaryrefslogtreecommitdiff
path: root/support/latexindent/LatexIndent
diff options
context:
space:
mode:
Diffstat (limited to 'support/latexindent/LatexIndent')
-rw-r--r--support/latexindent/LatexIndent/Arguments.pm2
-rw-r--r--support/latexindent/LatexIndent/BlankLines.pm6
-rw-r--r--support/latexindent/LatexIndent/Document.pm57
-rw-r--r--support/latexindent/LatexIndent/FileContents.pm37
-rw-r--r--support/latexindent/LatexIndent/GetYamlSettings.pm278
-rw-r--r--support/latexindent/LatexIndent/HiddenChildren.pm3
-rw-r--r--support/latexindent/LatexIndent/ModifyLineBreaks.pm207
-rw-r--r--support/latexindent/LatexIndent/Preamble.pm30
-rw-r--r--support/latexindent/LatexIndent/Sentence.pm7
-rw-r--r--support/latexindent/LatexIndent/Tokens.pm1
-rw-r--r--support/latexindent/LatexIndent/TrailingComments.pm6
-rw-r--r--support/latexindent/LatexIndent/Verbatim.pm9
-rw-r--r--support/latexindent/LatexIndent/Version.pm4
-rw-r--r--support/latexindent/LatexIndent/Wrap.pm317
14 files changed, 395 insertions, 569 deletions
diff --git a/support/latexindent/LatexIndent/Arguments.pm b/support/latexindent/LatexIndent/Arguments.pm
index 028f0ec842..35ea03a63e 100644
--- a/support/latexindent/LatexIndent/Arguments.pm
+++ b/support/latexindent/LatexIndent/Arguments.pm
@@ -82,7 +82,7 @@ sub find_opt_mand_arguments{
# text wrapping can make the ID split across lines
${$arguments}{idRegExp} = ${$arguments}{id};
- if($is_m_switch_active){
+ if($is_m_switch_active and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{huge} ne "overflow"){
my $IDwithLineBreaks = join("\\R?\\h*",split(//,${$arguments}{id}));
${$arguments}{idRegExp} = qr/$IDwithLineBreaks/s;
}
diff --git a/support/latexindent/LatexIndent/BlankLines.pm b/support/latexindent/LatexIndent/BlankLines.pm
index a3e439d2e0..b1a3cee40d 100644
--- a/support/latexindent/LatexIndent/BlankLines.pm
+++ b/support/latexindent/LatexIndent/BlankLines.pm
@@ -83,7 +83,11 @@ sub unprotect_blank_lines{
${$self}{body} =~ s/^\h*\R//mg;
$logger->trace("Unprotecting blank lines (see preserveBlankLines)") if $is_t_switch_active;
- my $blankLineToken = join("(?:\\h|\\R)*",split(//,$tokens{blanklines}));
+ my $blankLineToken = $tokens{blanklines};
+
+ if($is_m_switch_active and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{huge} ne "overflow"){
+ $blankLineToken = join("(?:\\h|\\R)*",split(//,$tokens{blanklines}));
+ }
# loop through the body, looking for the blank line token
while(${$self}{body} =~ m/$blankLineToken/s){
diff --git a/support/latexindent/LatexIndent/Document.pm b/support/latexindent/LatexIndent/Document.pm
index 5be5084729..2ad655a56a 100644
--- a/support/latexindent/LatexIndent/Document.pm
+++ b/support/latexindent/LatexIndent/Document.pm
@@ -27,12 +27,13 @@ use LatexIndent::Logger qw/@logFileLines/;
use LatexIndent::Check qw/simple_diff/;
use LatexIndent::Lines qw/lines_body_selected_lines lines_verbatim_create_line_block/;
use LatexIndent::Replacement qw/make_replacements/;
-use LatexIndent::GetYamlSettings qw/yaml_read_settings yaml_modify_line_breaks_settings yaml_get_indentation_settings_for_this_object yaml_poly_switch_get_every_or_custom_value yaml_get_indentation_information yaml_get_object_attribute_for_indentation_settings yaml_alignment_at_ampersand_settings yaml_get_textwrap_removeparagraphline_breaks %mainSettings yaml_get_columns/;
+use LatexIndent::GetYamlSettings qw/yaml_read_settings yaml_modify_line_breaks_settings yaml_get_indentation_settings_for_this_object yaml_poly_switch_get_every_or_custom_value yaml_get_indentation_information yaml_get_object_attribute_for_indentation_settings yaml_alignment_at_ampersand_settings %mainSettings /;
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 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::ModifyLineBreaks qw/modify_line_breaks_body modify_line_breaks_end modify_line_breaks_end_after remove_line_breaks_begin adjust_line_breaks_end_parent verbatim_modify_line_breaks/;
use LatexIndent::Sentence qw/one_sentence_per_line/;
+use LatexIndent::Wrap qw/text_wrap/;
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/;
@@ -104,9 +105,8 @@ sub operate_on_file{
$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->verbatim_modify_line_breaks (when=>"beforeTextWrap") if $is_m_switch_active;
$self->make_replacements(when=>"before") if $is_rv_switch_active;
- $self->text_wrap if ($is_m_switch_active and !${$mainSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis} and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns}>1);
$self->protect_blank_lines if $is_m_switch_active;
$self->remove_trailing_whitespace(when=>"before");
$self->find_file_contents_environments_and_preamble;
@@ -142,7 +142,6 @@ sub construct_regular_expressions{
$self->construct_key_equals_values_regexp;
$self->construct_grouping_braces_brackets_regexp;
$self->construct_unnamed_grouping_braces_brackets_regexp;
- $self->construct_paragraph_reg_exp if $is_m_switch_active;
}
sub output_indented_text{
@@ -231,19 +230,23 @@ sub find_objects{
# one sentence per line: sentences are objects, as of V3.5.1
$self->one_sentence_per_line if ($is_m_switch_active and ${$mainSettings{modifyLineBreaks}{oneSentencePerLine}}{manipulateSentences});
- if ($is_m_switch_active and !${$self}{preamblePresent}){
- $self->yaml_get_textwrap_removeparagraphline_breaks;
- }
-
- if( $is_m_switch_active and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{beforeFindingChildCodeBlocks} == 1){
- # call the remove_paragraph_line_breaks and text_wrap routines
- if(${$mainSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{beforeTextWrap}){
- $self->remove_paragraph_line_breaks if ${$self}{removeParagraphLineBreaks};
- $self->text_wrap if (${$self}{textWrapOptions} and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
- } else {
- $self->text_wrap if (${$self}{textWrapOptions} and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
- $self->remove_paragraph_line_breaks if ${$self}{removeParagraphLineBreaks};
- }
+ # text wrapping
+ #
+ # note: this routine will *not* be called if
+ #
+ # modifyLineBreaks:
+ # oneSentencePerLine:
+ # manipulateSentences: 1
+ # textWrapSentences: 1
+ #
+ if ($is_m_switch_active
+ and !${$mainSettings{modifyLineBreaks}{oneSentencePerLine}}{manipulateSentences}
+ and !${$mainSettings{modifyLineBreaks}{oneSentencePerLine}}{textWrapSentences}
+ and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns} !=0 ){
+ $self->text_wrap();
+
+ # text wrapping can affect verbatim poly-switches, so we run it again
+ $self->verbatim_modify_line_breaks(when=>"afterTextWrap");
}
# search for environments
@@ -261,18 +264,6 @@ sub find_objects{
# the ordering of finding commands and special code blocks can change
$self->find_commands_or_key_equals_values_braces_and_special if ${$self}{body} =~ m/$specialBeginAndBracesBracketsBasicRegExp/s;
- # documents without preamble need a manual call to the paragraph_one_line routine
- if ($is_m_switch_active and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{beforeFindingChildCodeBlocks} == 0 ){
- # call the remove_paragraph_line_breaks and text_wrap routines
- if(${$mainSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{beforeTextWrap}){
- $self->remove_paragraph_line_breaks if ${$self}{removeParagraphLineBreaks};
- $self->text_wrap if (${$self}{textWrapOptions} and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
- } else {
- $self->text_wrap if (${$self}{textWrapOptions} and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
- $self->remove_paragraph_line_breaks if ${$self}{removeParagraphLineBreaks};
- }
- }
-
# if there are no children, return
if(${$self}{children}){
$logger->trace("*Objects have been found.") if $is_t_switch_active;
@@ -326,15 +317,9 @@ sub get_settings_and_store_new_object{
# there are a number of tasks common to each object
$latexIndentObject->tasks_common_to_each_object(%{$self});
- # removeParagraphLineBreaks and textWrapping fun!
- $latexIndentObject->text_wrap_remove_paragraph_line_breaks if( $is_m_switch_active and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{beforeFindingChildCodeBlocks} );
-
# tasks particular to each object
$latexIndentObject->tasks_particular_to_each_object;
- # removeParagraphLineBreaks and textWrapping fun!
- $latexIndentObject->text_wrap_remove_paragraph_line_breaks if($is_m_switch_active and !${$mainSettings{modifyLineBreaks}{textWrapOptions}}{beforeFindingChildCodeBlocks} );
-
# store children in special hash
push(@{${$self}{children}},$latexIndentObject);
diff --git a/support/latexindent/LatexIndent/FileContents.pm b/support/latexindent/LatexIndent/FileContents.pm
index 439e764b31..4683cc7a11 100644
--- a/support/latexindent/LatexIndent/FileContents.pm
+++ b/support/latexindent/LatexIndent/FileContents.pm
@@ -93,7 +93,7 @@ sub find_file_contents_environments_and_preamble{
# text wrapping can make the ID split across lines
${$fileContentsBlock}{idRegExp} = ${$fileContentsBlock}{id};
- if($is_m_switch_active){
+ if($is_m_switch_active and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{huge} ne "overflow"){
my $IDwithLineBreaks = join("\\R?\\h*",split(//,${$fileContentsBlock}{id}));
${$fileContentsBlock}{idRegExp} = qr/$IDwithLineBreaks/s;
}
@@ -112,7 +112,7 @@ sub find_file_contents_environments_and_preamble{
push(@fileContentsStorageArray,$fileContentsBlock);
# log file output
- $logger->trace("FILECONTENTS environment found: ${$fileContentsEnv}{name}")if $is_t_switch_active;
+ $logger->trace("FILECONTENTS environment found: ${$fileContentsBlock}{name}")if $is_t_switch_active;
# remove the environment block, and replace with unique ID
${$self}{body} =~ s/$fileContentsRegExp/${$fileContentsBlock}{replacementText}/sx;
@@ -157,7 +157,7 @@ sub find_file_contents_environments_and_preamble{
# text wrapping can make the ID split across lines
${$preamble}{idRegExp} = ${$preamble}{id};
- if($is_m_switch_active){
+ if($is_m_switch_active and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{huge} ne "overflow"){
my $IDwithLineBreaks = join("\\R?\\h*",split(//,${$preamble}{id}));
${$preamble}{idRegExp} = qr/$IDwithLineBreaks/s;
}
@@ -220,6 +220,8 @@ sub find_file_contents_environments_and_preamble{
if($needToStorePreamble){
$preamble->dodge_double_backslash;
$preamble->remove_leading_space;
+ # text wrapping
+ $preamble->text_wrap() if ($is_m_switch_active and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns} !=0 );
$preamble->find_commands_or_key_equals_values_braces if($mainSettings{preambleCommandsBeforeEnvironments});
$preamble->tasks_particular_to_each_object;
push(@{${$self}{children}},$preamble);
@@ -238,23 +240,6 @@ sub create_unique_id{
sub tasks_particular_to_each_object{
my $self = shift;
- # text wrapping, remove paragraph line breaks
- if ($is_m_switch_active){
- $self->yaml_get_textwrap_removeparagraphline_breaks;
- }
-
- # option to textWrap beforeFindingChildCodeBlocks
- if( $is_m_switch_active and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{beforeFindingChildCodeBlocks} == 1){
- # call the remove_paragraph_line_breaks and text_wrap routines
- if(${$mainSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{beforeTextWrap}){
- $self->remove_paragraph_line_breaks if ${$self}{removeParagraphLineBreaks};
- $self->text_wrap if (${$self}{textWrapOptions} and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
- } else {
- $self->text_wrap if (${$self}{textWrapOptions} and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
- $self->remove_paragraph_line_breaks if ${$self}{removeParagraphLineBreaks};
- }
- }
-
# search for environments
$self->find_environments if ${$self}{body} =~ m/$environmentBasicRegExp/s;
@@ -266,18 +251,6 @@ sub tasks_particular_to_each_object{
# search for commands and special code blocks
$self->find_commands_or_key_equals_values_braces_and_special if ${$self}{body} =~ m/$specialBeginAndBracesBracketsBasicRegExp/s;
-
- # text wrapping, remove paragraph line breaks
- if ($is_m_switch_active and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{beforeFindingChildCodeBlocks} == 0){
- # call the remove_paragraph_line_breaks and text_wrap routines
- if(${$mainSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{beforeTextWrap}){
- $self->remove_paragraph_line_breaks if ${$self}{removeParagraphLineBreaks};
- $self->text_wrap if (${$self}{textWrapOptions} and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
- } else {
- $self->text_wrap if (${$self}{textWrapOptions} and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
- $self->remove_paragraph_line_breaks if ${$self}{removeParagraphLineBreaks};
- }
- }
}
1;
diff --git a/support/latexindent/LatexIndent/GetYamlSettings.pm b/support/latexindent/LatexIndent/GetYamlSettings.pm
index 50d33a4f2f..b8a9aa0d4e 100644
--- a/support/latexindent/LatexIndent/GetYamlSettings.pm
+++ b/support/latexindent/LatexIndent/GetYamlSettings.pm
@@ -24,7 +24,7 @@ use File::HomeDir;
use Cwd;
use Exporter qw/import/;
use LatexIndent::LogFile qw/$logger/;
-our @EXPORT_OK = qw/yaml_read_settings yaml_modify_line_breaks_settings yaml_get_indentation_settings_for_this_object yaml_poly_switch_get_every_or_custom_value yaml_get_indentation_information yaml_get_object_attribute_for_indentation_settings yaml_alignment_at_ampersand_settings yaml_get_textwrap_removeparagraphline_breaks %mainSettings yaml_get_columns/;
+our @EXPORT_OK = qw/yaml_read_settings yaml_modify_line_breaks_settings yaml_get_indentation_settings_for_this_object yaml_poly_switch_get_every_or_custom_value yaml_get_indentation_information yaml_get_object_attribute_for_indentation_settings yaml_alignment_at_ampersand_settings %mainSettings/;
# Read in defaultSettings.YAML file
our $defaultSettings;
@@ -590,100 +590,6 @@ sub yaml_read_settings{
}
- if( $is_m_switch_active
- and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{beforeFindingChildCodeBlocks}
- and !${$mainSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis} ){
-
- # the following settings don't make sense, so we change
- #
- # modifyLineBreaks:
- # textWrapOptions:
- # perCodeBlockBasis: 0
- # beforeFindingChildCodeBlocks: 1
- # into
- #
- # modifyLineBreaks:
- # textWrapOptions:
- # perCodeBlockBasis: 0
- # beforeFindingChildCodeBlocks: 0
- $logger->warn("*textWrapOptions:beforeFindingChildCodeBlocks:1 with textWrapOptions:perCodeBlockBasis:0");
- $logger->warn("turning off beforeFindingChildCodeBlocks by changing textWrapOptions:beforeFindingOtherCodeBlocks to be 0");
- $logger->warn("you need to set *both* values to be 1 to use the beforeFindingChildCodeBlocks feature");
- ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{beforeFindingChildCodeBlocks} = 0;
- }
-
- # modifyLineBreaks:
- # textWrapOptions:
- # columns: 80
- # perCodeBlockBasis: 1
- # masterDocument: 1
- #
- # needs to be interpretted as
- #
- # modifyLineBreaks:
- # textWrapOptions:
- # columns: 80
- # perCodeBlockBasis: 1
- # mainDocument: 1
- #
- if( $is_m_switch_active
- and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis}
- and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{masterDocument} ){
- $logger->warn("*textWrapOptions:masterDocument specified when textWrapOptions:mainDocument preferred");
- $logger->warn("setting textWrapOptions:mainDocument: 1, but note that future versions of latexindent.pl may not support this");
- $logger->warn("recommendation to use textWrapOptions:mainDocument: 1 in place of textWrapOptions:masterDocument:1");
- ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{mainDocument} = 1;
- }
-
- # modifyLineBreaks:
- # removeParagraphLineBreaks:
- # masterDocument: 1
- #
- # needs to be interpretted as
- #
- # modifyLineBreaks:
- # removeParagraphLineBreaks:
- # mainDocument: 1
- #
- if( $is_m_switch_active and ${$mainSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{masterDocument} ){
- $logger->warn("*removeParagraphLineBreaks:masterDocument specified when removeParagraphLineBreaks:mainDocument preferred");
- $logger->warn("setting removeParagraphLineBreaks:mainDocument: 1, but note that future versions of latexindent.pl may not support this");
- $logger->warn("recommendation to use removeParagraphLineBreaks:mainDocument: 1 in place of removeParagraphLineBreaks:masterDocument:1");
- ${$mainSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{mainDocument} = 1;
- }
-
- # modifyLineBreaks:
- # textWrapOptions/removeParagraphLineBreaks:
- # all:
- # except:
- # - 'masterDocument'
- #
- # need to be interpretted as
- #
- # modifyLineBreaks:
- # textWrapOptions/removeParagraphLineBreaks:
- # all:
- # except:
- # - 'mainDocument'
- #
- if( $is_m_switch_active ){
- foreach ("textWrapOptions","removeParagraphLineBreaks"){
- if ( ref ${$mainSettings{modifyLineBreaks}{$_}}{all} eq "HASH"
- and
- defined ${${$mainSettings{modifyLineBreaks}{$_}}{all}}{except}
- and
- ref ${${$mainSettings{modifyLineBreaks}{$_}}{all}}{except} eq "ARRAY") {
- my %except = map { $_ => 1 } @{${${$mainSettings{modifyLineBreaks}}{$_}}{all}{except}};
- if($except{masterDocument}){
- $logger->warn("*$_:all:except:masterDocument specified when mainDocument preferred");
- $logger->warn("setting $_:all:except:mainDocument:1, but note that future versions of latexindent.pl may not support this");
- $logger->warn("recommendation to use $_:all:except:mainDocument:1 in place of $_:all:except:masterDocument:1");
- push( @{${${$mainSettings{modifyLineBreaks}}{$_}}{all}{except}}, "mainDocument" );
- }
- }
- }
- }
-
# some users may wish to see showAmalgamatedSettings
# which details the overall state of the settings modified
# from the default in various user files
@@ -870,188 +776,6 @@ sub yaml_modify_line_breaks_settings{
);
};
- $self->yaml_get_textwrap_removeparagraphline_breaks;
- return;
-}
-
-sub yaml_get_textwrap_removeparagraphline_breaks{
- my $self = shift;
-
- # textWrap and removeParagraphLineBreaks settings
- foreach ("textWrapOptions","removeParagraphLineBreaks"){
-
- # first check for either
- #
- # textWrapOptions:
- # all: 0
- #
- # or
- #
- # removeParagraphLineBreaks:
- # all: 0
- #
- # *IMPORTANT*
- # even if all is set to 1, then it can still be disabled on either a
- #
- # per-object:
- #
- # for example
- #
- # textWrapOptions:
- # all:
- # except:
- # - environments
- #
- # will disable textWrapOptions for *all* environments
- #
- # per-name
- #
- # for example
- #
- # textWrapOptions:
- # all:
- # except:
- # - itemize
- #
- # will disable textWrapOptions for itemize
-
- # if 'all' is set as a hash, then the default value is 1, to be turned off (possibly) later
- ${$self}{$_} = ( ref ${$mainSettings{modifyLineBreaks}{$_}}{all} eq "HASH" ? 1 : ${$mainSettings{modifyLineBreaks}{$_}}{all});
-
- # get the columns
- if($_ eq "textWrapOptions" and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis}){
- $self->yaml_get_columns;
- }
-
- # name of the object in the modifyLineBreaks yaml (e.g environments, ifElseFi, etc)
- my $YamlName = ${$self}{modifyLineBreaksYamlName};
-
- # if the YamlName is either optionalArguments or mandatoryArguments, then we'll be looking for information about the *parent*
- my $name = ($YamlName =~ m/Arguments/) ? ${$self}{parent} : ${$self}{name};
-
- # move to the next <thing> if
- #
- # textWrapOptions/removeParagraphLineBreaks::
- # all: 1
- #
- if(${$self}{$_}
- and
- ref ${$mainSettings{modifyLineBreaks}{$_}}{all} ne "HASH"
- and
- ${$mainSettings{modifyLineBreaks}{$_}}{all}){
- $logger->trace("$_ for $name is ${$self}{$_}") if $is_t_switch_active;
- next;
- };
-
- # otherwise, look for exceptions, either through
- #
- # textWrapOptions/removeParagraphLineBreaks:
- # all:
- # except:
- # - <*type* of thing or *name* of thing>
- #
- # so, for example, the following (per code-block) is acceptable
- # which makes an exception for all *environments*
- #
- # all:
- # except:
- # - 'environments'
- #
- # the following (per-name) is acceptable
- # which only makes an exception for things called itemize
- #
- # all:
- # except:
- # - 'itemize'
- #
- if(${$self}{$_}
- and
- defined ${${$mainSettings{modifyLineBreaks}{$_}}{all}}{except}
- and
- ref ${${$mainSettings{modifyLineBreaks}{$_}}{all}}{except} eq "ARRAY"
- ){
- my %except = map { $_ => 1 } @{${${$mainSettings{modifyLineBreaks}}{$_}}{all}{except}};
- if( $except{$name} or $except{$YamlName}){
- ${$self}{$_} = 0;
- my $detail = ($except{$name} ? "per-name" : "per-code-block-type");
- $logger->trace("$_ for $name is ${$self}{$_} (found as exception $detail, see $_:all:except)") if $is_t_switch_active;
- next;
- }
- } else {
- # or otherwise through, for example
- #
- # all: 0
- # ifElseFi: 1
- #
- # the textWrapOptions/removeParagraphLineBreaks can contain fields that are hashes or scalar
- #
- if(ref ${$mainSettings{modifyLineBreaks}{$_}}{$YamlName} eq "HASH"){
- # textWrapOptions/removeParagraphLineBreaks:
- # all: 0
- # environments:
- # quotation: 0
- $logger->trace("*$YamlName specified with fields in $_, looking for $name") if $is_t_switch_active;
- ${$self}{$_} = ${${$mainSettings{modifyLineBreaks}{$_}}{$YamlName}}{$name} if (defined ${${$mainSettings{modifyLineBreaks}{$_}}{$YamlName}}{$name});
- } elsif(defined ${$mainSettings{modifyLineBreaks}{$_}}{$YamlName}){
- # textWrapOptions/removeParagraphLineBreaks:
- # all: 0
- # environments: 0
- $logger->trace("*$YamlName specified with just a number in $_ ${$mainSettings{modifyLineBreaks}{$_}}{$YamlName}") if $is_t_switch_active;
- ${$self}{$_} = ${$mainSettings{modifyLineBreaks}{$_}}{$YamlName} if (defined ${$mainSettings{modifyLineBreaks}{$_}}{$YamlName});
- }
- }
-
- # summary to log file
- $logger->trace("$_ for $name is ${$self}{$_}") if $is_t_switch_active;
- }
-
- return;
-}
-
-sub yaml_get_columns{
- my $self = shift;
-
- my $YamlName = ${$self}{modifyLineBreaksYamlName};
-
- # the columns settings can have a variety of different ways of being specified
- if(ref ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns} eq "HASH"){
- # assign default value of $columns
- my $columns;
- if(defined ${${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns}}{default}){
- $columns = ${${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns}}{default};
- } else {
- $columns = 80;
- }
-
- # possibly specify object wrapping on a per-name basis
- if(ref ${${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns}}{$YamlName} eq "HASH"){
- # for example:
- # modifyLineBreaks:
- # textWrapOptions:
- # columns:
- # default: 80
- # environments:
- # default: 80
- # something: 10
- # another: 20
- if(defined ${${${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns}}{$YamlName}}{${$self}{name}}){
- $columns = ${${${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns}}{$YamlName}}{${$self}{name}};
- } elsif (${${${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns}}{$YamlName}}{default}){
- $columns = ${${${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns}}{$YamlName}}{default};
- }
- } else {
- # for example:
- # modifyLineBreaks:
- # textWrapOptions:
- # columns:
- # default: 80
- # environments: 10
- $columns = ${${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns}}{$YamlName};
- }
- ${$self}{columns} = $columns;
- } else {
- ${$self}{columns} = ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns};
- }
return;
}
diff --git a/support/latexindent/LatexIndent/HiddenChildren.pm b/support/latexindent/LatexIndent/HiddenChildren.pm
index a402a7cbce..0e6d965780 100644
--- a/support/latexindent/LatexIndent/HiddenChildren.pm
+++ b/support/latexindent/LatexIndent/HiddenChildren.pm
@@ -19,6 +19,7 @@ use warnings;
use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active $is_m_switch_active /;
use LatexIndent::Tokens qw/%tokens/;
use LatexIndent::LogFile qw/$logger/;
+use LatexIndent::GetYamlSettings qw/%mainSettings/;
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 hidden_children_preparation_for_alignment unpack_children_into_body/;
@@ -158,7 +159,7 @@ sub check_for_hidden_children{
my @matched;
# grab the matches
- if($is_m_switch_active){
+ if($is_m_switch_active and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{huge} ne "overflow"){
# if modifyLineBreaks is active, then the IDS can be split across lines
my $ifElseFiSpecialBegin = join("\\R?\\h*",split(//,$tokens{ifelsefiSpecial}));
my $BeginwithLineBreaks = join("\\R?\\h*",split(//,$tokens{beginOfToken}));
diff --git a/support/latexindent/LatexIndent/ModifyLineBreaks.pm b/support/latexindent/LatexIndent/ModifyLineBreaks.pm
index 128dcd8ed8..63f6c2d03f 100644
--- a/support/latexindent/LatexIndent/ModifyLineBreaks.pm
+++ b/support/latexindent/LatexIndent/ModifyLineBreaks.pm
@@ -17,7 +17,6 @@ package LatexIndent::ModifyLineBreaks;
use strict;
use warnings;
use Exporter qw/import/;
-use Text::Wrap;
use LatexIndent::GetYamlSettings qw/%mainSettings/;
use LatexIndent::Tokens qw/%tokens/;
use LatexIndent::TrailingComments qw/$trailingCommentRegExp/;
@@ -25,7 +24,7 @@ use LatexIndent::Switches qw/$is_m_switch_active $is_t_switch_active $is_tt_swit
use LatexIndent::Item qw/$listOfItems/;
use LatexIndent::LogFile qw/$logger/;
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 @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 verbatim_modify_line_breaks/;
our $paragraphRegExp = q();
sub modify_line_breaks_body{
@@ -247,6 +246,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;
+ my %input = @_;
while ( my ($key,$child)= each %verbatimStorage){
if(defined ${$child}{BeginStartsOnOwnLine}){
my $BeginStringLogFile = ${$child}{aliases}{BeginStartsOnOwnLine};
@@ -272,191 +272,32 @@ sub verbatim_modify_line_breaks{
${$self}{body} =~ s/\h*${$child}{id}/$trailingCharacterToken\n${$child}{id}/s;
}
}
- }
-}
-
-sub text_wrap_remove_paragraph_line_breaks{
- my $self = shift;
-
- if(${$mainSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{beforeTextWrap}){
- $self->remove_paragraph_line_breaks if ${$self}{removeParagraphLineBreaks};
- $self->text_wrap if (${$self}{textWrapOptions} and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
- } else {
- $self->text_wrap if (${$self}{textWrapOptions} and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
- }
-
-}
-
-sub text_wrap{
-
- my $self = shift;
-
- # alignment at ampersand can take priority
- return if(${$self}{lookForAlignDelims} and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{alignAtAmpersandTakesPriority});
-
- # goal: get an accurate measurement of verbatim objects;
- #
- # example:
- # Lorem \verb!x+y! ipsum dolor sit amet
- #
- # is represented as
- #
- # Lorem LTXIN-TK-VERBATIM1-END ipsum dolor sit amet
- #
- # so we *measure* the verbatim token and replace it with
- # an appropriate-length string
- #
- # Lorem a2A41233rt ipsum dolor sit amet
- #
- # and then put the body back to
- #
- # Lorem LTXIN-TK-VERBATIM1-END ipsum dolor sit amet
- #
- # following the text wrapping
- my @putVerbatimBackIn;
-
- # check body for verbatim and get measurements
- if (${$self}{body} =~ m/$tokens{verbatim}/s and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{huge} eq "overflow"){
-
- # reference: https://stackoverflow.com/questions/10336660/in-perl-how-can-i-generate-random-strings-consisting-of-eight-hex-digits
- my @set = ('0' ..'9', 'A' .. 'Z', 'a' .. 'z');
-
- # loop through verbatim objects
- while( my ($verbatimID,$child)= each %verbatimStorage){
- my $verbatimThing = ${$child}{begin}.${$child}{body}.${$child}{end};
-
- # if the object has line breaks, don't measure it
- next if $verbatimThing =~ m/\R/s;
-
- if(${$self}{body} =~m/$verbatimID/s){
-
- # measure length
- my $verbatimLength = Unicode::GCString->new($verbatimThing)->columns();
-
- # create temporary ID, and check that it is not contained in the body
- my $verbatimTmpID = join '' => map $set[rand @set], 1 .. $verbatimLength;
- while(${$self}{body} =~m/$verbatimTmpID/s){
- $verbatimTmpID = join '' => map $set[rand @set], 1 .. $verbatimLength;
+ # after text wrap poly-switch check
+ if ($input{when} eq "afterTextWrap"){
+ $logger->trace("*post text wrap poly-switch check for EndFinishesWithLineBreak") if $is_t_switch_active ;
+ if (defined ${$child}{EndFinishesWithLineBreak}
+ and ${$child}{EndFinishesWithLineBreak}>=1
+ and ${$self}{body} =~m/${$child}{id}\h*\S+/m){
+ ${$child}{linebreaksAtEnd}{end} = 1;
+
+ # by default, assume that no trailing comment token is needed
+ my $trailingCommentToken = q();
+ my $lineBreakCharacter = q();
+ my $EndStringLogFile = ${$self}{aliases}{EndStartsOnOwnLine}||"EndStartsOnOwnLine";
+
+ if(${$child}{EndFinishesWithLineBreak}==1){
+ $logger->trace("Adding a linebreak at the end of ${$child}{end} (post text wrap $EndStringLogFile==1)") if $is_t_switch_active;
+ $lineBreakCharacter = "\n";
+ } elsif(${$child}{EndFinishesWithLineBreak}==2 and ${$self}{body} !~ m/${$child}{id}\h*$trailingCommentRegExp/s){
+ $logger->trace("Adding a % immediately after ${$child}{end} (post text wrap $EndStringLogFile==2)") if $is_t_switch_active;
+ $trailingCommentToken = "%".$self->add_comment_symbol."\n";
+ } elsif(${$child}{EndFinishesWithLineBreak}==3){
+ $lineBreakCharacter .= (${$mainSettings{modifyLineBreaks}}{preserveBlankLines}?$tokens{blanklines}:"\n")."\n";
}
-
- # store for use after the text wrapping
- push(@putVerbatimBackIn,{origVerbatimID=>$verbatimID,tmpVerbatimID=>$verbatimTmpID});
-
- # make the substitution
- ${$self}{body} =~ s/$verbatimID/$verbatimTmpID/s;
+ ${$self}{body} =~s/${$child}{id}(\h*)/${$child}{id}$1$trailingCommentToken$lineBreakCharacter/s;
}
}
}
-
- # call the text wrapping routine
- my $columns;
-
- # columns might have been defined by the user
- if(defined ${$self}{columns}){
- $columns = ${$self}{columns};
- } elsif(ref ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns} eq "HASH"){
- if(defined ${${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns}}{default}){
- $columns = ${${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns}}{default};
- } else {
- $columns = 80;
- }
- } elsif (defined ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns}){
- $columns = ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns} ;
- } else {
- $columns = 80;
- }
-
- # vital Text::Wrap options
- $Text::Wrap::columns=$columns;
- $Text::Wrap::huge = ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{huge};
-
- # all other Text::Wrap options not usually needed/helpful, but available
- $Text::Wrap::separator=${$mainSettings{modifyLineBreaks}{textWrapOptions}}{separator} if(${$mainSettings{modifyLineBreaks}{textWrapOptions}}{separator} ne '');
- $Text::Wrap::break = ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{break} if ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{break};
- $Text::Wrap::unexpand = ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{unexpand} if ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{unexpand};
- $Text::Wrap::tabstop = ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{tabstop} if ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{tabstop};
-
- # perform the text wrapping
- ${$self}{body} = wrap('','',${$self}{body});
-
- ${$self}{body} =~ s/${$_}{tmpVerbatimID}/${$_}{origVerbatimID}/s foreach (@putVerbatimBackIn);
}
-sub construct_paragraph_reg_exp{
- my $self = shift;
-
- $logger->trace("*Constructing the paragraph-stop regexp (see paragraphsStopAt)") if $is_t_switch_active ;
- my $stopAtRegExp = q();
- while( my ($paragraphStopAt,$yesNo)= each %{${$mainSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{paragraphsStopAt}}){
- if($yesNo){
- # the headings (chapter, section, etc) need a slightly special treatment
- $paragraphStopAt = "afterHeading" if($paragraphStopAt eq "heading");
-
- # the comment need a slightly special treatment
- $paragraphStopAt = "trailingComment" if($paragraphStopAt eq "comments");
-
- # output to log file
- $logger->trace("The paragraph-stop regexp WILL include $tokens{$paragraphStopAt} (see paragraphsStopAt)") if $is_t_switch_active ;
-
- # update the regexp
- if($paragraphStopAt eq "items"){
- $stopAtRegExp .= "|(?:\\\\(?:".$listOfItems."))";
- } else {
- $stopAtRegExp .= "|(?:".($paragraphStopAt eq "trailingComment" ? "%" : q() ).$tokens{$paragraphStopAt}."\\d+)";
- }
- } else {
- $logger->trace("The paragraph-stop regexp won't include $tokens{$paragraphStopAt} (see paragraphsStopAt)") if ($tokens{$paragraphStopAt} and $is_t_switch_active);
- }
- }
-
- $paragraphRegExp = qr/
- ^
- (?!$tokens{beginOfToken})
- (\w
- (?:
- (?!
- (?:$tokens{blanklines}|\\par)
- ).
- )*?
- )
- (
- (?:
- ^(?:(\h*\R)|\\par|$tokens{blanklines}$stopAtRegExp)
- )
- |
- \z # end of string
- )/sxm;
-
- $logger->trace("The paragraph-stop-regexp is:") if $is_tt_switch_active ;
- $logger->trace($paragraphRegExp) if $is_tt_switch_active ;
-}
-
-sub remove_paragraph_line_breaks{
- my $self = shift;
- return unless ${$self}{removeParagraphLineBreaks};
-
- # alignment at ampersand can take priority
- return if(${$self}{lookForAlignDelims} and ${$mainSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{alignAtAmpersandTakesPriority});
-
- $logger->trace("Checking ${$self}{name} for paragraphs (see removeParagraphLineBreaks)") if $is_t_switch_active;
-
- my $paragraphCounter;
- my @paragraphStorage;
-
- ${$self}{body} =~ s/$paragraphRegExp/
- $paragraphCounter++;
- push(@paragraphStorage,{id=>$tokens{paragraph}.$paragraphCounter.$tokens{endOfToken},value=>$1});
-
- # replace comment with dummy text
- $tokens{paragraph}.$paragraphCounter.$tokens{endOfToken}.$2;
- /xsmeg;
-
- while( my $paragraph = pop @paragraphStorage){
- # remove all line breaks from paragraph, except for any at the very end
- ${$paragraph}{value} =~ s/\R(?!\z)/ /sg;
- ${$self}{body} =~ s/${$paragraph}{id}/${$paragraph}{value}/;
- }
-}
-
-
1;
diff --git a/support/latexindent/LatexIndent/Preamble.pm b/support/latexindent/LatexIndent/Preamble.pm
index eab45a10d9..bade8d42d1 100644
--- a/support/latexindent/LatexIndent/Preamble.pm
+++ b/support/latexindent/LatexIndent/Preamble.pm
@@ -51,23 +51,6 @@ sub indent{
sub tasks_particular_to_each_object{
my $self = shift;
- # text wrapping, remove paragraph line breaks
- if ($is_m_switch_active){
- $self->yaml_get_textwrap_removeparagraphline_breaks;
- }
-
- # option to textWrap beforeFindingChildCodeBlocks
- if( $is_m_switch_active and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{beforeFindingChildCodeBlocks} == 1){
- # call the remove_paragraph_line_breaks and text_wrap routines
- if(${$mainSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{beforeTextWrap}){
- $self->remove_paragraph_line_breaks if ${$self}{removeParagraphLineBreaks};
- $self->text_wrap if (${$self}{textWrapOptions} and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
- } else {
- $self->text_wrap if (${$self}{textWrapOptions} and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
- $self->remove_paragraph_line_breaks if ${$self}{removeParagraphLineBreaks};
- }
- }
-
# search for environments
$self->find_environments if ${$self}{body} =~ m/$environmentBasicRegExp/;
@@ -87,19 +70,6 @@ sub tasks_particular_to_each_object{
# search for special begin/end
$self->find_special if ${$self}{body} =~ m/$specialBeginBasicRegExp/s;
}
-
- # text wrapping, remove paragraph line breaks
- if ($is_m_switch_active and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{beforeFindingChildCodeBlocks} == 0){
- # call the remove_paragraph_line_breaks and text_wrap routines
- if(${$mainSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{beforeTextWrap}){
- $self->remove_paragraph_line_breaks if ${$self}{removeParagraphLineBreaks};
- $self->text_wrap if (${$self}{textWrapOptions} and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
- } else {
- $self->text_wrap if (${$self}{textWrapOptions} and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
- $self->remove_paragraph_line_breaks if ${$self}{removeParagraphLineBreaks};
- }
- }
-
}
1;
diff --git a/support/latexindent/LatexIndent/Sentence.pm b/support/latexindent/LatexIndent/Sentence.pm
index d41c8869b6..9370f55886 100644
--- a/support/latexindent/LatexIndent/Sentence.pm
+++ b/support/latexindent/LatexIndent/Sentence.pm
@@ -251,8 +251,7 @@ sub one_sentence_per_line{
);
# text wrapping
- $sentenceObj->yaml_get_columns;
- if(${$sentenceObj}{columns}<=0){
+ if(${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns}==0){
$logger->warn("*Sentence text wrap warning:");
$logger->info("You have specified oneSentencePerLine:textWrapSentences, but columns is set to 0");
$logger->info("You might wish to specify, for example: modifyLineBreaks: textWrapOptions: columns: 80");
@@ -305,8 +304,8 @@ sub tasks_particular_to_each_object{
my $self = shift;
# option to text wrap (and option to indent) sentences
- if(${$mainSettings{modifyLineBreaks}{oneSentencePerLine}}{textWrapSentences}){
- $self->yaml_get_columns;
+ if(${$mainSettings{modifyLineBreaks}{oneSentencePerLine}}{textWrapSentences}
+ and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns} !=0 ){
$self->text_wrap;
}
diff --git a/support/latexindent/LatexIndent/Tokens.pm b/support/latexindent/LatexIndent/Tokens.pm
index 2e358e0b62..98926a9759 100644
--- a/support/latexindent/LatexIndent/Tokens.pm
+++ b/support/latexindent/LatexIndent/Tokens.pm
@@ -48,6 +48,7 @@ our %tokens = (
arguments=>$beginningToken."ARGUMENTS",
roundBracket=>$beginningToken."ROUND-BRACKET",
verbatim=>$beginningToken."VERBATIM",
+ verbatimInline=>$beginningToken."VERBATIM-inline",
preamble=>$beginningToken."preamble",
beginOfToken=>$beginningToken,
doubleBackSlash=>$beginningToken."DOUBLEBACKSLASH",
diff --git a/support/latexindent/LatexIndent/TrailingComments.pm b/support/latexindent/LatexIndent/TrailingComments.pm
index 7d03349c52..82ff154c87 100644
--- a/support/latexindent/LatexIndent/TrailingComments.pm
+++ b/support/latexindent/LatexIndent/TrailingComments.pm
@@ -99,7 +99,9 @@ sub put_trailing_comments_back_in{
# the -m switch can modify max characters per line, and trailing comment IDs can
# be split across lines
- if($is_m_switch_active and ${$self}{body} !~ m/%$trailingcommentID/m){
+ if($is_m_switch_active
+ and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{huge} ne "overflow"
+ and ${$self}{body} !~ m/%$trailingcommentID/m){
$logger->trace("$trailingcommentID not found in body using /m matching, assuming it has been split across line (see modifyLineBreaks: textWrapOptions)") if($is_t_switch_active);
my $trailingcommentIDwithLineBreaks;
@@ -126,6 +128,8 @@ sub put_trailing_comments_back_in{
/mx and $1 ne ''){
$logger->trace("Comment not at end of line $trailingcommentID, moving it to end of line")if $is_t_switch_active;
${$self}{body} =~ s/%$trailingcommentID(.*)$/$1%$trailingcommentValue/m;
+ #####if(${$self}{body} =~ m/%$trailingcommentID\h*[^%]+?$/mx){
+ ##### $logger->trace("Comment not at end of line $trailingcommentID, moving it to end of line") if $is_t_switch_active;
} else {
${$self}{body} =~ s/%$trailingcommentID/%$trailingcommentValue/;
}
diff --git a/support/latexindent/LatexIndent/Verbatim.pm b/support/latexindent/LatexIndent/Verbatim.pm
index 0bb41c5227..edff0698a8 100644
--- a/support/latexindent/LatexIndent/Verbatim.pm
+++ b/support/latexindent/LatexIndent/Verbatim.pm
@@ -332,6 +332,13 @@ sub find_verbatim_commands{
# output, if desired
$logger->trace(Dumper($verbatimCommand),'ttrace') if($is_tt_switch_active);
+ # check for nested verbatim commands
+ if(${$verbatimCommand}{body} =~ m/($tokens{verbatimInline}\d+$tokens{endOfToken})/s){
+ my $verbatimNestedID = $1;
+ my $verbatimBody = ${$verbatimStorage{$verbatimNestedID}}{begin}.${$verbatimStorage{$verbatimNestedID}}{body}.${$verbatimStorage{$verbatimNestedID}}{end};
+ ${$verbatimCommand}{body} =~ s/$verbatimNestedID/$verbatimBody/s;
+ delete $verbatimStorage{$verbatimNestedID};
+ }
# verbatim children go in special hash
$verbatimStorage{${$verbatimCommand}{id}}=$verbatimCommand;
@@ -534,7 +541,7 @@ sub create_unique_id{
my $self = shift;
$verbatimCounter++;
- ${$self}{id} = "$tokens{verbatim}$verbatimCounter$tokens{endOfToken}";
+ ${$self}{id} = (${$self}{type} eq 'command' ? $tokens{verbatimInline} : $tokens{verbatim}).$verbatimCounter.$tokens{endOfToken};
return;
}
diff --git a/support/latexindent/LatexIndent/Version.pm b/support/latexindent/LatexIndent/Version.pm
index 313d0ffb02..7727a270e9 100644
--- a/support/latexindent/LatexIndent/Version.pm
+++ b/support/latexindent/LatexIndent/Version.pm
@@ -19,6 +19,6 @@ use warnings;
use Exporter qw/import/;
our @EXPORT_OK = qw/$versionNumber $versionDate/;
-our $versionNumber = '3.15';
-our $versionDate = '2022-01-21';
+our $versionNumber = '3.16';
+our $versionDate = '2022-03-13';
1
diff --git a/support/latexindent/LatexIndent/Wrap.pm b/support/latexindent/LatexIndent/Wrap.pm
new file mode 100644
index 0000000000..a2b8383d94
--- /dev/null
+++ b/support/latexindent/LatexIndent/Wrap.pm
@@ -0,0 +1,317 @@
+package LatexIndent::Wrap;
+# 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
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# See http://www.gnu.org/licenses/.
+#
+# Chris Hughes, 2017
+#
+# For all communication, please visit: https://github.com/cmhughes/latexindent.pl
+use strict;
+use warnings;
+use Text::Wrap;
+use LatexIndent::Tokens qw/%tokens/;
+use LatexIndent::TrailingComments qw/$trailingCommentRegExp/;
+use LatexIndent::GetYamlSettings qw/%mainSettings/;
+use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active $is_m_switch_active/;
+use LatexIndent::LogFile qw/$logger/;
+use LatexIndent::Verbatim qw/%verbatimStorage/;
+use Exporter qw/import/;
+our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321
+our @EXPORT_OK = qw/text_wrap/;
+our $sentenceCounter;
+
+sub text_wrap{
+ my $self = shift;
+
+ $logger->trace("*Text wrap regular expression construction: (see textWrapOptions: )") if $is_t_switch_active;
+
+ # textWrap Blocks FOLLOW
+ # textWrap Blocks FOLLOW
+ # textWrap Blocks FOLLOW
+ my $blocksFollow = q();
+ my $blocksFollowHash = \%{${$mainSettings{modifyLineBreaks}{textWrapOptions}}{blocksFollow}};
+
+ foreach my $blocksFollowEachPart (sort keys %{$blocksFollowHash}) {
+ my $yesNo = $blocksFollowHash->{$blocksFollowEachPart};
+ if($yesNo){
+ if($blocksFollowEachPart eq "par"){
+ $blocksFollowEachPart = qr/\R?\\par/s;
+ } elsif ($blocksFollowEachPart eq "blankLine"){
+ $blocksFollowEachPart = qr/
+ (?:\A(?:$tokens{blanklines}\R)+) # the order of each of these
+ | # is important, as (like always) the first
+ (?:\G(?:$tokens{blanklines}\R)+) # thing to be matched will
+ | # be accepted
+ (?:(?:$tokens{blanklines}\h*\R)+)
+ |
+ \R{2,}
+ |
+ \G
+ /sx;
+ } elsif ($blocksFollowEachPart eq "commentOnPreviousLine"){
+ $blocksFollowEachPart = qr/^$trailingCommentRegExp/m;
+ } elsif ($blocksFollowEachPart eq "verbatim"){
+ $blocksFollowEachPart = qr/$tokens{verbatim}\d+$tokens{endOfToken}/;
+ } elsif ($blocksFollowEachPart eq "filecontents"){
+ $blocksFollowEachPart = qr/$tokens{filecontents}\d+$tokens{endOfToken}/;
+ } elsif ($blocksFollowEachPart eq "headings"){
+ $blocksFollowEachPart = q();
+
+ my %headingsLevels = %{$mainSettings{indentAfterHeadings}};
+ while( my ($headingName,$headingInfo)= each %headingsLevels){
+ # check for a * in the name
+ $headingName =~ s/\*/\\\*/g;
+
+ # make the regex as
+ #
+ # headingName
+ # <hspace> # possible horizontal space
+ # []? # possible optional argument
+ # <hspace> # possible horizontal space
+ # {} # mandatory argument
+ #
+ $headingName = qr/\\$headingName\h*(?:\[[^]]*?\])?\h*\{[^}]*?\}\h*(?:\\label\{[^}]*?\})?/m;
+
+ # put starred headings at the front of the regexp
+ if($headingName =~ m/\*/){
+ $blocksFollowEachPart = $headingName.($blocksFollowEachPart eq '' ?q():"|$blocksFollowEachPart");
+ } else {
+ $blocksFollowEachPart .= ($blocksFollowEachPart eq '' ?q():"|").$headingName ;
+ }
+ }
+ } elsif ($blocksFollowEachPart eq "other"){
+ $blocksFollowEachPart = qr/$yesNo/x;
+ }
+ $blocksFollow .= ($blocksFollow eq '' ? q() : "|").qr/$blocksFollowEachPart/sx;
+ }
+ }
+
+ # if blankLine is not active from blocksFollow then we need to set up the
+ # beginning of the string, but make sure that it is *not* followed by a
+ # blank line token, or a blank line
+ if(!${${$mainSettings{modifyLineBreaks}{textWrapOptions}}{blocksFollow}}{blankLine}){
+ $blocksFollow .= ($blocksFollow eq '' ? q() : "|").
+ qr/
+ \G
+ (?!$tokens{blanklines})
+ /sx;
+ }
+
+ # followed by 0 or more h-space and line breaks
+ $blocksFollow = ($blocksFollow eq '' ? q() : qr/(?:$blocksFollow)(?:\h|\R)*/sx );
+
+ $logger->trace("textWrap blocks follow regexp:") if $is_tt_switch_active;
+ $logger->trace($blocksFollow) if $is_tt_switch_active;
+
+ # textWrap Blocks BEGIN with
+ # textWrap Blocks BEGIN with
+ # textWrap Blocks BEGIN with
+ my $blocksBeginWith = q();
+ my $blocksBeginWithHash = \%{${$mainSettings{modifyLineBreaks}{textWrapOptions}}{blocksBeginWith}};
+
+ foreach my $blocksBeginWithEachPart (sort keys %{$blocksBeginWithHash}) {
+ my $yesNo = $blocksBeginWithHash->{$blocksBeginWithEachPart};
+ if($yesNo){
+ if($blocksBeginWithEachPart eq "A-Z"){
+ $logger->trace("textWrap Blocks BEGINS with capital letters (see textWrap:blocksBeginWith:A-Z)") if $is_t_switch_active;
+ $blocksBeginWithEachPart = qr/(?!(?:$tokens{blanklines}|$tokens{verbatim}|$tokens{preamble}))[A-Z]/;
+ } elsif ($blocksBeginWithEachPart eq "a-z"){
+ $logger->trace("textWrap Blocks BEGINS with lower-case letters (see textWrap:blocksBeginWith:a-z)") if $is_t_switch_active;
+ $blocksBeginWithEachPart = qr/[a-z]/;
+ } elsif ($blocksBeginWithEachPart eq "0-9"){
+ $logger->trace("textWrap Blocks BEGINS with numbers (see textWrap:blocksBeginWith:0-9)") if $is_t_switch_active;
+ $blocksBeginWithEachPart = qr/[0-9]/;
+ } elsif ($blocksBeginWithEachPart eq "other"){
+ $logger->trace("textWrap Blocks BEGINS with other $yesNo (reg exp) (see textWrap:blocksBeginWith:other)") if $is_t_switch_active;
+ $blocksBeginWithEachPart = qr/$yesNo/;
+ }
+ $blocksBeginWith .= ($blocksBeginWith eq "" ? q(): "|" ).$blocksBeginWithEachPart;
+ }
+ }
+ $blocksBeginWith = qr/$blocksBeginWith/;
+
+ # textWrap Blocks END with
+ # textWrap Blocks END with
+ # textWrap Blocks END with
+ my $blocksEndBefore = q();
+ my $blocksEndBeforeHash = \%{${$mainSettings{modifyLineBreaks}{textWrapOptions}}{blocksEndBefore}};
+
+ foreach my $blocksEndBeforeEachPart (sort keys %{$blocksEndBeforeHash}) {
+ my $yesNo = $blocksEndBeforeHash->{$blocksEndBeforeEachPart};
+ if($yesNo){
+ if ($blocksEndBeforeEachPart eq "other"){
+ $logger->trace("textWrap Blocks ENDS with other $yesNo (reg exp) (see textWrap:blocksEndBefore:other)") if $is_t_switch_active;
+ $blocksEndBeforeEachPart = qr/\R?$yesNo/;
+ } elsif ($blocksEndBeforeEachPart eq "commentOnOwnLine"){
+ $logger->trace("textWrap Blocks ENDS with commentOnOwnLine (see textWrap:blocksEndBefore:commentOnOwnLine)") if $is_t_switch_active;
+ $blocksEndBeforeEachPart = qr/^$trailingCommentRegExp/m;
+ } elsif ($blocksEndBeforeEachPart eq "verbatim"){
+ $logger->trace("textWrap Blocks ENDS with verbatim (see textWrap:blocksEndBefore:verbatim)") if $is_t_switch_active;
+ $blocksEndBeforeEachPart = qr/$tokens{verbatim}\d/;
+ } elsif ($blocksEndBeforeEachPart eq "filecontents"){
+ $logger->trace("textWrap Blocks ENDS with filecontents (see textWrap:blocksEndBefore:filecontents)") if $is_t_switch_active;
+ $blocksEndBeforeEachPart = qr/$tokens{filecontents}/;
+ }
+ $blocksEndBefore .= ($blocksEndBefore eq "" ? q(): "|" ).$blocksEndBeforeEachPart;
+ }
+ }
+ $blocksEndBefore = qr/$blocksEndBefore/;
+
+ # the OVERALL textWrap Blocks regexp
+ # the OVERALL textWrap Blocks regexp
+ # the OVERALL textWrap Blocks regexp
+ $logger->trace("Overall textWrap Blocks end with regexp:") if $is_tt_switch_active;
+ $logger->trace($blocksEndBefore) if $is_tt_switch_active;
+
+ # store the text wrap blocks
+ my @textWrapBlockStorage = split(/($blocksFollow)/,${$self}{body});
+
+ # sentences need special treatment
+ if (${$self}{modifyLineBreaksYamlName} eq 'sentence'){
+ @textWrapBlockStorage = (${$self}{body});
+ }
+
+ # call the text wrapping routine
+ my $columns = ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns};
+
+ # vital Text::Wrap options
+ $Text::Wrap::columns=$columns;
+ $Text::Wrap::huge = ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{huge};
+
+ # all other Text::Wrap options not usually needed/helpful, but available
+ $Text::Wrap::separator = ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{separator} if(${$mainSettings{modifyLineBreaks}{textWrapOptions}}{separator} ne '');
+ $Text::Wrap::break = ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{break} if ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{break};
+ $Text::Wrap::unexpand = ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{unexpand} if ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{unexpand};
+ $Text::Wrap::tabstop = ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{tabstop} if ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{tabstop};
+
+ # clear the body, which will be updated with newly wrapped body
+ ${$self}{body} = q();
+
+ # loop back through the text wrap block storage
+ foreach my $textWrapBlockStorageValue (@textWrapBlockStorage){
+ if ($textWrapBlockStorageValue =~ m/^\s*$blocksBeginWith/s or ${$self}{modifyLineBreaksYamlName} eq 'sentence') {
+
+ # LIMIT is one greater than the maximum number of times EXPR may be split
+ my @textWrapBeforeEndWith = split(/($blocksEndBefore)/,$textWrapBlockStorageValue,2);
+
+ # sentences need special treatment
+ if (${$self}{modifyLineBreaksYamlName} eq 'sentence'){
+ @textWrapBeforeEndWith = ();
+ }
+
+ # if we have an occurence of blocksEndBefore, then grab the stuff before it
+ if (scalar @textWrapBeforeEndWith > 1){
+ $textWrapBlockStorageValue = $textWrapBeforeEndWith[0];
+ }
+
+ $logger->trace("TEXTWRAP BLOCK: $textWrapBlockStorageValue") if $is_tt_switch_active;
+
+ # initiate the trailing comments storage
+ my $trailingComments = q();
+
+ # grab all *internal* trailing comments from the block
+ while($textWrapBlockStorageValue =~ m|$trailingCommentRegExp|){
+ $textWrapBlockStorageValue =~ s|(\h*$trailingCommentRegExp)||s;
+ $trailingComments .= $1;
+ }
+
+ # remove internal line breaks
+ $textWrapBlockStorageValue =~ s/\R(?!\Z)/ /sg;
+
+ # convert multiple spaces into single
+ $textWrapBlockStorageValue =~ s/\h{2,}/ /sg if ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{multipleSpacesToSingle};
+
+ # goal: get an accurate measurement of verbatim objects;
+ #
+ # example:
+ # Lorem \verb!x+y! ipsum dolor sit amet
+ #
+ # is represented as
+ #
+ # Lorem LTXIN-TK-VERBATIM1-END ipsum dolor sit amet
+ #
+ # so we *measure* the verbatim token and replace it with
+ # an appropriate-length string
+ #
+ # Lorem a2A41233rt ipsum dolor sit amet
+ #
+ # and then put the body back to
+ #
+ # Lorem LTXIN-TK-VERBATIM1-END ipsum dolor sit amet
+ #
+ # following the text wrapping
+ my @putVerbatimBackIn;
+
+ # check body for verbatim and get measurements
+ if ($textWrapBlockStorageValue =~ m/$tokens{verbatim}/s and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{huge} eq "overflow"){
+
+ # reference: https://stackoverflow.com/questions/10336660/in-perl-how-can-i-generate-random-strings-consisting-of-eight-hex-digits
+ my @set = ('0' ..'9', 'A' .. 'Z', 'a' .. 'z');
+
+ # loop through verbatim objects
+ while( my ($verbatimID,$child)= each %verbatimStorage){
+ my $verbatimThing = ${$child}{begin}.${$child}{body}.${$child}{end};
+
+ # if the object has line breaks, don't measure it
+ next if $verbatimThing =~ m/\R/s;
+
+ if($textWrapBlockStorageValue =~m/$verbatimID/s){
+
+ # measure length
+ my $verbatimLength = Unicode::GCString->new($verbatimThing)->columns();
+
+ # create temporary ID, and check that it is not contained in the body
+ my $verbatimTmpID = join '' => map $set[rand @set], 1 .. $verbatimLength;
+ while($textWrapBlockStorageValue=~m/$verbatimTmpID/s){
+ $verbatimTmpID = join '' => map $set[rand @set], 1 .. $verbatimLength;
+ }
+
+ # store for use after the text wrapping
+ push(@putVerbatimBackIn,{origVerbatimID=>$verbatimID,tmpVerbatimID=>$verbatimTmpID});
+
+ # make the substitution
+ $textWrapBlockStorageValue =~ s/$verbatimID/$verbatimTmpID/s;
+ }
+ }
+ }
+
+ # perform the text wrap routine
+ $textWrapBlockStorageValue = wrap('','',$textWrapBlockStorageValue) if ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns} > 0;
+
+ # append trailing comments from WITHIN the block
+ $textWrapBlockStorageValue =~ s/\R?$/$trailingComments\n/s if ($trailingComments ne '');
+
+ # append blocksEndBefore and the stuff following it
+ if (scalar @textWrapBeforeEndWith > 1){
+ $textWrapBlockStorageValue .= $textWrapBeforeEndWith[1].$textWrapBeforeEndWith[2];
+ }
+
+ # put blank line tokens on their own lines, should only happen when the following is used:
+ # blocksFollow:
+ # blankLine: 0
+ while ($textWrapBlockStorageValue =~ m/^\H.*?$tokens{blanklines}/m ){
+ $textWrapBlockStorageValue =~ s/^(\H.*?)$tokens{blanklines}/$1\n$tokens{blanklines}/m;
+ }
+
+ # remove surrounding spaces from blank line tokens
+ $textWrapBlockStorageValue =~ s/^\h*$tokens{blanklines}\h*/$tokens{blanklines}/mg;
+
+ # put verbatim back in
+ $textWrapBlockStorageValue=~ s/${$_}{tmpVerbatimID}/${$_}{origVerbatimID}/s foreach (@putVerbatimBackIn);
+ }
+
+ # update the body
+ ${$self}{body} .= $textWrapBlockStorageValue;
+ }
+
+}
+
+1;