summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2019-07-13 21:40:12 +0000
committerKarl Berry <karl@freefriends.org>2019-07-13 21:40:12 +0000
commit757d85974d6b7911f766ae371404144ec3bdce34 (patch)
tree795c61e735cf8826289bb477020f3e50ec5aa914 /Master/texmf-dist/scripts
parent8e8c05aa6d6db2c28633a8924de4a0b941b52030 (diff)
latexindent (13jul19)
git-svn-id: svn://tug.org/texlive/trunk@51635 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts')
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm21
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm42
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/LatexIndent/Command.pm11
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm64
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm45
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm56
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/FileExtension.pm15
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm19
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm4
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm83
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/LatexIndent/KeyEqualsValuesBraces.pm15
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm11
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/MandatoryArgument.pm4
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm204
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm19
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/OptionalArgument.pm4
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Replacement.pm89
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Sentence.pm2
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Switches.pm9
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/UnNamedGroupingBracesBrackets.pm18
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm4
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/defaultSettings.yaml198
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/latexindent.pl5
23 files changed, 631 insertions, 311 deletions
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm
index 7a4a9727c89..8b8e387d095 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm
@@ -27,7 +27,7 @@ use LatexIndent::GetYamlSettings qw/%masterSettings/;
use LatexIndent::Tokens qw/%tokens/;
use LatexIndent::LogFile qw/$logger/;
our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321
-our @EXPORT_OK = qw/align_at_ampersand find_aligned_block/;
+our @EXPORT_OK = qw/align_at_ampersand find_aligned_block double_back_slash_else/;
our $alignmentBlockCounter;
sub find_aligned_block{
@@ -258,7 +258,7 @@ sub align_at_ampersand{
}
# output some of the info so far to the log file
- $logger->trace("*Alignment at ampersand routine") if $is_t_switch_active;
+ $logger->trace("*Alignment at ampersand routine for ${$self}{name} (see lookForAlignDelims)") if $is_t_switch_active;
$logger->trace("Maximum column sizes of horizontally stripped formatted block (${$self}{name}): @maximumColumnWidth") if $is_t_switch_active;
$logger->trace("align at ampersand: ${$self}{lookForAlignDelims}") if $is_t_switch_active;
$logger->trace("align at \\\\: ${$self}{alignDoubleBackSlash}") if $is_t_switch_active;
@@ -505,4 +505,21 @@ sub align_at_ampersand{
${$self}{body} =~ s/\h*\R$//s if !${$self}{linebreaksAtEnd}{body};
}
+sub double_back_slash_else{
+ my $self = shift;
+
+ # check for existence of \\ statement, and associated line break information
+ $self->check_for_else_statement(
+ # else name regexp
+ elseNameRegExp=>qr/${${$masterSettings{fineTuning}}{modifyLineBreaks}}{doubleBackSlash}/,
+ # else statements name: note that DBS stands for 'Double Back Slash'
+ ElseStartsOnOwnLine=>"DBSStartsOnOwnLine",
+ # end statements
+ ElseFinishesWithLineBreak=>"DBSFinishesWithLineBreak",
+ # for the YAML settings storage
+ storageNameAppend=>"DBS",
+ # logfile information
+ logName=>"double-back-slash-block (for align at ampersand, see lookForAlignDelims)",
+ );
+}
1;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm
index 7c84a0e65f3..96450fdaaf2 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm
@@ -24,7 +24,7 @@ use LatexIndent::LogFile qw/$logger/;
use Data::Dumper;
use Exporter qw/import/;
our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321
-our @EXPORT_OK = qw/get_arguments_regexp find_opt_mand_arguments get_numbered_arg_regexp construct_arguments_regexp $optAndMandRegExp/;
+our @EXPORT_OK = qw/get_arguments_regexp find_opt_mand_arguments construct_arguments_regexp $optAndMandRegExp comma_else/;
our $ArgumentCounter;
our $optAndMandRegExp;
our $optAndMandRegExpWithLineBreaks;
@@ -222,13 +222,6 @@ sub create_unique_id{
return;
}
-sub get_numbered_arg_regexp{
-
- # for example #1 #2, etc
- my $numberedArgRegExp = qr/(?:#\d\h*;?,?\/?)+/;
- return $numberedArgRegExp;
-}
-
sub get_arguments_regexp{
my $self = shift;
@@ -240,11 +233,9 @@ sub get_arguments_regexp{
# some calls to this routine need to account for the linebreaks at the end, some do not
my $lineBreaksAtEnd = (defined ${input}{mode} and ${input}{mode} eq 'lineBreaksAtEnd')?'\R*':q();
- # for example #1 #2, etc
- my $numberedArgRegExp = $self->get_numbered_arg_regexp;
-
- # beamer special
- my $beamerRegExp = qr/\<.*?\>/;
+ # arguments Before, by default, includes beamer special and numbered arguments, for example #1 #2, etc
+ my $argumentsBefore = qr/${${$masterSettings{fineTuning}}{arguments}}{before}/;
+ my $argumentsBetween = qr/${${$masterSettings{fineTuning}}{arguments}}{between}/;
# commands are allowed strings between arguments, e.g node, decoration, etc, specified in stringsAllowedBetweenArguments
my $stringsBetweenArguments = q();
@@ -272,7 +263,7 @@ sub get_arguments_regexp{
return qr/
( # capture into $1
(?:
- (?:\h|\R|$blankLineToken|$trailingCommentRegExp|$numberedArgRegExp|$beamerRegExp|_|\^|$stringsBetweenArguments)*
+ (?:\h|\R|$blankLineToken|$trailingCommentRegExp|$argumentsBefore|$argumentsBetween|$stringsBetweenArguments)*
(?:
(?:
\h* # 0 or more spaces
@@ -332,7 +323,7 @@ sub get_arguments_regexp{
# NOT followed by
(?!
(?:
- (?:\h|\R|$blankLineToken|$trailingCommentRegExp|$numberedArgRegExp|$beamerRegExp|$stringsBetweenArguments)* # 0 or more h-space, blanklines, trailing comments
+ (?:\h|\R|$blankLineToken|$trailingCommentRegExp|$argumentsBefore|$stringsBetweenArguments)* # 0 or more h-space, blanklines, trailing comments
(?:
(?:(?<!\\)\[)
|
@@ -350,7 +341,7 @@ sub get_arguments_regexp{
return qr/
( # capture into $1
(?:
- (?:\h|\R|$blankLineToken|$trailingCommentRegExp|$numberedArgRegExp|$beamerRegExp|_|\^|$stringsBetweenArguments)*
+ (?:\h|\R|$blankLineToken|$trailingCommentRegExp|$argumentsBefore|$argumentsBetween|$stringsBetweenArguments)*
(?:
(?:
\h* # 0 or more spaces
@@ -383,7 +374,7 @@ sub get_arguments_regexp{
# NOT followed by
(?!
(?:
- (?:\h|\R|$blankLineToken|$trailingCommentRegExp|$numberedArgRegExp|$beamerRegExp)* # 0 or more h-space, blanklines, trailing comments
+ (?:\h|\R|$blankLineToken|$trailingCommentRegExp|$argumentsBefore)* # 0 or more h-space, blanklines, trailing comments
(?:
(?:(?<!\\)\[)
|
@@ -398,4 +389,21 @@ sub get_arguments_regexp{
}
}
+sub comma_else{
+ my $self = shift;
+
+ # check for existence of \\ statement, and associated line break information
+ $self->check_for_else_statement(
+ # else name regexp
+ elseNameRegExp=>qr/${${$masterSettings{fineTuning}}{modifyLineBreaks}}{comma}/,
+ # else statements name
+ ElseStartsOnOwnLine=>"CommaStartsOnOwnLine",
+ # end statements
+ ElseFinishesWithLineBreak=>"CommaFinishesWithLineBreak",
+ # for the YAML settings storage
+ storageNameAppend=>"comma",
+ # logfile information
+ logName=>"comma block, see CommaStartsOnOwnLine and CommaFinishesWithLineBreak",
+ );
+}
1;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Command.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Command.pm
index 2ba44bd5a62..a877a6295c1 100755
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Command.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Command.pm
@@ -64,11 +64,14 @@ sub construct_command_regexp{
# details to log file
$logger->trace("*The special command names regexp is: $commandNameSpecialRegExp (see commandNameSpecial)") if $is_t_switch_active;
+ # read from fine tuning
+ my $commandNameRegExp = qr/${${$masterSettings{fineTuning}}{commands}}{name}/;
+
# construct the command regexp
$commandRegExp = qr/
(\\|\\@|@)
(
- [+a-zA-Z@\*0-9_\:]+?|$commandNameSpecialRegExp # lowercase|uppercase letters, @, *, numbers
+ $commandNameRegExp|$commandNameSpecialRegExp # lowercase|uppercase letters, @, *, numbers
)
(\h*)
(\R*)?
@@ -203,4 +206,10 @@ sub align_at_ampersand{
return;
}
+sub double_back_slash_else{
+ # need an empty routine here for commands; see
+ # test-cases/alignment/command-align.tex for example
+ return;
+}
+
1;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm
index b4441b99455..7f6694d0493 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm
@@ -21,8 +21,9 @@ use utf8;
use open ':std', ':encoding(UTF-8)';
# gain access to subroutines in the following modules
-use LatexIndent::Switches qw/storeSwitches %switches $is_m_switch_active $is_t_switch_active $is_tt_switch_active/;
+use LatexIndent::Switches qw/storeSwitches %switches $is_m_switch_active $is_t_switch_active $is_tt_switch_active $is_r_switch_active $is_rr_switch_active $is_rv_switch_active/;
use LatexIndent::LogFile qw/processSwitches $logger/;
+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 %masterSettings yaml_get_columns/;
use LatexIndent::FileExtension qw/file_extension_check/;
use LatexIndent::BackUpFileProcedure qw/create_back_up_file/;
@@ -34,15 +35,15 @@ use LatexIndent::HorizontalWhiteSpace qw/remove_trailing_whitespace remove_leadi
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/;
+use LatexIndent::AlignmentAtAmpersand qw/align_at_ampersand find_aligned_block double_back_slash_else/;
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::Environment qw/find_environments $environmentBasicRegExp/;
+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/;
-use LatexIndent::Arguments qw/get_arguments_regexp find_opt_mand_arguments get_numbered_arg_regexp construct_arguments_regexp/;
+use LatexIndent::Arguments qw/get_arguments_regexp find_opt_mand_arguments construct_arguments_regexp comma_else/;
use LatexIndent::OptionalArgument qw/find_optional_arguments/;
use LatexIndent::MandatoryArgument qw/find_mandatory_arguments get_mand_arg_reg_exp/;
use LatexIndent::RoundBrackets qw/find_round_brackets/;
@@ -83,28 +84,34 @@ sub operate_on_file{
$self->create_back_up_file;
$self->token_check;
- $self->construct_regular_expressions;
- $self->find_noindent_block;
- $self->find_verbatim_commands;
- $self->find_aligned_block;
- $self->remove_trailing_comments;
- $self->find_verbatim_environments;
- $self->find_verbatim_special;
- $self->verbatim_modify_line_breaks if $is_m_switch_active;
- $self->text_wrap if ($is_m_switch_active and !${$masterSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis} and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}>1);
- $self->protect_blank_lines;
- $self->remove_trailing_whitespace(when=>"before");
- $self->find_file_contents_environments_and_preamble;
- $self->dodge_double_backslash;
- $self->remove_leading_space;
- $self->process_body_of_text;
- $self->remove_trailing_whitespace(when=>"after");
- $self->condense_blank_lines;
- $self->unprotect_blank_lines;
- $self->un_dodge_double_backslash;
- $self->put_verbatim_back_in (match=>"everything-except-commands");
- $self->put_trailing_comments_back_in;
- $self->put_verbatim_back_in (match=>"just-commands");
+ $self->make_replacements(when=>"before") if ($is_r_switch_active and !$is_rv_switch_active);
+ unless ($is_rr_switch_active){
+ $self->construct_regular_expressions;
+ $self->find_noindent_block;
+ $self->find_verbatim_commands;
+ $self->find_aligned_block;
+ $self->remove_trailing_comments;
+ $self->find_verbatim_environments;
+ $self->find_verbatim_special;
+ $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);
+ $self->protect_blank_lines;
+ $self->remove_trailing_whitespace(when=>"before");
+ $self->find_file_contents_environments_and_preamble;
+ $self->dodge_double_backslash;
+ $self->remove_leading_space;
+ $self->process_body_of_text;
+ $self->remove_trailing_whitespace(when=>"after");
+ $self->condense_blank_lines;
+ $self->unprotect_blank_lines;
+ $self->un_dodge_double_backslash;
+ $self->make_replacements(when=>"after") if $is_rv_switch_active;
+ $self->put_verbatim_back_in (match=>"everything-except-commands");
+ $self->put_trailing_comments_back_in;
+ $self->put_verbatim_back_in (match=>"just-commands");
+ $self->make_replacements(when=>"after") if ($is_r_switch_active and !$is_rv_switch_active);
+ }
$self->output_indented_text;
return
}
@@ -112,6 +119,7 @@ sub operate_on_file{
sub construct_regular_expressions{
my $self = shift;
$self->construct_trailing_comment_regexp;
+ $self->construct_environments_regexp;
$self->construct_ifelsefi_regexp;
$self->construct_list_of_items;
$self->construct_special_begin;
@@ -335,7 +343,7 @@ 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;
+ $self->modify_line_breaks_body if ($is_m_switch_active and defined ${$self}{BodyStartsOnOwnLine});
# modify line breaks end statements
$self->modify_line_breaks_end if $is_m_switch_active;
@@ -343,6 +351,8 @@ sub tasks_common_to_each_object{
# 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});
return;
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm
index 10b1cc4d41b..5a367c784fc 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm
@@ -55,27 +55,32 @@ sub check_for_else_statement{
while(${$self}{body} =~ m/$elseRegExp(\h*)($trailingCommentRegExp)?/){
${$self}{body} =~ s/$elseRegExp(\h*)($trailingCommentRegExp)?
/
- # create a new IfElseFi object
+ # create a new Else object
my $else = LatexIndent::Else->new(begin=>$1,
- name=>${$self}{name},
- storageNameAppend=>$input{storageNameAppend},
- body=>$3,
- end=>q(),
- linebreaksAtEnd=>{
- begin=>$2?1:0,
- body=>0,
- end=>0,
- },
- aliases=>{
- # begin statements
- BeginStartsOnOwnLine=>$input{ElseStartsOnOwnLine},
- # end statements
- BodyStartsOnOwnLine=>$input{ElseFinishesWithLineBreak},
- },
- modifyLineBreaksYamlName=>${$self}{modifyLineBreaksYamlName},
- endImmediatelyFollowedByComment=>0,
- horizontalTrailingSpace=>q(),
- );
+ name=>${$self}{name},
+ storageNameAppend=>$input{storageNameAppend},
+ body=>$3,
+ end=>q(),
+ linebreaksAtEnd=>{
+ begin=>$2?1:0,
+ body=>0,
+ end=>0,
+ },
+ aliases=>{
+ # begin statements
+ BeginStartsOnOwnLine=>$input{ElseStartsOnOwnLine},
+ # end statements
+ BodyStartsOnOwnLine=>$input{ElseFinishesWithLineBreak},
+ },
+ modifyLineBreaksYamlName=>${$self}{modifyLineBreaksYamlName},
+ endImmediatelyFollowedByComment=>0,
+ horizontalTrailingSpace=>q(),
+ # mandatory and optional arguments have a parent, which we need
+ # to detail for double back slash poly-switches
+ # (see test-cases alignment command-align.tex, for example)
+ parent=>(${$self}{parent}?${$self}{parent}:"none"),
+ );
+
# log file output
$logger->trace("*$input{logName} found: ${$self}{name}")if $is_t_switch_active;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm
index 2c74f47554e..401cbecbee2 100755
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm
@@ -28,35 +28,41 @@ use LatexIndent::Special qw/$specialBeginAndBracesBracketsBasicRegExp/;
use Data::Dumper;
use Exporter qw/import/;
our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321
-our @EXPORT_OK = qw/find_environments $environmentBasicRegExp/;
+our @EXPORT_OK = qw/find_environments $environmentBasicRegExp construct_environments_regexp/;
our $environmentCounter;
our $environmentBasicRegExp = qr/\\begin\{/;
+our $environmentRegExp;
# store the regular expresssion for matching and replacing the \begin{}...\end{} statements
-our $environmentRegExp = qr/
- (
- \\begin\{
- (
- [a-zA-Z@\*0-9_\\]+ # lowercase|uppercase letters, @, *, numbers
- ) # environment name captured into $2
- \} # \begin{<something>} statement
- \h* # horizontal space
- (\R*)? # possible line breaks (into $3)
- ) # begin statement captured into $1
- (
- (?: # cluster-only (), don't capture
- (?! # don't include \begin in the body
- (?:\\begin) # cluster-only (), don't capture
- ). # any character, but not \\begin
- )*? # non-greedy
- (\R*)? # possible line breaks (into $5)
- ) # environment body captured into $4
- (
- \\end\{\2\} # \end{<something>} statement
- ) # captured into $6
- (\h*)? # possibly followed by horizontal space
- (\R)? # possibly followed by a line break
- /sx;
+sub construct_environments_regexp{
+
+ # read from fine tuning
+ my $environmentNameRegExp = qr/${${$masterSettings{fineTuning}}{environments}}{name}/;
+ $environmentRegExp = qr/
+ (
+ \\begin\{
+ (
+ $environmentNameRegExp # lowercase|uppercase letters, @, *, numbers
+ ) # environment name captured into $2
+ \} # \begin{<something>} statement
+ \h* # horizontal space
+ (\R*)? # possible line breaks (into $3)
+ ) # begin statement captured into $1
+ (
+ (?: # cluster-only (), don't capture
+ (?! # don't include \begin in the body
+ (?:\\begin) # cluster-only (), don't capture
+ ). # any character, but not \\begin
+ )*? # non-greedy
+ (\R*)? # possible line breaks (into $5)
+ ) # environment body captured into $4
+ (
+ \\end\{\2\} # \end{<something>} statement
+ ) # captured into $6
+ (\h*)? # possibly followed by horizontal space
+ (\R)? # possibly followed by a line break
+ /sx;
+}
sub find_environments{
my $self = shift;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/FileExtension.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/FileExtension.pm
index 93f8016f030..716598de777 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/FileExtension.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/FileExtension.pm
@@ -35,28 +35,23 @@ sub file_extension_check{
# grab the filename
my $fileName = ${$self}{fileName};
+ # see if an extension exists for the fileName
+ my ($name,$dir,$ext) = fileparse($fileName,qr/\..[^.]*$/);
+
# grab the file extension preferences
my %fileExtensionPreference= %{$masterSettings{fileExtensionPreference}};
# sort the file extensions by preference
my @fileExtensions = sort { $fileExtensionPreference{$a} <=> $fileExtensionPreference{$b} } keys(%fileExtensionPreference);
- # get the base file name, allowing for different extensions (possibly no extension)
- my ($name, $dir, $ext) = fileparse($fileName, @fileExtensions);
+ # store the base name
${$self}{baseName} = $name;
- # check to make sure given file type is supported
- if( -e $fileName and !$ext ){
- my $message = "The file $fileName exists , but the extension does not correspond to any given in fileExtensionPreference; consinder updating fileExtensionPreference.";
- $logger->fatal("*$message");
- die($message);
- }
-
# if no extension, search according to fileExtensionPreference
if ($fileName ne "-"){
if (!$ext) {
$logger->info("*File extension work:");
- $logger->info("latexindent called to act upon $fileName with a file extension;\nsearching for file with an extension in the following order (see fileExtensionPreference):");
+ $logger->info("latexindent called to act upon $fileName without a file extension;\nsearching for file with an extension in the following order (see fileExtensionPreference):");
$logger->info(join("\n",@fileExtensions));
my $fileFound = 0;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm
index 97cb36df823..3029043f23f 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm
@@ -256,6 +256,23 @@ sub yaml_read_settings{
}
}
}
+ } elsif (ref($firstLevelValue) eq "ARRAY") {
+ # update amalgamate in master settings
+ if(ref(${$firstLevelValue}[0]) eq "HASH" and defined ${$firstLevelValue}[0]{amalgamate}){
+ ${$masterSettings{$firstLevelKey}[0]}{amalgamate} = ${$firstLevelValue}[0]{amalgamate};
+ shift @{$firstLevelValue} if ${$masterSettings{$firstLevelKey}[0]}{amalgamate};
+ }
+
+ # if amalgamate is set to 1, then append
+ if(${$masterSettings{$firstLevelKey}[0]}{amalgamate}){
+ # loop through the other settings
+ foreach (@{$firstLevelValue}){
+ push (@{$masterSettings{$firstLevelKey}},$_);
+ }
+ } else {
+ # otherwise overwrite
+ $masterSettings{$firstLevelKey} = $firstLevelValue;
+ }
} else {
$masterSettings{$firstLevelKey} = $firstLevelValue;
}
@@ -375,7 +392,7 @@ sub yaml_read_settings{
# loop through each of the settings specified in the -y switch
foreach(@yamlSettings){
# split each value at semi-colon
- my (@keysValues) = split(/(?<!\\):/,$_);
+ my (@keysValues) = split(/(?<!(?:\\|\[)):(?!\])/,$_);
# $value will always be the last element
my $value = $keysValues[-1];
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm
index 29a0065bfe6..056b36d8c3e 100755
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm
@@ -17,6 +17,7 @@ package LatexIndent::IfElseFi;
use strict;
use warnings;
use LatexIndent::Tokens qw/%tokens/;
+use LatexIndent::GetYamlSettings qw/%masterSettings/;
use LatexIndent::TrailingComments qw/$trailingCommentRegExp/;
use LatexIndent::Switches qw/$is_m_switch_active $is_t_switch_active $is_tt_switch_active/;
use LatexIndent::LogFile qw/$logger/;
@@ -33,10 +34,11 @@ our $ifElseFiBasicRegExp = qr/\\if/;
# note: we search for \else separately in an attempt to keep this regexp a little more managable
sub construct_ifelsefi_regexp{
+ my $ifElseFiNameRegExp = qr/${${$masterSettings{fineTuning}}{ifElseFi}}{name}/;
$ifElseFiRegExp = qr/
(
\\
- (@?if[a-zA-Z@]*?)
+ ($ifElseFiNameRegExp)
\h*
(\R*)
) # begin statement, e.g \ifnum, \ifodd
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm
index fce49e2c660..eb36db21082 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm
@@ -325,40 +325,57 @@ sub indent_children_recursively{
if(defined ${$child}{BeginStartsOnOwnLine}){
my $BeginStringLogFile = ${$child}{aliases}{BeginStartsOnOwnLine}||"BeginStartsOnOwnLine";
- # if the child ID is not the first character and BeginStartsOnOwnLine>=1
- # then we will need to add a line break (==1), a comment (==2) or another blank line (==3)
- if(${$child}{BeginStartsOnOwnLine}>=1 and !$IDFirstNonWhiteSpaceCharacter){
- # by default, assume that no trailing comment token is needed
- my $trailingCharacterToken = q();
- if(${$child}{BeginStartsOnOwnLine}==2){
- $logger->trace("Removing space immediately before ${$child}{id}, in preparation for adding % ($BeginStringLogFile == 2)") if $is_t_switch_active;
- ${$self}{body} =~ s/\h*${$child}{idRegExp}/${$child}{id}/s;
- $logger->trace("Adding a % at the end of the line that ${$child}{begin} is on, then a linebreak ($BeginStringLogFile == 2)") if $is_t_switch_active;
- $trailingCharacterToken = "%".$self->add_comment_symbol;
- } elsif (${$child}{BeginStartsOnOwnLine}==3){
- $logger->trace("Adding a blank line at the end of the line that ${$child}{begin} is on, then a linebreak ($BeginStringLogFile == 3)") if $is_t_switch_active;
- $trailingCharacterToken = "\n".(${$masterSettings{modifyLineBreaks}}{preserveBlankLines}?$tokens{blanklines}:q());
- } else {
- $logger->trace("Adding a linebreak at the beginning of ${$child}{begin} (see $BeginStringLogFile)") if $is_t_switch_active;
+ #
+ # Blank line poly-switch notes (==4)
+ #
+ # when BeginStartsOnOwnLine=4 we adopt the following approach:
+ # temporarily change BeginStartsOnOwnLine to -1, make adjustments
+ # temporarily change BeginStartsOnOwnLine to 3, make adjustments
+ #
+ # we use an array, @polySwitchValues to facilitate this
+ my @polySwitchValues = (${$child}{BeginStartsOnOwnLine}==4)?(-1,3):(${$child}{BeginStartsOnOwnLine});
+
+ foreach(@polySwitchValues){
+ # if BeginStartsOnOwnLine is 4, then we hack
+ # $IDFirstNonWhiteSpaceCharacter
+ # to be 0 on the second time through (poly-switch set to 3)
+ $IDFirstNonWhiteSpaceCharacter = 0 if (${$child}{BeginStartsOnOwnLine}==4 and $_==3);
+
+ # if the child ID is not the first character and BeginStartsOnOwnLine>=1
+ # then we will need to add a line break (==1), a comment (==2) or another blank line (==3)
+ if($_>=1 and !$IDFirstNonWhiteSpaceCharacter){
+ # by default, assume that no trailing comment token is needed
+ my $trailingCharacterToken = q();
+ if($_==2){
+ $logger->trace("Removing space immediately before ${$child}{id}, in preparation for adding % ($BeginStringLogFile == 2)") if $is_t_switch_active;
+ ${$self}{body} =~ s/\h*${$child}{idRegExp}/${$child}{id}/s;
+ $logger->trace("Adding a % at the end of the line that ${$child}{begin} is on, then a linebreak ($BeginStringLogFile == 2)") if $is_t_switch_active;
+ $trailingCharacterToken = "%".$self->add_comment_symbol;
+ } elsif ($_==3){
+ $logger->trace("Adding a blank line at the end of the line that ${$child}{begin} is on, then a linebreak ($BeginStringLogFile == 3)") if $is_t_switch_active;
+ $trailingCharacterToken = "\n".(${$masterSettings{modifyLineBreaks}}{preserveBlankLines}?$tokens{blanklines}:q());
+ } else {
+ $logger->trace("Adding a linebreak at the beginning of ${$child}{begin} (see $BeginStringLogFile)") if $is_t_switch_active;
+ }
+
+ # the trailing comment/linebreak magic
+ ${$child}{begin} = "$trailingCharacterToken\n".${$child}{begin};
+ $child->add_surrounding_indentation_to_begin_statement;
+
+ # remove surrounding indentation ahead of %
+ ${$child}{begin} =~ s/^(\h*)%/%/ if($_==2);
+ } elsif ($_==-1 and $IDFirstNonWhiteSpaceCharacter){
+ # finally, if BeginStartsOnOwnLine == -1 then we might need to *remove* a blank line(s)
+ # important to check we don't move the begin statement next to a blank-line-token
+ my $blankLineToken = $tokens{blanklines};
+ if(${$self}{body} !~ m/$blankLineToken\R*\h*${$child}{idRegExp}/s){
+ $logger->trace("Removing linebreak before ${$child}{begin} (see $BeginStringLogFile in ${$child}{modifyLineBreaksYamlName} YAML)") if $is_t_switch_active;
+ ${$self}{body} =~ s/(\h*)(?:\R*|\h*)+${$child}{idRegExp}/$1${$child}{id}/s;
+ } else {
+ $logger->trace("Not removing linebreak ahead of ${$child}{begin}, as blank-line-token present (see preserveBlankLines)") if $is_t_switch_active;
+ }
}
-
- # the trailing comment/linebreak magic
- ${$child}{begin} = "$trailingCharacterToken\n".${$child}{begin};
- $child->add_surrounding_indentation_to_begin_statement;
-
- # remove surrounding indentation ahead of %
- ${$child}{begin} =~ s/^(\h*)%/%/ if(${$child}{BeginStartsOnOwnLine}==2);
- } elsif (${$child}{BeginStartsOnOwnLine}==-1 and $IDFirstNonWhiteSpaceCharacter){
- # finally, if BeginStartsOnOwnLine == -1 then we might need to *remove* a blank line(s)
- # important to check we don't move the begin statement next to a blank-line-token
- my $blankLineToken = $tokens{blanklines};
- if(${$self}{body} !~ m/$blankLineToken\R*\h*${$child}{idRegExp}/s){
- $logger->trace("Removing linebreak before ${$child}{begin} (see $BeginStringLogFile in ${$child}{modifyLineBreaksYamlName} YAML)") if $is_t_switch_active;
- ${$self}{body} =~ s/(\h*)(?:\R*|\h*)+${$child}{idRegExp}/$1${$child}{id}/s;
- } else {
- $logger->trace("Not removing linebreak ahead of ${$child}{begin}, as blank-line-token present (see preserveBlankLines)") if $is_t_switch_active;
- }
- }
+ }
}
$logger->trace(Dumper(\%{$child})) if($is_tt_switch_active);
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/KeyEqualsValuesBraces.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/KeyEqualsValuesBraces.pm
index 0e939731015..590d9acb8c5 100755
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/KeyEqualsValuesBraces.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/KeyEqualsValuesBraces.pm
@@ -17,6 +17,7 @@ package LatexIndent::KeyEqualsValuesBraces;
use strict;
use warnings;
use LatexIndent::Tokens qw/%tokens/;
+use LatexIndent::GetYamlSettings qw/%masterSettings/;
use LatexIndent::TrailingComments qw/$trailingCommentRegExp/;
use LatexIndent::Switches qw/$is_m_switch_active $is_t_switch_active $is_tt_switch_active/;
use LatexIndent::LogFile qw/$logger/;
@@ -37,21 +38,19 @@ sub construct_key_equals_values_regexp{
# blank line token
my $blankLineToken = $tokens{blanklines};
+ # read from fine tuning
+ my $keyEqualsValuesBracesBrackets = qr/${${$masterSettings{fineTuning}}{keyEqualsValuesBracesBrackets}}{name}/;
+ my $keyEqualsValuesBracesBracketsFollow = qr/${${$masterSettings{fineTuning}}{keyEqualsValuesBracesBrackets}}{follow}/;
+
# store the regular expresssion for matching and replacing
$key_equals_values_bracesRegExp = qr/
(
- (?:
- (?:(?<!\\)\{)
- |
- ,
- |
- (?:(?<!\\)\[)
- )
+ (?:$keyEqualsValuesBracesBracketsFollow)
(?:\h|\R|$blankLineToken|$trailingCommentRegExp)*
) # $1 pre-key bit: could be { OR , OR [
(\\)? # $2 possible backslash
(
- [a-zA-Z@\*0-9_\/.\h\{\}:\#-]+? # lowercase|uppercase letters, @, *, numbers, forward slash, dots
+ $keyEqualsValuesBracesBrackets? # lowercase|uppercase letters, @, *, numbers, forward slash, dots
) # $3 name
(
(?:\h|\R|$blankLineToken|$trailingCommentRegExp)*
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm
index b8ebc034b3a..75ebe0b2ea2 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm
@@ -80,6 +80,15 @@ usage: latexindent.pl [options] [file][.tex|.sty|.cls|.bib|...]
-m, --modifylinebreaks
modify linebreaks before, during, and at the end of code blocks;
trailing comments and blank lines can also be added using this feature
+ -r,--replacement
+ replacement mode, allows you to replace strings and regular expressions
+ verbatim blocks not respected
+ -rv,--replacementrespectverb
+ replacement mode, allows you to replace strings and regular expressions
+ while respecting verbatim code blocks
+ -rr,--onlyreplacement
+ *only* replacement mode, no indentation
+ verbatim blocks not respected
ENDQUOTE
;
exit(2);
@@ -182,6 +191,8 @@ ENDQUOTE
$logger->info("-m|--modifylinebreaks: modify line breaks") if($switches{modifyLineBreaks});
$logger->info("-g|--logfile: logfile name") if($switches{logFileName});
$logger->info("-c|--cruft: cruft directory") if($switches{cruftDirectory});
+ $logger->info("-r|--replacement: replacement mode") if($switches{replacement});
+ $logger->info("-rr|--onlyreplacement: *only* replacement mode, no indentation") if($switches{onlyreplacement});
# check if overwrite and outputfile are active similtaneously
if($switches{overwrite} and $switches{outputToFile}){
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/MandatoryArgument.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/MandatoryArgument.pm
index 0b641231f2a..b5b3ac8de6f 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/MandatoryArgument.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/MandatoryArgument.pm
@@ -18,7 +18,7 @@ use strict;
use warnings;
use LatexIndent::Tokens qw/%tokens/;
use LatexIndent::TrailingComments qw/$trailingCommentRegExp/;
-use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/;
+use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active $is_m_switch_active /;
use LatexIndent::LogFile qw/$logger/;
use LatexIndent::IfElseFi qw/$ifElseFiBasicRegExp/;
use LatexIndent::Special qw/$specialBeginBasicRegExp/;
@@ -128,6 +128,8 @@ sub tasks_particular_to_each_object{
# search for special begin/end
$self->find_special if ${$self}{body} =~ m/$specialBeginBasicRegExp/s;
+ # comma poly-switch check
+ $self->comma_else if $is_m_switch_active;
}
1;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm
index a0763456e02..0f33f88b834 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm
@@ -28,27 +28,34 @@ 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/;
our $paragraphRegExp = q();
-
sub modify_line_breaks_body{
my $self = shift;
+ #
+ # Blank line poly-switch notes (==4)
+ #
+ # when BodyStartsOnOwnLine=4 we adopt the following approach:
+ # temporarily change BodyStartsOnOwnLine to -1, make adjustments
+ # temporarily change BodyStartsOnOwnLine to 3, make adjustments
+ # switch BodyStartsOnOwnLine back to 4
# add a line break after \begin{statement} if appropriate
- if(defined ${$self}{BodyStartsOnOwnLine}){
+ my @polySwitchValues = (${$self}{BodyStartsOnOwnLine}==4)?(-1,3):(${$self}{BodyStartsOnOwnLine});
+ foreach(@polySwitchValues){
my $BodyStringLogFile = ${$self}{aliases}{BodyStartsOnOwnLine}||"BodyStartsOnOwnLine";
- if(${$self}{BodyStartsOnOwnLine}>=1 and !${$self}{linebreaksAtEnd}{begin}){
+ if($_>=1 and !${$self}{linebreaksAtEnd}{begin}){
# if the <begin> statement doesn't finish with a line break,
# then we have different actions based upon the value of BodyStartsOnOwnLine:
# BodyStartsOnOwnLine == 1 just add a new line
# BodyStartsOnOwnLine == 2 add a comment, and then new line
# BodyStartsOnOwnLine == 3 add a blank line, and then new line
- if(${$self}{BodyStartsOnOwnLine}==1){
+ if($_==1){
# modify the begin statement
- $logger->trace("Adding a linebreak at the end of begin, ${$self}{begin} (see $BodyStringLogFile)") if $is_t_switch_active;
+ $logger->trace("Adding a linebreak at the end of begin statement ${$self}{begin} (see $BodyStringLogFile)") if $is_t_switch_active;
${$self}{begin} .= "\n";
${$self}{linebreaksAtEnd}{begin} = 1;
$logger->trace("Removing leading space from body of ${$self}{name} (see $BodyStringLogFile)") if $is_t_switch_active;
${$self}{body} =~ s/^\h*//;
- } elsif(${$self}{BodyStartsOnOwnLine}==2){
+ } elsif($_==2){
# by default, assume that no trailing comment token is needed
my $trailingCommentToken = q();
if(${$self}{body} !~ m/^\h*$trailingCommentRegExp/s){
@@ -63,7 +70,7 @@ sub modify_line_breaks_body{
} else {
$logger->trace("Even though $BodyStringLogFile == 2, ${$self}{begin} already finishes with a %, so not adding another.") if $is_t_switch_active;
}
- } elsif (${$self}{BodyStartsOnOwnLine}==3){
+ } elsif ($_==3){
my $trailingCharacterToken = q();
$logger->trace("Adding a blank line at the end of begin ${$self}{begin} followed by a linebreak ($BodyStringLogFile == 3)") if $is_t_switch_active;
${$self}{begin} =~ s/\h*$//;
@@ -72,12 +79,12 @@ sub modify_line_breaks_body{
$logger->trace("Removing leading space from body of ${$self}{name} (see $BodyStringLogFile)") if $is_t_switch_active;
${$self}{body} =~ s/^\h*//;
}
- } elsif (${$self}{BodyStartsOnOwnLine}==-1 and ${$self}{linebreaksAtEnd}{begin}){
+ } elsif ($_==-1 and ${$self}{linebreaksAtEnd}{begin}){
# remove line break *after* begin, if appropriate
$self->remove_line_breaks_begin;
}
}
- }
+}
sub remove_line_breaks_begin{
my $self = shift;
@@ -90,86 +97,111 @@ sub remove_line_breaks_begin{
sub modify_line_breaks_end{
my $self = shift;
- # possibly modify line break *before* \end{statement}
- if(defined ${$self}{EndStartsOnOwnLine}){
- my $EndStringLogFile = ${$self}{aliases}{EndStartsOnOwnLine}||"EndStartsOnOwnLine";
- if(${$self}{EndStartsOnOwnLine}>=1 and !${$self}{linebreaksAtEnd}{body}){
- # if the <body> statement doesn't finish with a line break,
- # then we have different actions based upon the value of EndStartsOnOwnLine:
- # EndStartsOnOwnLine == 1 just add a new line
- # EndStartsOnOwnLine == 2 add a comment, and then new line
- # EndStartsOnOwnLine == 3 add a blank line, and then new line
- $logger->trace("Adding a linebreak at the end of body (see $EndStringLogFile)") if $is_t_switch_active;
-
- # by default, assume that no trailing character token is needed
- my $trailingCharacterToken = q();
- if(${$self}{EndStartsOnOwnLine}==2){
- $logger->trace("Adding a % immediately after body of ${$self}{name} ($EndStringLogFile==2)") if $is_t_switch_active;
- $trailingCharacterToken = "%".$self->add_comment_symbol;
- ${$self}{body} =~ s/\h*$//s;
- } elsif (${$self}{EndStartsOnOwnLine}==3) {
- $logger->trace("Adding a blank line immediately after body of ${$self}{name} ($EndStringLogFile==3)") if $is_t_switch_active;
- $trailingCharacterToken = "\n".(${$masterSettings{modifyLineBreaks}}{preserveBlankLines}?$tokens{blanklines}:q());
- ${$self}{body} =~ s/\h*$//s;
- }
-
- # modified end statement
- if(${$self}{body} =~ m/^\h*$/s and ${$self}{BodyStartsOnOwnLine} >=1 ){
- ${$self}{linebreaksAtEnd}{body} = 0;
- } else {
- ${$self}{body} .= "$trailingCharacterToken\n";
- ${$self}{linebreaksAtEnd}{body} = 1;
- }
- } elsif (${$self}{EndStartsOnOwnLine}==-1 and ${$self}{linebreaksAtEnd}{body}){
- # remove line break *after* body, if appropriate
-
- # check to see that body does *not* finish with blank-line-token,
- # if so, then don't remove that final line break
- if(${$self}{body} !~ m/$tokens{blanklines}$/s){
- $logger->trace("Removing linebreak at the end of body (see $EndStringLogFile)") if $is_t_switch_active;
- ${$self}{body} =~ s/\R*$//sx;
- ${$self}{linebreaksAtEnd}{body} = 0;
- } else {
- $logger->trace("Blank line token found at end of body (${$self}{name}), see preserveBlankLines, not removing line break before ${$self}{end}") if $is_t_switch_active;
+ #
+ # Blank line poly-switch notes (==4)
+ #
+ # when EndStartsOnOwnLine=4 we adopt the following approach:
+ # temporarily change EndStartsOnOwnLine to -1, make adjustments
+ # temporarily change EndStartsOnOwnLine to 3, make adjustments
+ # switch EndStartsOnOwnLine back to 4
+ #
+
+ my @polySwitchValues =(defined ${$self}{EndStartsOnOwnLine} and ${$self}{EndStartsOnOwnLine}==4) ?(-1,3):(${$self}{EndStartsOnOwnLine});
+ foreach(@polySwitchValues){
+ # possibly modify line break *before* \end{statement}
+ if(defined ${$self}{EndStartsOnOwnLine}){
+ my $EndStringLogFile = ${$self}{aliases}{EndStartsOnOwnLine}||"EndStartsOnOwnLine";
+ if($_>=1 and !${$self}{linebreaksAtEnd}{body}){
+ # if the <body> statement doesn't finish with a line break,
+ # then we have different actions based upon the value of EndStartsOnOwnLine:
+ # EndStartsOnOwnLine == 1 just add a new line
+ # EndStartsOnOwnLine == 2 add a comment, and then new line
+ # EndStartsOnOwnLine == 3 add a blank line, and then new line
+ $logger->trace("Adding a linebreak at the end of body (see $EndStringLogFile)") if $is_t_switch_active;
+
+ # by default, assume that no trailing character token is needed
+ my $trailingCharacterToken = q();
+ if($_==2){
+ $logger->trace("Adding a % immediately after body of ${$self}{name} ($EndStringLogFile==2)") if $is_t_switch_active;
+ $trailingCharacterToken = "%".$self->add_comment_symbol;
+ ${$self}{body} =~ s/\h*$//s;
+ } elsif ($_==3) {
+ $logger->trace("Adding a blank line immediately after body of ${$self}{name} ($EndStringLogFile==3)") if $is_t_switch_active;
+ $trailingCharacterToken = "\n".(${$masterSettings{modifyLineBreaks}}{preserveBlankLines}?$tokens{blanklines}:q());
+ ${$self}{body} =~ s/\h*$//s;
+ }
+
+ # modified end statement
+ if(${$self}{body} =~ m/^\h*$/s and (defined ${$self}{BodyStartsOnOwnLine}) and ${$self}{BodyStartsOnOwnLine} >=1 ){
+ ${$self}{linebreaksAtEnd}{body} = 0;
+ } else {
+ ${$self}{body} .= "$trailingCharacterToken\n";
+ ${$self}{linebreaksAtEnd}{body} = 1;
+ }
+ } elsif ($_==-1 and ${$self}{linebreaksAtEnd}{body}){
+ # remove line break *after* body, if appropriate
+
+ # check to see that body does *not* finish with blank-line-token,
+ # if so, then don't remove that final line break
+ if(${$self}{body} !~ m/$tokens{blanklines}$/s){
+ $logger->trace("Removing linebreak at the end of body (see $EndStringLogFile)") if $is_t_switch_active;
+ ${$self}{body} =~ s/\R*$//sx;
+ ${$self}{linebreaksAtEnd}{body} = 0;
+ } else {
+ $logger->trace("Blank line token found at end of body (${$self}{name}), see preserveBlankLines, not removing line break before ${$self}{end}") if $is_t_switch_active;
+ }
}
- }
+ }
}
- # possibly modify line break *after* \end{statement}
- if(defined ${$self}{EndFinishesWithLineBreak}
- and ${$self}{EndFinishesWithLineBreak}>=1
- and !${$self}{linebreaksAtEnd}{end}){
- # if the <end> statement doesn't finish with a line break,
- # then we have different actions based upon the value of EndFinishesWithLineBreak:
- # EndFinishesWithLineBreak == 1 just add a new line
- # EndFinishesWithLineBreak == 2 add a comment, and then new line
- # EndFinishesWithLineBreak == 3 add a blank line, and then new line
- my $EndStringLogFile = ${$self}{aliases}{EndFinishesWithLineBreak}||"EndFinishesWithLineBreak";
- if(${$self}{EndFinishesWithLineBreak}==1){
- $logger->trace("Adding a linebreak at the end of ${$self}{end} ($EndStringLogFile==1)") if $is_t_switch_active;
- ${$self}{linebreaksAtEnd}{end} = 1;
-
- # modified end statement
- ${$self}{replacementText} .= "\n";
- } elsif(${$self}{EndFinishesWithLineBreak}==2){
- if(${$self}{endImmediatelyFollowedByComment}){
- # no need to add a % if one already exists
- $logger->trace("Even though $EndStringLogFile == 2, ${$self}{end} is immediately followed by a %, so not adding another; not adding line break.") if $is_t_switch_active;
- } else {
- # otherwise, create a trailing comment, and tack it on
- $logger->trace("Adding a % immediately after, ${$self}{end} ($EndStringLogFile==2)") if $is_t_switch_active;
- my $trailingCommentToken = "%".$self->add_comment_symbol;
- ${$self}{end} =~ s/\h*$//s;
- ${$self}{replacementText} .= "$trailingCommentToken\n";
- ${$self}{linebreaksAtEnd}{end} = 1;
- }
- } elsif(${$self}{EndFinishesWithLineBreak}==3){
- $logger->trace("Adding a blank line at the end of ${$self}{end} ($EndStringLogFile==3)") if $is_t_switch_active;
- ${$self}{linebreaksAtEnd}{end} = 1;
-
- # modified end statement
- ${$self}{replacementText} .= (${$masterSettings{modifyLineBreaks}}{preserveBlankLines}?$tokens{blanklines}:"\n")."\n";
- }
+ #
+ # Blank line poly-switch notes (==4)
+ #
+ # when EndFinishesWithLineBreak=4 we adopt the following approach:
+ # temporarily change EndFinishesWithLineBreak to -1, make adjustments
+ # temporarily change EndFinishesWithLineBreak to 3, make adjustments
+ # switch EndFinishesWithLineBreak back to 4
+ #
+ @polySwitchValues =(defined ${$self}{EndFinishesWithLineBreak} and ${$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));
+
+ # possibly modify line break *after* \end{statement}
+ if(defined $_ and $_>=1
+ and !${$self}{linebreaksAtEnd}{end}){
+ # if the <end> statement doesn't finish with a line break,
+ # then we have different actions based upon the value of EndFinishesWithLineBreak:
+ # EndFinishesWithLineBreak == 1 just add a new line
+ # EndFinishesWithLineBreak == 2 add a comment, and then new line
+ # EndFinishesWithLineBreak == 3 add a blank line, and then new line
+ my $EndStringLogFile = ${$self}{aliases}{EndFinishesWithLineBreak}||"EndFinishesWithLineBreak";
+ if($_==1){
+ $logger->trace("Adding a linebreak at the end of ${$self}{end} ($EndStringLogFile==1)") if $is_t_switch_active;
+ ${$self}{linebreaksAtEnd}{end} = 1;
+
+ # modified end statement
+ ${$self}{replacementText} .= "\n";
+ } elsif($_==2){
+ if(${$self}{endImmediatelyFollowedByComment}){
+ # no need to add a % if one already exists
+ $logger->trace("Even though $EndStringLogFile == 2, ${$self}{end} is immediately followed by a %, so not adding another; not adding line break.") if $is_t_switch_active;
+ } else {
+ # otherwise, create a trailing comment, and tack it on
+ $logger->trace("Adding a % immediately after, ${$self}{end} ($EndStringLogFile==2)") if $is_t_switch_active;
+ my $trailingCommentToken = "%".$self->add_comment_symbol;
+ ${$self}{end} =~ s/\h*$//s;
+ ${$self}{replacementText} .= "$trailingCommentToken\n";
+ ${$self}{linebreaksAtEnd}{end} = 1;
+ }
+ } elsif($_==3){
+ $logger->trace("Adding a blank line at the end of ${$self}{end} ($EndStringLogFile==3)") if $is_t_switch_active;
+ ${$self}{linebreaksAtEnd}{end} = 1;
+
+ # modified end statement
+ ${$self}{replacementText} .= (${$masterSettings{modifyLineBreaks}}{preserveBlankLines}?$tokens{blanklines}:"\n")."\n";
+ }
+ }
}
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm
index 4508943ddfa..f20e23ca547 100755
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm
@@ -17,6 +17,7 @@ package LatexIndent::NamedGroupingBracesBrackets;
use strict;
use warnings;
use LatexIndent::Tokens qw/%tokens/;
+use LatexIndent::GetYamlSettings qw/%masterSettings/;
use LatexIndent::TrailingComments qw/$trailingCommentRegExp/;
use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/;
use LatexIndent::LogFile qw/$logger/;
@@ -33,18 +34,22 @@ sub construct_grouping_braces_brackets_regexp{
# grab the arguments regexp
my $optAndMandRegExp = $self->get_arguments_regexp;
+ # read from fine tuning
+ my $NamedGroupingBracesBracketsRegExp = qr/${${$masterSettings{fineTuning}}{NamedGroupingBracesBrackets}}{name}/;
+ my $NamedGroupingFollowRegExp = qr/${${$masterSettings{fineTuning}}{NamedGroupingBracesBrackets}}{follow}/;
+
# store the regular expresssion for matching and replacing
$grouping_braces_regexp = qr/
(
- \h|\R|\{|\[|\$|\)|\(
+ $NamedGroupingFollowRegExp
)
(
- [0-9\.a-zA-Z@\*><]+? # lowercase|uppercase letters, @, *, numbers, forward slash, dots
- ) # $2 name
- (\h*) # $3 h-space
- (\R*) # $4 linebreaks
- ($optAndMandRegExp) # $5 mand|opt arguments (at least one)
- (\R)? # $8 linebreak
+ $NamedGroupingBracesBracketsRegExp # lowercase|uppercase letters, @, *, numbers, forward slash, dots
+ ) # $2 name
+ (\h*) # $3 h-space
+ (\R*) # $4 linebreaks
+ ($optAndMandRegExp) # $5 mand|opt arguments (at least one)
+ (\R)? # $8 linebreak
/sx;
# something {value} grouping braces with trailing comment
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/OptionalArgument.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/OptionalArgument.pm
index 60e03ca91d4..fdaa549a7ae 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/OptionalArgument.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/OptionalArgument.pm
@@ -18,7 +18,7 @@ use strict;
use warnings;
use LatexIndent::Tokens qw/%tokens/;
use LatexIndent::TrailingComments qw/$trailingCommentRegExp/;
-use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/;
+use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active $is_m_switch_active /;
use LatexIndent::LogFile qw/$logger/;
use LatexIndent::IfElseFi qw/$ifElseFiBasicRegExp/;
use LatexIndent::Special qw/$specialBeginBasicRegExp/;
@@ -113,6 +113,8 @@ sub tasks_particular_to_each_object{
# search for special begin/end
$self->find_special if ${$self}{body} =~ m/$specialBeginBasicRegExp/s;
+ # comma poly-switch check
+ $self->comma_else if $is_m_switch_active;
}
1;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Replacement.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Replacement.pm
new file mode 100644
index 00000000000..1bc51caed2d
--- /dev/null
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Replacement.pm
@@ -0,0 +1,89 @@
+package LatexIndent::Replacement;
+# 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 LatexIndent::Tokens qw/%tokens/;
+use LatexIndent::TrailingComments qw/$trailingCommentRegExp/;
+use LatexIndent::GetYamlSettings qw/%masterSettings/;
+use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active $is_rr_switch_active/;
+use LatexIndent::LogFile qw/$logger/;
+use Data::Dumper;
+use Exporter qw/import/;
+our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321
+our @EXPORT_OK = qw/make_replacements/;
+
+sub make_replacements{
+ my $self = shift;
+ my %input = @_;
+ if ($is_t_switch_active and !$is_rr_switch_active){
+ $logger->trace("*Replacement mode *$input{when}* indentation: -r") ;
+ } elsif ($is_t_switch_active and $is_rr_switch_active) {
+ $logger->trace("*Replacement mode, -rr switch is active") if $is_t_switch_active ;
+ }
+
+ my @replacements = @{$masterSettings{replacements}};
+
+ foreach ( @replacements ){
+ next if !(${$_}{this} or ${$_}{substitution});
+
+ # default value of "lookForThis" is 1
+ ${$_}{lookForThis} = 1 if( !(defined ${$_}{lookForThis}));
+
+ # move on if this one shouldn't be looked for
+ next if(!${$_}{lookForThis});
+
+ # default value of "when" is before
+ ${$_}{when} = "before" if( !(defined ${$_}{when}) or $is_rr_switch_active);
+
+ # update to the logging file
+ if($is_t_switch_active and (${$_}{when} eq $input{when})){
+ $logger->trace("-");
+ $logger->trace("this: ${$_}{this}") if(${$_}{this});
+ $logger->trace("that: ${$_}{that}") if(${$_}{that});
+ $logger->trace("substitution: ${$_}{substitution}") if(${$_}{substitution});
+ $logger->trace("when: ${$_}{when}");
+ }
+
+ # perform the substitutions
+ if(${$_}{when} eq $input{when}){
+ $logger->warn("*You have specified both 'this' and 'substitution'; the 'substitution' field will be ignored") if(${$_}{this} and ${$_}{substitution});
+ if(${$_}{this}){
+ # *string* replacement
+ # *string* replacement
+ # *string* replacement
+ my $this = qq{${$_}{this}};
+ my $that = (defined ${$_}{that}) ? qq{${$_}{that}} : q();
+ my $index_match = index(${$self}{body}, $this);
+ while ( $index_match != -1 ) {
+ substr (${$self}{body}, $index_match, length($this), $that );
+ $index_match = index(${$self}{body}, $this);
+ }
+ } else {
+ # *regex* replacement
+ # *regex* replacement
+ # *regex* replacement
+
+ # https://stackoverflow.com/questions/12423337/how-to-pass-a-replacing-regex-as-a-command-line-argument-to-a-perl-script
+ my $body = ${$self}{body};
+ eval("\$body =~ ${$_}{substitution}");
+ ${$self}{body} = $body ;
+ }
+ }
+ }
+}
+
+1;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Sentence.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Sentence.pm
index 48ae0379d6c..cc11997e36f 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Sentence.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Sentence.pm
@@ -129,7 +129,7 @@ sub one_sentence_per_line{
$sentencesEndWithEachPart = qr/\./;
} elsif($sentencesEndWithEachPart eq "betterFullStop"){
$logger->trace("sentence ENDS with *better* full stop (see oneSentencePerLine:sentencesEndWith:betterFullStop") if $is_t_switch_active;
- $sentencesEndWithEachPart = qr/(?:\.\)(?!\h*[a-z]))|(?:(?<!(?:(?:e\.g)|(?:i\.e)|(?:etc))))\.(?!(?:[a-z]|[A-Z]|\-|~|\,|[0-9]))/;
+ $sentencesEndWithEachPart = qr/${${$masterSettings{fineTuning}}{modifyLineBreaks}}{betterFullStop}/;
} elsif ($sentencesEndWithEachPart eq "exclamationMark"){
$logger->trace("sentence ENDS with exclamation mark (see oneSentencePerLine:sentencesEndWith:exclamationMark)") if $is_t_switch_active;
$sentencesEndWithEachPart = qr/!/;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Switches.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Switches.pm
index a5b07936a6d..d738a4b36b6 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Switches.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Switches.pm
@@ -17,11 +17,14 @@ package LatexIndent::Switches;
use strict;
use warnings;
use Exporter qw/import/;
-our @EXPORT_OK = qw/%switches storeSwitches $is_m_switch_active $is_t_switch_active $is_tt_switch_active/;
+our @EXPORT_OK = qw/%switches storeSwitches $is_m_switch_active $is_t_switch_active $is_tt_switch_active $is_r_switch_active $is_rr_switch_active $is_rv_switch_active/;
our %switches;
our $is_m_switch_active;
our $is_t_switch_active;
our $is_tt_switch_active;
+our $is_r_switch_active;
+our $is_rr_switch_active;
+our $is_rv_switch_active;
sub storeSwitches{
my $self = shift;
@@ -32,6 +35,10 @@ sub storeSwitches{
$is_t_switch_active = defined $switches{trace}?$switches{trace}: 0;
$is_tt_switch_active = defined $switches{ttrace}?$switches{ttrace}: 0;
$is_t_switch_active = $is_tt_switch_active ? $is_tt_switch_active : $is_t_switch_active;
+ $is_r_switch_active = defined $switches{replacement}?$switches{replacement}: 0;
+ $is_rr_switch_active = defined $switches{onlyreplacement}?$switches{onlyreplacement}: 0;
+ $is_rv_switch_active = defined $switches{replacementRespectVerb}?$switches{replacementRespectVerb}: 0;
+ $is_r_switch_active = ($is_rr_switch_active|$is_rv_switch_active) ? ($is_rr_switch_active|$is_rv_switch_active) : $is_r_switch_active;
delete ${$self}{switches};
}
1;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/UnNamedGroupingBracesBrackets.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/UnNamedGroupingBracesBrackets.pm
index 0c18484649a..eea6ee6747a 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/UnNamedGroupingBracesBrackets.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/UnNamedGroupingBracesBrackets.pm
@@ -17,6 +17,7 @@ package LatexIndent::UnNamedGroupingBracesBrackets;
use strict;
use warnings;
use LatexIndent::Tokens qw/%tokens/;
+use LatexIndent::GetYamlSettings qw/%masterSettings/;
use LatexIndent::TrailingComments qw/$trailingCommentRegExp/;
use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/;
use LatexIndent::LogFile qw/$logger/;
@@ -36,8 +37,9 @@ sub construct_unnamed_grouping_braces_brackets_regexp{
# blank line token
my $blankLineToken = $tokens{blanklines};
- # for example #1 #2, etc
- my $numberedArgRegExp = $self->get_numbered_arg_regexp;
+ # arguments Before, by default, includes beamer special and numbered arguments, for example #1 #2, etc
+ my $argumentsBefore = qr/${${$masterSettings{fineTuning}}{arguments}}{before}/;
+ my $UnNamedGroupingFollowRegExp = qr/${${$masterSettings{fineTuning}}{UnNamedGroupingBracesBrackets}}{follow}/;
# store the regular expresssion for matching and replacing
$un_named_grouping_braces_RegExp = qr/
@@ -48,18 +50,18 @@ sub construct_unnamed_grouping_braces_brackets_regexp{
|
(?:(?<!\\)\})
)
- (?:\h|\R|$blankLineToken|$trailingCommentRegExp|$numberedArgRegExp)* # 0 or more h-space, blanklines, trailing comments
+ (?:\h|\R|$blankLineToken|$trailingCommentRegExp|$argumentsBefore)* # 0 or more h-space, blanklines, trailing comments
)
# END of NOT
(
(?:
- \{|\[|,|&|\)|\(|\$ # starting with { OR [ OR , OR & OR ) OR ( OR $
+ $UnNamedGroupingFollowRegExp # starting with { OR [ OR , OR & OR ) OR ( OR $
)
\h*
- ) # $1 into beginning bit
- (\R*) # $2 linebreaksAtEnd of begin
- ($optAndMandRegExp) # $3 mand|opt arguments (at least one) stored into body
- (\R)? # $6 linebreak
+ ) # $1 into beginning bit
+ (\R*) # $2 linebreaksAtEnd of begin
+ ($optAndMandRegExp) # $3 mand|opt arguments (at least one) stored into body
+ (\R)? # $6 linebreak
/sx;
$un_named_grouping_braces_RegExp_trailing_comment = qr/$un_named_grouping_braces_RegExp(\h*)((?:$trailingCommentRegExp\h*)*)?/;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm
index 52a659dc79c..c0ecb8bb067 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.6';
-our $versionDate = '2019-05-05';
+our $versionNumber = '3.7';
+our $versionDate = '2019-07-13';
1
diff --git a/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml b/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml
index d457e96e3a3..a706131365a 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.6, 2019-05-05
+# defaultSettings.yaml for latexindent.pl, version 3.7, 2019-07-13
# a script that aims to
# beautify .tex, .sty, .cls files
#
@@ -21,15 +21,18 @@
# For all communication, please visit: https://github.com/cmhughes/latexindent.pl
-# You're welcome to change anything you like in here, but
+# You should feel encouraged to change anything you like in these settings, but
# it would probably be better to have your own user settings
# files somewhere else - remember that this file may be overwritten
-# when you update your distribution. Please see the manual
-# for details of how to setup your own settings files.
+# when you update your tex distribution. Please see the manual linked from:
#
-# Please read the manual first to understand what each switch does.
+# https://github.com/cmhughes/latexindent.pl
+#
+# for details of how to create and configure your own settings files.
+#
+# Please read the manual (linked from above) first to understand what each switch does.
-# latexindent can be called without a file extension,
+# latexindent can be called to act on a file without using the file's extension,
# e.g, simply
# latexindent myfile
# in which case the choice of file extension is chosen
@@ -41,7 +44,7 @@ fileExtensionPreference:
.cls: 3
.bib: 4
-# default file extension of backup file (if original is overwritten with -w switch)
+# default file extension of backup file (if -w switch is active)
# for example, if your .tex file is called
# myfile.tex
# and you specify the backupExtension as BACKUP.bak then your
@@ -49,23 +52,26 @@ fileExtensionPreference:
# myfileBACKUP.bak
backupExtension: .bak
-# only one backup per file; if onlyOneBackUp is 0 then, as a safety measure,
-# the number on the extension increments by 1 each time:
-# myfile.bak0, myfile.bak1, myfile.bak2
+# only one backup per file:
+# - if onlyOneBackUp is 0 then, as a safety measure,
+# the number on the extension increments by 1 each time:
#
-# if you set onlyOnebackUp to 1, then the backup file will
-# be overwritten each time (not recommended until you trust the script)
+# myfile.bak0, myfile.bak1, myfile.bak2
+# - if you set onlyOnebackUp to 1, then the backup file will
+# be overwritten each time (not recommended until you trust the script)
onlyOneBackUp: 0
-# some users may only want a set number of backup files,
-# say at most 3; in which case, they can change this switch.
+# some users may want a finite number of backup files,
+# say at most 3; in which case, they can change this maxNumberOfBackUps.
+#
# If maxNumberOfBackUps is set to 0 (or less) then infinitely
# many backups are possible, unless onlyOneBackUp is switched on
maxNumberOfBackUps: 0
-# some users may wish to cycle through back up files, for example,
-# with maxNumberOfBackUps: 4, they may wish to delete the oldest
-# back up file, and keep only the most recent.
+# some users may wish to cycle through back up files.
+#
+# for example, with maxNumberOfBackUps: 4, they may
+# wish to delete the oldest back up file, and keep only the most recent.
#
# copy myfile.bak1 to myfile.bak0
# copy myfile.bak2 to myfile.bak1
@@ -102,8 +108,7 @@ verbatimCommands:
# no indent blocks (not necessarily verbatim
# environments) which are marked as %\begin{noindent}
-# or anything else that the user puts in this hash
-# table
+# or anything else that you detail in the following
noIndentBlock:
noindent: 1
cmhtest: 1
@@ -136,7 +141,7 @@ lookForPreamble:
# postfoothook=\end{mdframed},
preambleCommandsBeforeEnvironments: 0
-# Default value of indentation
+# default value of indentation
defaultIndent: "\t"
# name of code blocks that should have their body aligned at ampersand delimiters
@@ -185,7 +190,7 @@ indentAfterItems:
description: 1
list: 1
-# if you want to use other names for your items (such as, for example, part)
+# if you want to use other names for your items (for example, \part)
# then populate them here; note that you can trick latexindent.pl
# into indenting all kinds of commands (within environments specified in
# indentAfterItems) using this technique.
@@ -193,7 +198,7 @@ itemNames:
item: 1
myitem: 1
-# specialBeginEnd is mainly mathmode focus, although
+# specialBeginEnd is, by default, mathmode focus, although
# there's no restrictions
specialBeginEnd:
displayMath:
@@ -248,10 +253,10 @@ indentAfterHeadings:
maximumIndentation: -1
# if you don't want to have additional indentation
-# in an environment put it in this hash table; note that
-# environments in this field will inherit
+# in a code block, then add it to noAdditionalIndent; note that
+# code blocks in this field will inherit
# the *current* level of indentation they just won't
-# get any *additional*.
+# get any *additional* indentation
noAdditionalIndent:
myexample: 1
mydefinition: 1
@@ -264,8 +269,8 @@ noAdditionalIndent:
document: 1
frame: 0
-# if you have indent rules for particular environments
-# or commands, put them in here; for example, you might just want
+# if you have indent rules for particular code blocks
+# then you can populate them in indentRules; for example, you might just want
# to use a space " " or maybe a double tab "\t\t"
indentRules:
myenvironment: "\t\t"
@@ -325,72 +330,114 @@ commandCodeBlocks:
# modifyLineBreaks will only be searched if the -m
# switch is active
-# BeginStartsOnOwnLine: 1
-# if a begin statement is not already on its own line,
-# then, with -m active, it will be moved to its own line.
#
+# poly-switch examples:
+#
+# BeginStartsOnOwnLine:
+# modify line breaks before a begin statement
+#
+# when set to -1, e.g
+# some text some text
+# \begin{myenvironment}
+# will be changed to
+# some text some text \begin{myenvironment}
+# when set to 0, the switch is ignored
# when set to 1, e.g
# some text some text \begin{myenvironment}
# will be changed to
# some text some text
# \begin{myenvironment}
-# when set to -1, e.g
-# some text some text
-# \begin{myenvironment}
+# when set to 2, e.g
+# some text some text \begin{myenvironment}
# will be changed to
+# some text some text%
+# \begin{myenvironment}
+# when set to 3, e.g
# some text some text \begin{myenvironment}
-# when set to 0, the switch is ignored
+# will be changed to
+# some text some text
#
-# BodyStartsOnOwnLine: 1
-# if body does not already start on its own line, then with
-# -m active, it will be moved to its own line.
+# \begin{myenvironment}
+#
+# BodyStartsOnOwnLine:
+# modify line breaks before the beginning of the body
#
+# when set to -1, e.g
+# \begin{myenv}
+# body text body text
+# will be changed to
+# \begin{myenv}body text body text
+# when set to 0, the switch is ignored
# when set to 1, e.g
# \begin{myenv}body text body text
# will be changed to
# \begin{myenv}
# body text body text
-# when set to -1, e.g
-# \begin{myenv}
-# body text body text
+# when set to 2, e.g
+# \begin{myenv}body text body text
# will be changed to
+# \begin{myenv}%
+# body text body text
+# when set to 3, e.g
# \begin{myenv}body text body text
-# when set to 0, the switch is ignored
+# will be changed to
+# \begin{myenv}
+#
+# body text body text
#
-# EndStartsOnOwnLine: 1
-# if an end statement is not already on its own line,
-# then, with -m active, it will be moved to its own line.
+# EndStartsOnOwnLine:
+# modify line breaks before the end statement
#
+# when set to -1, e.g
+# some text some text
+# \end{myenvironment}
+# will be changed to
+# some text some text \end{myenvironment}
+# when set to 0, the switch is ignored
# when set to 1, e.g
# some text some text \end{myenvironment}
# will be changed to
# some text some text
# \end{myenvironment}
-# when set to -1, e.g
-# some text some text
-# \end{myenvironment}
+# when set to 2, e.g
+# some text some text \end{myenvironment}
# will be changed to
+# some text some text%
+# \end{myenvironment}
+# when set to 3, e.g
# some text some text \end{myenvironment}
-# when set to 0, the switch is ignored
+# will be changed to
+# some text some text
#
-# EndFinishesWithLineBreak: 1
-# this switch adjusts line breaks immmediately
-# after an end statement (with -m active)
+# \end{myenvironment}
+#
+# EndFinishesWithLineBreak:
+# modify line breaks after the end statement
#
-# when set to 1, e.g
-# \end{myenvironment}some text some text
-# will be changed to
-# \end{myenvironment}
-# some text some text
# when set to -1, e.g
# \end{myenvironment}
# some text some text
# will be changed to
# \end{myenvironment}some text some text
# when set to 0, the switch is ignored
+# when set to 1, e.g
+# \end{myenvironment}some text some text
+# will be changed to
+# \end{myenvironment}
+# some text some text
+# when set to 2, e.g
+# \end{myenvironment}some text some text
+# will be changed to
+# \end{myenvironment}%
+# some text some text
+# when set to 3, e.g
+# \end{myenvironment}some text some text
+# will be changed to
+# \end{myenvironment}
+#
+# some text some text
#
-# Naturally, you can specify settings for individual environments,
-# commands, headings, etc, populate as you wish.
+# you can specify settings on a per-name basis
modifyLineBreaks:
preserveBlankLines: 1
condenseMultipleBlankLinesInto: 1
@@ -519,3 +566,38 @@ modifyLineBreaks:
verbatim:
VerbatimBeginStartsOnOwnLine: 0
VerbatimEndFinishesWithLineBreak: 0
+
+# replacements, only active when either -r or -rr switches are active
+replacements:
+ -
+ amalgamate: 1
+ -
+ this: 'latexindent.pl'
+ that: 'pl.latexindent'
+ lookForThis: 1
+ when: before
+
+# fineTuning allows you to tweak the internal pattern matching that
+# is central to latexindent.pl
+fineTuning:
+ environments:
+ name: '[a-zA-Z@\*0-9_\\]+'
+ ifElseFi:
+ name: '@?if[a-zA-Z@]*?'
+ commands:
+ name: '[+a-zA-Z@\*0-9_\:]+?'
+ keyEqualsValuesBracesBrackets:
+ name: '[a-zA-Z@\*0-9_\/.\h\{\}:\#-]+?'
+ follow: '(?:(?<!\\)\{)|,|(?:(?<!\\)\[)'
+ NamedGroupingBracesBrackets:
+ name: '[0-9\.a-zA-Z@\*><]+?'
+ follow: '\h|\R|\{|\[|\$|\)|\('
+ UnNamedGroupingBracesBrackets:
+ follow: '\{|\[|,|&|\)|\(|\$'
+ arguments:
+ before: '(?:#\d\h*;?,?\/?)+|\<.*?\>'
+ between: '_|\^|\*'
+ modifyLineBreaks:
+ betterFullStop: '(?:\.\)(?!\h*[a-z]))|(?:(?<!(?:(?:e\.g)|(?:i\.e)|(?:etc))))\.(?!(?:[a-z]|[A-Z]|\-|~|\,|[0-9]))'
+ doubleBackSlash: '\\\\(?:\h*\[\h*\d+\h*[a-zA-Z]+\h*\])?'
+ comma: ','
diff --git a/Master/texmf-dist/scripts/latexindent/latexindent.pl b/Master/texmf-dist/scripts/latexindent/latexindent.pl
index cb2208d1176..ecdf7c79e48 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.6, 2019-05-05
+# latexindent.pl, version 3.7, 2019-07-13
#
# 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
@@ -44,6 +44,9 @@ GetOptions (
"help|h"=>\$switches{showhelp},
"cruft|c=s"=>\$switches{cruftDirectory},
"screenlog|sl"=>\$switches{screenlog},
+ "replacement|r"=>\$switches{replacement},
+ "onlyreplacement|rr"=>\$switches{onlyreplacement},
+ "replacementrespectverb|rv"=>\$switches{replacementRespectVerb},
);
# check local settings doesn't interfer with reading the file;