summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/latexindent
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2017-06-05 23:23:10 +0000
committerKarl Berry <karl@freefriends.org>2017-06-05 23:23:10 +0000
commitd024b5690e678248a097a1b55231af47c09328e1 (patch)
treea4fd859c9e19baa4bb31438bdbe452951f5fa23e /Master/texmf-dist/scripts/latexindent
parent54b6d43a181a1c487ee932cb9eb9d70344ab4b47 (diff)
latexindent (28may17)
git-svn-id: svn://tug.org/texlive/trunk@44492 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/latexindent')
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/LatexIndent/Command.pm2
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm13
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm2
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm2
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm39
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Heading.pm17
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm2
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm3
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Item.pm4
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/LatexIndent/KeyEqualsValuesBraces.pm2
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm4
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/MandatoryArgument.pm2
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm97
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm2
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/OptionalArgument.pm2
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm2
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Tokens.pm29
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/TrailingComments.pm21
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/UnNamedGroupingBracesBrackets.pm2
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm20
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/defaultSettings.yaml49
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/latexindent.pl4
22 files changed, 268 insertions, 52 deletions
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Command.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Command.pm
index 022064fd1d7..70712a03626 100755
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Command.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Command.pm
@@ -165,7 +165,7 @@ sub create_unique_id{
my $self = shift;
$commandCounter++;
- ${$self}{id} = "$tokens{command}$commandCounter";
+ ${$self}{id} = "$tokens{commands}$commandCounter";
return;
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm
index 1872f181c86..93d8c404928 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm
@@ -23,11 +23,11 @@ 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::LogFile qw/logger output_logfile processSwitches/;
-use LatexIndent::GetYamlSettings qw/readSettings modify_line_breaks_settings get_indentation_settings_for_this_object get_every_or_custom_value get_indentation_information get_object_attribute_for_indentation_settings alignment_at_ampersand_settings/;
+use LatexIndent::GetYamlSettings qw/readSettings modify_line_breaks_settings get_indentation_settings_for_this_object get_every_or_custom_value get_indentation_information get_object_attribute_for_indentation_settings alignment_at_ampersand_settings %masterSettings/;
use LatexIndent::FileExtension qw/file_extension_check/;
use LatexIndent::BackUpFileProcedure qw/create_back_up_file/;
use LatexIndent::BlankLines qw/protect_blank_lines unprotect_blank_lines condense_blank_lines/;
-use LatexIndent::ModifyLineBreaks qw/modify_line_breaks_body modify_line_breaks_end remove_line_breaks_begin adjust_line_breaks_end_parent/;
+use LatexIndent::ModifyLineBreaks qw/modify_line_breaks_body modify_line_breaks_end remove_line_breaks_begin adjust_line_breaks_end_parent max_char_per_line paragraphs_on_one_line construct_paragraph_reg_exp/;
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/;
@@ -87,6 +87,7 @@ sub operate_on_file{
$self->find_aligned_block;
$self->remove_trailing_comments;
$self->find_verbatim_environments;
+ $self->max_char_per_line;
$self->protect_blank_lines;
$self->remove_trailing_whitespace(when=>"before");
$self->find_file_contents_environments_and_preamble;
@@ -116,7 +117,7 @@ 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{
@@ -189,6 +190,12 @@ sub find_objects{
$self->logger('looking for SPECIAL begin/end');
$self->find_special;
+ # documents without preamble need a manual call to the paragraph_one_line routine
+ if ($is_m_switch_active and !${$self}{preamblePresent}){
+ ${$self}{removeParagraphLineBreaks} = ${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{all}||${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{masterDocument}||0;
+ $self->paragraphs_on_one_line ;
+ }
+
# if there are no children, return
if(${$self}{children}){
$self->logger("Objects have been found.",'heading');
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm
index 1b0ad27d550..2f6afe07e4b 100755
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm
@@ -120,7 +120,7 @@ sub create_unique_id{
my $self = shift;
$environmentCounter++;
- ${$self}{id} = "$tokens{environment}$environmentCounter";
+ ${$self}{id} = "$tokens{environments}$environmentCounter";
return;
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm
index a1b56391f2c..d4d13507a13 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm
@@ -158,6 +158,8 @@ sub find_file_contents_environments_and_preamble{
$preamble->unprotect_blank_lines;
${$self}{verbatim}{${$preamble}{id}} = $preamble;
}
+ } else {
+ ${$self}{preamblePresent} = 0;
}
# loop through the fileContents array, check if it's in the preamble
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm
index 4c93bc80426..1a9b9c1f9f8 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm
@@ -234,6 +234,7 @@ sub get_indentation_settings_for_this_object{
BodyStartsOnOwnLine=>${$self}{BodyStartsOnOwnLine},
EndStartsOnOwnLine=>${$self}{EndStartsOnOwnLine},
EndFinishesWithLineBreak=>${$self}{EndFinishesWithLineBreak},
+ removeParagraphLineBreaks=>${$self}{removeParagraphLineBreaks},
);
# don't forget alignment settings!
@@ -275,12 +276,6 @@ sub alignment_at_ampersand_settings{
# spacesBeforeDoubleBackSlash: 2
return unless ${$masterSettings{lookForAlignDelims}}{$name};
- ## check, for example,
- ## lookForAlignDelims:
- ## tabular:
- ## body: 1
- #return unless $self->get_object_attribute_for_indentation_settings;
-
if(ref ${$masterSettings{lookForAlignDelims}}{$name} eq "HASH"){
${$self}{lookForAlignDelims} = (defined ${${$masterSettings{lookForAlignDelims}}{$name}}{delims} ) ? ${${$masterSettings{lookForAlignDelims}}{$name}}{delims} : 1;
${$self}{alignDoubleBackSlash} = (defined ${${$masterSettings{lookForAlignDelims}}{$name}}{alignDoubleBackSlash} ) ? ${${$masterSettings{lookForAlignDelims}}{$name}}{alignDoubleBackSlash} : 1;
@@ -308,13 +303,43 @@ sub modify_line_breaks_settings{
# the following will *definitley* be in the array, so let's add them
push(@toBeAssignedTo,("BeginStartsOnOwnLine","BodyStartsOnOwnLine","EndStartsOnOwnLine","EndFinishesWithLineBreak"));
- # we can effeciently loop through the following
+ # we can efficiently loop through the following
foreach (@toBeAssignedTo){
$self->get_every_or_custom_value(
toBeAssignedTo=>$_,
toBeAssignedToAlias=> ${$self}{aliases}{$_} ? ${$self}{aliases}{$_} : $_,
);
}
+
+ # paragraph line break settings
+ ${$self}{removeParagraphLineBreaks} = ${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{all};
+
+ return if(${$self}{removeParagraphLineBreaks});
+
+ # the removeParagraphLineBreaks can contain fields that are hashes or scalar, for example:
+ #
+ # removeParagraphLineBreaks:
+ # all: 0
+ # environments: 0
+ # or
+ # removeParagraphLineBreaks:
+ # all: 0
+ # environments:
+ # quotation: 0
+
+ # 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};
+
+ if(ref ${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{$YamlName} eq "HASH"){
+ $self->logger("$YamlName specified with fields in removeParagraphLineBreaks, looking for $name") if $is_t_switch_active;
+ ${$self}{removeParagraphLineBreaks} = ${${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{$YamlName}}{$name}||0;
+ } else {
+ $self->logger("$YamlName specified with just a number in removeParagraphLineBreaks ${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{$YamlName}") if $is_t_switch_active;
+ ${$self}{removeParagraphLineBreaks} = ${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{$YamlName};
+ }
return;
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Heading.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Heading.pm
index be7ea36661d..6cca3c26695 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Heading.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Heading.pm
@@ -34,6 +34,9 @@ sub construct_headings_levels{
# grab the heading levels
my %headingsLevels = %{$masterSettings{indentAfterHeadings}};
+ # output to log file
+ $self->logger("Constructing headings reg exp for example, chapter, section, etc (see indentAfterThisHeading)") if $is_t_switch_active ;
+
# delete the values that have indentAfterThisHeading set to 0
while( my ($headingName,$headingInfo)= each %headingsLevels){
if(!${$headingsLevels{$headingName}}{indentAfterThisHeading}){
@@ -42,10 +45,10 @@ sub construct_headings_levels{
} else {
# *all heading* regexp, remembering put starred headings at the front of the regexp
if($headingName =~ m/\*/){
- $self->logger("Putting $headingName at the beginning of the allHeadings regexp, as it contains a *");
+ $self->logger("Putting $headingName at the beginning of the allHeadings regexp, as it contains a *") if $is_t_switch_active ;
$allHeadingsRegexp = $headingName.($allHeadingsRegexp eq '' ?q():"|$allHeadingsRegexp");
} else {
- $self->logger("Putting $headingName at the END of the allHeadings regexp, as it contains a *");
+ $self->logger("Putting $headingName at the END of the allHeadings regexp, as it contains a *") if $is_t_switch_active ;
$allHeadingsRegexp .= ($allHeadingsRegexp eq '' ?q():"|").$headingName ;
}
}
@@ -60,8 +63,8 @@ sub construct_headings_levels{
# it could be that @sortedByLevels is empty;
return if !@sortedByLevels;
- $self->logger("All headings regexp: $allHeadingsRegexp",'heading');
- $self->logger("Now to construct headings regexp for each level:",'heading');
+ $self->logger("All headings regexp: $allHeadingsRegexp",'heading') if $is_t_switch_active;
+ $self->logger("Now to construct headings regexp for each level:",'heading') if $is_t_switch_active;
# loop through the levels, and create a regexp for each (min and max values are the first and last values respectively from sortedByLevels)
for(my $i = ${$headingsLevels{$sortedByLevels[0]}}{level}; $i <= ${$headingsLevels{$sortedByLevels[-1]}}{level}; $i++ ){
@@ -72,10 +75,10 @@ sub construct_headings_levels{
foreach(@tmp){
# put starred headings at the front of the regexp
if($_ =~ m/\*/){
- $self->logger("Putting $_ at the beginning of this regexp, as it contains a *");
+ $self->logger("Putting $_ at the beginning of this regexp, as it contains a *") if $is_t_switch_active;
$headingsAtThisLevel = $_.($headingsAtThisLevel eq '' ?q():"|$headingsAtThisLevel");
} else {
- $self->logger("Putting $_ at the END of this regexp, as it contains a *");
+ $self->logger("Putting $_ at the END of this regexp, as it contains a *") if $is_t_switch_active;
$headingsAtThisLevel .= ($headingsAtThisLevel eq '' ?q():"|").$_ ;
}
}
@@ -161,7 +164,7 @@ sub create_unique_id{
$headingCounter++;
- ${$self}{id} = "$tokens{heading}$headingCounter";
+ ${$self}{id} = "$tokens{afterHeading}$headingCounter";
return;
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm
index e1ac17b3613..a98cebf05e2 100755
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm
@@ -182,7 +182,7 @@ sub create_unique_id{
$ifElseFiCounter++;
- ${$self}{id} = "$tokens{ifelsefi}$ifElseFiCounter";
+ ${$self}{id} = "$tokens{ifElseFi}$ifElseFiCounter";
return;
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm
index 600aed5040f..f0cf33aa23f 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm
@@ -120,6 +120,9 @@ sub indent_body{
# some objects can format their body to align at the & character
$self->align_at_ampersand if ${$self}{lookForAlignDelims};
+ # possibly remove paragraph line breaks
+ $self->paragraphs_on_one_line if $is_m_switch_active;
+
# body indendation
if(${$self}{linebreaksAtEnd}{begin}==1){
if(${$self}{body} =~ m/^\h*$/s){
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Item.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Item.pm
index d85f4e24c31..1166282895d 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Item.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Item.pm
@@ -23,7 +23,7 @@ use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/;
use Data::Dumper;
use Exporter qw/import/;
our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321
-our @EXPORT_OK = qw/find_items construct_list_of_items/;
+our @EXPORT_OK = qw/find_items construct_list_of_items $listOfItems/;
our $itemCounter;
our $listOfItems = q();
our $itemRegExp;
@@ -111,7 +111,7 @@ sub create_unique_id{
$itemCounter++;
- ${$self}{id} = "$tokens{item}$itemCounter";
+ ${$self}{id} = "$tokens{items}$itemCounter";
return;
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/KeyEqualsValuesBraces.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/KeyEqualsValuesBraces.pm
index 41fcb981a15..974003d3a87 100755
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/KeyEqualsValuesBraces.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/KeyEqualsValuesBraces.pm
@@ -106,7 +106,7 @@ sub create_unique_id{
my $self = shift;
$key_equals_values_braces_Counter++;
- ${$self}{id} = "$tokens{key_equals_values_braces}$key_equals_values_braces_Counter";
+ ${$self}{id} = "$tokens{keyEqualsValuesBracesBrackets}$key_equals_values_braces_Counter";
return;
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm
index 309d8355bea..eca7ae7aad5 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm
@@ -41,7 +41,7 @@ sub processSwitches{
my $self = shift;
# details of the script to log file
- $self->logger("$FindBin::Script version 3.0.2, a script to indent .tex files",'heading');
+ $self->logger("$FindBin::Script version 3.1, a script to indent .tex files",'heading');
$self->logger("$FindBin::Script lives here: $FindBin::RealBin/");
# time the script is used
@@ -50,7 +50,7 @@ sub processSwitches{
if(scalar(@ARGV) < 1 or $switches{showhelp}) {
print <<ENDQUOTE
-latexindent.pl version 3.0.2
+latexindent.pl version 3.1
usage: latexindent.pl [options] [file][.tex|.sty|.cls|.bib|...]
-h, --help
help (see the documentation for detailed instructions and examples)
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/MandatoryArgument.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/MandatoryArgument.pm
index 172e002eda4..47b538d2ca2 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/MandatoryArgument.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/MandatoryArgument.pm
@@ -78,7 +78,7 @@ sub create_unique_id{
my $self = shift;
$mandatoryArgumentCounter++;
- ${$self}{id} = "$tokens{mandatoryArgument}$mandatoryArgumentCounter";
+ ${$self}{id} = "$tokens{mandatoryArguments}$mandatoryArgumentCounter";
return;
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm
index bcfb2336264..3f0148d4670 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm
@@ -18,11 +18,15 @@ use strict;
use warnings;
use Data::Dumper;
use Exporter qw/import/;
+use Text::Wrap;
+use LatexIndent::GetYamlSettings qw/%masterSettings/;
use LatexIndent::Tokens qw/%tokens/;
use LatexIndent::TrailingComments qw/$trailingCommentRegExp/;
use LatexIndent::Switches qw/$is_m_switch_active $is_t_switch_active $is_tt_switch_active/;
-our @EXPORT_OK = qw/modify_line_breaks_body modify_line_breaks_end adjust_line_breaks_end_parent remove_line_breaks_begin/;
-our @allObjects;
+use LatexIndent::Item qw/$listOfItems/;
+our @EXPORT_OK = qw/modify_line_breaks_body modify_line_breaks_end adjust_line_breaks_end_parent remove_line_breaks_begin max_char_per_line paragraphs_on_one_line construct_paragraph_reg_exp/;
+our $paragraphRegExp = q();
+
sub modify_line_breaks_body{
my $self = shift;
@@ -171,4 +175,93 @@ sub adjust_line_breaks_end_parent{
}
+sub max_char_per_line{
+ return unless $is_m_switch_active;
+
+ my $self = shift;
+ return unless ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}>1;
+
+ # call the text wrapping routine
+ $Text::Wrap::columns=${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns};
+ if(${$masterSettings{modifyLineBreaks}{textWrapOptions}}{separator} ne ''){
+ $Text::Wrap::separator=${$masterSettings{modifyLineBreaks}{textWrapOptions}}{separator};
+ }
+ ${$self}{body} = wrap('','',${$self}{body});
+}
+
+sub construct_paragraph_reg_exp{
+ my $self = shift;
+
+ my $stopAtRegExp = q();
+ while( my ($paragraphStopAt,$yesNo)= each %{${$masterSettings{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
+ $self->logger("The paragraph-stop regexp WILL include $tokens{$paragraphStopAt} (see paragraphsStopAt)",'heading') if $is_t_switch_active ;
+
+ # update the regexp
+ if($paragraphStopAt eq "items"){
+ $stopAtRegExp .= "|(?:\\\\(?:".$listOfItems."))";
+ } else {
+ $stopAtRegExp .= "|(?:".($paragraphStopAt eq "trailingComment" ? "%" : q() ).$tokens{$paragraphStopAt}."\\d+)";
+ }
+ } else {
+ $self->logger("The paragraph-stop regexp won't include $tokens{$paragraphStopAt} (see paragraphsStopAt)",'heading') if $is_t_switch_active ;
+ }
+ }
+
+ $paragraphRegExp = qr/
+ ^
+ (?!$tokens{beginOfToken})
+ (\w
+ (?:
+ (?!
+ (?:$tokens{blanklines}|\\par)
+ ).
+ )*?
+ )
+ (
+ (?:
+ ^(?:(\h*\R)|\\par|$tokens{blanklines}$stopAtRegExp)
+ )
+ |
+ \z # end of string
+ )/sxm;
+
+ $self->logger("The paragraph-stop-regexp is:",'heading') if $is_tt_switch_active ;
+ $self->logger($paragraphRegExp) if $is_tt_switch_active ;
+}
+
+sub paragraphs_on_one_line{
+ my $self = shift;
+ return unless ${$self}{removeParagraphLineBreaks};
+
+ # alignment at ampersand can take priority
+ return if(${$self}{lookForAlignDelims} and ${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{alignAtAmpersandTakesPriority});
+
+ $self->logger("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/Master/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm
index ea2c5323cf3..f7469504e10 100755
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm
@@ -55,7 +55,7 @@ sub create_unique_id{
my $self = shift;
$groupingBracesCounter++;
- ${$self}{id} = "$tokens{groupingBraces}$groupingBracesCounter";
+ ${$self}{id} = "$tokens{namedGroupingBracesBrackets}$groupingBracesCounter";
return;
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/OptionalArgument.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/OptionalArgument.pm
index b949e9b7e92..a44ca52a51d 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/OptionalArgument.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/OptionalArgument.pm
@@ -97,7 +97,7 @@ sub create_unique_id{
my $self = shift;
$optionalArgumentCounter++;
- ${$self}{id} = "$tokens{optionalArgument}$optionalArgumentCounter";
+ ${$self}{id} = "$tokens{optionalArguments}$optionalArgumentCounter";
return;
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm
index ba7b905b492..d278d80e75c 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm
@@ -177,7 +177,7 @@ sub create_unique_id{
$specialCounter++;
- ${$self}{id} = "$tokens{special}$specialCounter";
+ ${$self}{id} = "$tokens{specialBeginEnd}$specialCounter";
return;
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Tokens.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Tokens.pm
index 8a9a100dc26..e50c66d25d0 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Tokens.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Tokens.pm
@@ -26,28 +26,31 @@ my $ifelsefiSpecial = "!-!";
# the %tokens hash is passed around many modules
our %tokens = (
- environment=>$beginningToken."ENVIRONMENT",
- ifelsefiSpecial=>$ifelsefiSpecial,
- ifelsefi=>$ifelsefiSpecial.$beginningToken."IFELSEFI",
- item=>$beginningToken."ITEMS",
+ # user-facing naming convention
+ environments=>$beginningToken."ENVIRONMENT",
+ commands=>$beginningToken."COMMAND",
+ optionalArguments=>$beginningToken."OPTIONAL-ARGUMENT",
+ mandatoryArguments=>$beginningToken."MANDATORY-ARGUMENT",
+ ifElseFi=>$ifelsefiSpecial.$beginningToken."IFELSEFI",
+ items=>$beginningToken."ITEMS",
+ keyEqualsValuesBracesBrackets=>$beginningToken."KEY-VALUE-BRACES",
+ namedGroupingBracesBrackets=>$beginningToken."GROUPING-BRACES",
+ UnNamedGroupingBracesBrackets=>$beginningToken."UN-NAMED-GROUPING-BRACES",
+ specialBeginEnd=>$beginningToken."SPECIAL",
+ afterHeading=>$beginningToken."HEADING",
+ filecontents=>$beginningToken."FILECONTENTS",
+ # internal-facing naming convention
trailingComment=>"latexindenttrailingcomment",
+ ifelsefiSpecial=>$ifelsefiSpecial,
blanklines=>$beginningToken."blank-line",
arguments=>$beginningToken."ARGUMENTS",
- optionalArgument=>$beginningToken."OPTIONAL-ARGUMENT",
- mandatoryArgument=>$beginningToken."MANDATORY-ARGUMENT",
roundBracket=>$beginningToken."ROUND-BRACKET",
verbatim=>$beginningToken."VERBATIM",
- command=>$beginningToken."COMMAND",
- key_equals_values_braces=>$beginningToken."KEY-VALUE-BRACES",
- groupingBraces=>$beginningToken."GROUPING-BRACES",
- unNamedgroupingBraces=>$beginningToken."UN-NAMED-GROUPING-BRACES",
- special=>$beginningToken."SPECIAL",
- heading=>$beginningToken."HEADING",
- filecontents=>$beginningToken."FILECONTENTS",
preamble=>$beginningToken."preamble",
beginOfToken=>$beginningToken,
doubleBackSlash=>$beginningToken."DOUBLEBACKSLASH",
alignmentBlock=>$beginningToken."ALIGNMENTBLOCK",
+ paragraph=>$beginningToken."PARA",
endOfToken=>"-END",
);
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/TrailingComments.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/TrailingComments.pm
index f8987d271f1..cbc35f6eee7 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/TrailingComments.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/TrailingComments.pm
@@ -17,7 +17,8 @@ package LatexIndent::TrailingComments;
use strict;
use warnings;
use LatexIndent::Tokens qw/%tokens/;
-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::GetYamlSettings qw/%masterSettings/;
use Data::Dumper;
use Exporter qw/import/;
our @EXPORT_OK = qw/remove_trailing_comments put_trailing_comments_back_in $trailingCommentRegExp add_comment_symbol construct_trailing_comment_regexp/;
@@ -90,6 +91,24 @@ sub put_trailing_comments_back_in{
while( my $comment = pop @trailingComments){
my $trailingcommentID = ${$comment}{id};
my $trailingcommentValue = ${$comment}{value};
+
+ # 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){
+ $self->logger("$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;
+
+ # construct a reg exp that contains possible line breaks in between each character
+ if(${$masterSettings{modifyLineBreaks}{textWrapOptions}}{separator} ne ''){
+ $trailingcommentIDwithLineBreaks = join("\\".${$masterSettings{modifyLineBreaks}{textWrapOptions}}{separator}."?",split(//,$trailingcommentID));
+ } else {
+ $trailingcommentIDwithLineBreaks = join("\\R?",split(//,$trailingcommentID));
+ }
+ my $trailingcommentIDwithLineBreaksRegExp = qr/$trailingcommentIDwithLineBreaks/s;
+
+ # replace the line-broken trailing comment ID with a non-broken trailing comment ID
+ ${$self}{body} =~ s/%$trailingcommentIDwithLineBreaksRegExp/%$trailingcommentID/s;
+ }
if(${$self}{body} =~ m/%$trailingcommentID
(
(?! # not immediately preceeded by
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/UnNamedGroupingBracesBrackets.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/UnNamedGroupingBracesBrackets.pm
index 268f5b5adfa..30c969076c7 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/UnNamedGroupingBracesBrackets.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/UnNamedGroupingBracesBrackets.pm
@@ -68,7 +68,7 @@ sub create_unique_id{
my $self = shift;
$unNamedGroupingBracesCounter++;
- ${$self}{id} = "$tokens{unNamedgroupingBraces}$unNamedGroupingBracesCounter";
+ ${$self}{id} = "$tokens{UnNamedGroupingBracesBrackets}$unNamedGroupingBracesCounter";
return;
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm
index f3804aaf94d..ba6b698175e 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm
@@ -18,7 +18,7 @@ use strict;
use warnings;
use LatexIndent::Tokens qw/%tokens/;
use LatexIndent::GetYamlSettings qw/%masterSettings/;
-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 Data::Dumper;
use Exporter qw/import/;
our @EXPORT_OK = qw/put_verbatim_back_in find_verbatim_environments find_noindent_block find_verbatim_commands put_verbatim_commands_back_in/;
@@ -236,6 +236,15 @@ sub put_verbatim_back_in {
# delete the hash so it won't be operated upon again
delete ${$self}{verbatim}{${$child}{id}};
$self->logger("deleted key") if $is_t_switch_active;
+ } elsif ($is_m_switch_active and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}>1 and ${$self}{body} !~ m/${$child}{id}/){
+ $self->logger("${$child}{id} not found in body using /m matching, it may have been split across line (see modifyLineBreaks: textWrapOptions)") if($is_t_switch_active);
+
+ # search for a version of the verbatim ID that may have line breaks
+ my $verbatimIDwithLineBreaks = join("\\R?",split(//,${$child}{id}));
+ my $verbatimIDwithLineBreaksRegExp = qr/$verbatimIDwithLineBreaks/s;
+
+ # replace the line-broken verbatim ID with a non-broken verbatim ID
+ ${$self}{body} =~ s/$verbatimIDwithLineBreaksRegExp/${$child}{id}/s;
}
}
}
@@ -273,6 +282,15 @@ sub put_verbatim_commands_back_in {
# delete the hash so it won't be operated upon again
delete ${$self}{verbatimCommands}{${$child}{id}};
$self->logger("deleted key") if $is_t_switch_active;
+ } elsif ($is_m_switch_active and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}>1 and ${$self}{body} !~ m/${$child}{id}/){
+ $self->logger("${$child}{id} not found in body using /m matching, it may have been split across line (see modifyLineBreaks: textWrapOptions)") if($is_t_switch_active);
+
+ # search for a version of the verbatim ID that may have line breaks
+ my $verbatimIDwithLineBreaks = join("\\R?",split(//,${$child}{id}));
+ my $verbatimIDwithLineBreaksRegExp = qr/$verbatimIDwithLineBreaks/s;
+
+ # replace the line-broken verbatim ID with a non-broken verbatim ID
+ ${$self}{body} =~ s/$verbatimIDwithLineBreaksRegExp/${$child}{id}/s;
}
}
}
diff --git a/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml b/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml
index 20040817b12..fbc5401c3e9 100755
--- a/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml
+++ b/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml
@@ -1,17 +1,33 @@
-#
-# defaultSettings.yaml for latexindent.pl, version 3.0
+# defaultSettings.yaml for latexindent.pl, version 3.1, 2017-05-27
# a script that aims to
# beautify .tex, .sty, .cls files
#
# (or latexindent.exe if you're on Windows)
#
+# 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
+
+
# You're welcome to change anything you like in here, but
# it would probably be better to have your own user settings
# files somewhere else- remember that this file may be overwritten
# anytime that you update your distribution. Please see the manual
# for details of how to setup your own settings files.
#
-# Please read the manual first to understand what each switch does :)
+# Please read the manual first to understand what each switch does.
# latexindent can be called without a file extension,
# e.g, simply
@@ -71,6 +87,7 @@ logFilePreferences:
verbatimEnvironments:
verbatim: 1
lstlisting: 1
+ minted: 1
# verbatim commands such as \verb! body !, \lstinline$something else$
verbatimCommands:
@@ -155,6 +172,7 @@ lookForAlignDelims:
indentAfterItems:
itemize: 1
enumerate: 1
+ description: 1
list: 1
# if you want to use other names for your items (such as, for example, part)
@@ -356,6 +374,31 @@ commandCodeBlocks:
modifyLineBreaks:
preserveBlankLines: 1
condenseMultipleBlankLinesInto: 1
+ textWrapOptions:
+ columns: 0
+ separator: ""
+ removeParagraphLineBreaks:
+ all: 0
+ alignAtAmpersandTakesPriority: 1
+ environments:
+ quotation: 0
+ ifElseFi: 0
+ optionalArguments: 0
+ mandatoryArguments: 0
+ items: 0
+ specialBeginEnd: 0
+ afterHeading: 0
+ filecontents: 0
+ masterDocument: 0
+ paragraphsStopAt:
+ environments: 1
+ commands: 0
+ ifElseFi: 0
+ items: 0
+ specialBeginEnd: 0
+ heading: 0
+ filecontents: 0
+ comments: 0
environments:
BeginStartsOnOwnLine: 0
BodyStartsOnOwnLine: 0
diff --git a/Master/texmf-dist/scripts/latexindent/latexindent.pl b/Master/texmf-dist/scripts/latexindent/latexindent.pl
index 7cfe4a98bbd..b4474a14c49 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.0.2, 2017-05-12
+# latexindent.pl, version 3.1, 2017-05-27
#
# 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
@@ -67,6 +67,6 @@ if(defined($switches{readLocalSettings}) and ($switches{readLocalSettings} eq ''
$switches{readLocalSettings} = 'localSettings.yaml';
}
-my $document = LatexIndent::Document->new(name=>"masterdocument",fileName=>$ARGV[0],switches=>\%switches);
+my $document = LatexIndent::Document->new(name=>"masterDocument",fileName=>$ARGV[0],switches=>\%switches);
$document->latexindent;
exit(0);