diff options
Diffstat (limited to 'support')
25 files changed, 491 insertions, 146 deletions
diff --git a/support/latexindent/LatexIndent/AlignmentAtAmpersand.pm b/support/latexindent/LatexIndent/AlignmentAtAmpersand.pm index 8f67d62c58..6607bf6c9d 100644 --- a/support/latexindent/LatexIndent/AlignmentAtAmpersand.pm +++ b/support/latexindent/LatexIndent/AlignmentAtAmpersand.pm @@ -16,20 +16,18 @@ package LatexIndent::AlignmentAtAmpersand; # For all communication, please visit: https://github.com/cmhughes/latexindent.pl use strict; use warnings; -use utf8; -use Unicode::GCString; use Data::Dumper; use Exporter qw/import/; use List::Util qw/max min sum/; 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 %switches/; use LatexIndent::GetYamlSettings qw/%mainSettings/; use LatexIndent::Tokens qw/%tokens/; use LatexIndent::LogFile qw/$logger/; use LatexIndent::HiddenChildren qw/%familyTree/; use LatexIndent::Verbatim qw/%verbatimStorage/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 -our @EXPORT_OK = qw/align_at_ampersand find_aligned_block double_back_slash_else main_formatting individual_padding multicolumn_padding multicolumn_pre_check multicolumn_post_check dont_measure hidden_child_cell_row_width hidden_child_row_width /; +our @EXPORT_OK = qw/align_at_ampersand find_aligned_block double_back_slash_else main_formatting individual_padding multicolumn_padding multicolumn_pre_check multicolumn_post_check dont_measure hidden_child_cell_row_width hidden_child_row_width get_column_width/; our $alignmentBlockCounter; our @cellStorage; # two-dimensional storage array containing the cell information our @formattedBody; # array for the new body @@ -38,6 +36,7 @@ our @maxColumnWidth; our @maxDelimiterWidth; sub find_aligned_block{ + my $self = shift; return unless (${$self}{body} =~ m/(?!<\\)%\*\h*\\begin\{/s); @@ -246,7 +245,7 @@ sub align_at_ampersand{ # for the *previous* cell my $spanningOffSet = ($spanning > 0 ? $spanning - 1 : 0); ${$cellStorage[$rowCounter][$columnCounter - $spanningOffSet]}{delimiter} = $1; - ${$cellStorage[$rowCounter][$columnCounter - $spanningOffSet]}{delimiterLength} = Unicode::GCString->new($1)->columns(); + ${$cellStorage[$rowCounter][$columnCounter - $spanningOffSet]}{delimiterLength} = &get_column_width($1); # keep track of maximum delimiter width $maxDelimiterWidth[$columnCounter - $spanningOffSet] = @@ -273,7 +272,7 @@ sub align_at_ampersand{ # basic cell storage $cellStorage[$rowCounter][$columnCounter] - = ({width=>Unicode::GCString->new($column)->columns(), + = ({width=>&get_column_width($column), entry=>$column, type=>($numberOfAmpersands>0 ? "X" : "*"), groupPadding=>0, @@ -443,7 +442,7 @@ sub align_at_ampersand{ if( (${$self}{begin} eq '{' | ${$self}{begin} eq '[') and ${$self}{parentBegin}){ $lengthOfBegin = ${$self}{parentBegin}."{"; } - ${$self}{indentation} = " " x Unicode::GCString->new($lengthOfBegin)->columns(); + ${$self}{indentation} = " " x (&get_column_width($lengthOfBegin)); $logger->trace("Adjusting indentation of ${$self}{name} in AlignAtAmpersand routine") if($is_t_switch_active); } } @@ -540,7 +539,7 @@ sub main_formatting { # objective (2): calculate row width and update maximumRowWidth # objective (2): calculate row width and update maximumRowWidth # objective (2): calculate row width and update maximumRowWidth - my $rowWidth = Unicode::GCString->new($tmpRow)->columns(); + my $rowWidth = &get_column_width($tmpRow); # possibly update rowWidth if there are hidden children; see test-cases/alignment/hidden-child1.tex and friends $rowWidth = $self->hidden_child_row_width($tmpRow,$rowCount,$rowWidth) if(${$self}{measureHiddenChildren} or ${$self}{measureVerbatim}); @@ -1434,12 +1433,12 @@ sub hidden_child_cell_row_width{ if($bodyLineBreaks>0){ my $maxRowWidthWithinCell = 0; foreach(split("\n",$tmpCellEntry)){ - my $currentRowWidth = Unicode::GCString->new($_)->columns(); + my $currentRowWidth = &get_column_width($_); $maxRowWidthWithinCell = $currentRowWidth if ($currentRowWidth > $maxRowWidthWithinCell ); } ${$cellStorage[$rowCounter][$columnCounter]}{width} = $maxRowWidthWithinCell; } else { - ${$cellStorage[$rowCounter][$columnCounter]}{width} = Unicode::GCString->new($tmpCellEntry)->columns(); + ${$cellStorage[$rowCounter][$columnCounter]}{width} = &get_column_width($tmpCellEntry); } } @@ -1481,7 +1480,7 @@ sub hidden_child_row_width{ if( (${$self}{begin} eq '{' | ${$self}{begin} eq '[') and ${$self}{parentBegin}){ $beginToMeasure = ${$self}{parentBegin}."{"; } - $lengthOfBegin = Unicode::GCString->new($beginToMeasure)->columns(); + $lengthOfBegin = &get_column_width($beginToMeasure); $tmpRow = $beginToMeasure.$tmpRow if $rowCount == 0; } @@ -1492,7 +1491,7 @@ sub hidden_child_row_width{ for my $hiddenChildToMeasure (@{${$self}{measureHiddenChildren}}){ if($tmpRow=~m/(^.*)?$hiddenChildToMeasure/m and defined $familyTree{$hiddenChildToMeasure}{bodyForMeasure}){ my $partBeforeId = $1; - my $lengthPartBeforeId = Unicode::GCString->new($partBeforeId)->columns(); + my $lengthPartBeforeId = &get_column_width($partBeforeId); foreach (@{$familyTree{$hiddenChildToMeasure}{ancestors}}){ if (${$_}{ancestorID} eq ${$self}{id}){ @@ -1536,17 +1535,17 @@ sub hidden_child_row_width{ my $maxRowWidth = 0; foreach(split("\n",$tmpRow)){ - my $currentRowWidth = Unicode::GCString->new($_)->columns(); + my $currentRowWidth = &get_column_width($_); $maxRowWidth = $currentRowWidth if ($currentRowWidth > $maxRowWidth ); } $rowWidth = $maxRowWidth; } else { - $rowWidth = Unicode::GCString->new($tmpRow)->columns(); + $rowWidth = &get_column_width($tmpRow); } } elsif (!${${$self}{linebreaksAtEnd}}{begin} and ${$cellStorage[0][0]}{type} eq "X" and ${$cellStorage[0][0]}{measureThis}){ - $rowWidth = Unicode::GCString->new($tmpRow)->columns(); + $rowWidth = &get_column_width($tmpRow); } # possibly draw ruler to log file @@ -1567,7 +1566,7 @@ sub draw_ruler_to_logfile{ $logger->trace("*tmpRow:"); foreach(split("\n",$tmpRow)){ - my $currentRowWidth = Unicode::GCString->new($_)->columns(); + my $currentRowWidth = &get_column_width($_); $logger->trace("$_ \t(length: $currentRowWidth)"); } @@ -1579,4 +1578,20 @@ sub draw_ruler_to_logfile{ $logger->trace($ruler); } + +sub get_column_width{ + + my $stringToBeMeasured = $_[0]; + + # default length measurement + # credit/reference: https://perldoc.perl.org/perlunicook#%E2%84%9E-33:-String-length-in-graphemes + unless ($switches{GCString}){ + my $count = 0; + while ($stringToBeMeasured =~ /\X/g) { $count++ } + return $count; + } + + # if GCString actice, then use Unicode::GCString + return Unicode::GCString->new($stringToBeMeasured)->columns(); +} 1; diff --git a/support/latexindent/LatexIndent/BackUpFileProcedure.pm b/support/latexindent/LatexIndent/BackUpFileProcedure.pm index e74b3fd75f..bcc2bb0fb3 100644 --- a/support/latexindent/LatexIndent/BackUpFileProcedure.pm +++ b/support/latexindent/LatexIndent/BackUpFileProcedure.pm @@ -22,14 +22,14 @@ use LatexIndent::LogFile qw/$logger/; use File::Basename; # to get the filename and directory path use File::Copy; # to copy the original file to backup (if overwrite option set) use Exporter qw/import/; -our @EXPORT_OK = qw/create_back_up_file/; +our @EXPORT_OK = qw/create_back_up_file check_if_different/; # copy main file to a back up in the case of the overwrite switch being active sub create_back_up_file{ my $self = shift; - return unless($switches{overwrite}); + return unless(${$self}{overwrite}); # if we want to over write the current file create a backup first $logger->info("*Backup procedure (-w flag active):"); @@ -147,4 +147,21 @@ sub create_back_up_file{ exit(5); } } + +sub check_if_different{ + my $self = shift; + + if (${$self}{originalBody} eq ${$self}{body}){ + $logger->info("*-wd switch active"); + $logger->info("Original body matches indented body, NOT overwriting, no back up files created"); + return; + } + + # otherwise, continue + $logger->info("*-wd switch active"); + $logger->info("Original body is *different* from indented body"); + $logger->info("activating overwrite switch, -w"); + ${$self}{overwrite}=1; + $self->create_back_up_file; +} 1; diff --git a/support/latexindent/LatexIndent/Document.pm b/support/latexindent/LatexIndent/Document.pm index 2ad655a56a..34eb16919b 100644 --- a/support/latexindent/LatexIndent/Document.pm +++ b/support/latexindent/LatexIndent/Document.pm @@ -17,7 +17,7 @@ package LatexIndent::Document; use strict; use warnings; use Data::Dumper; -use utf8; +use File::Basename; # to get the filename and directory path use open ':std', ':encoding(UTF-8)'; # gain access to subroutines in the following modules @@ -29,7 +29,7 @@ use LatexIndent::Lines qw/lines_body_selected_lines lines_verbatim_create_line_b 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 %mainSettings /; use LatexIndent::FileExtension qw/file_extension_check/; -use LatexIndent::BackUpFileProcedure qw/create_back_up_file/; +use LatexIndent::BackUpFileProcedure qw/create_back_up_file check_if_different/; use LatexIndent::BlankLines qw/protect_blank_lines unprotect_blank_lines condense_blank_lines/; use LatexIndent::ModifyLineBreaks qw/modify_line_breaks_body modify_line_breaks_end modify_line_breaks_end_after remove_line_breaks_begin adjust_line_breaks_end_parent verbatim_modify_line_breaks/; use LatexIndent::Sentence qw/one_sentence_per_line/; @@ -77,14 +77,72 @@ sub new{ sub latexindent{ my $self = shift; + my @fileNames = @{$_[0]}; + + my $check_switch_status_across_files = 0; + + my $file_extension_status_across_files = 0; + + # one-time operations $self->store_switches; - $self->process_switches; + ${$self}{fileName} = $fileNames[0]; + $self->process_switches(\@fileNames); $self->yaml_read_settings; - $self->file_extension_check; - $self->operate_on_file; + + ${$self}{multipleFiles} = 1 if ( (scalar (@fileNames)) >1 ); + + my $fileCount = 0; + + # per-file operations + foreach (@fileNames) { + $fileCount++; + if ( (scalar (@fileNames)) >1 ){ + $logger->info("*Filename: $_ (".$fileCount." of ".(scalar (@fileNames)).")") ; + } + ${$self}{fileName} = $_; + ${$self}{cruftDirectory} = $switches{cruftDirectory}||(dirname ${$self}{fileName}); + + # file existence/extension checks + my $file_existence = $self->file_extension_check; + if ($file_existence>0){ + $file_extension_status_across_files=$file_existence; + next + } + + # overwrite and overwriteIfDifferent switches, per file + ${$self}{overwrite} = $switches{overwrite}; + ${$self}{overwriteIfDifferent} = $switches{overwriteIfDifferent}; + + # the main operations + $self->operate_on_file; + + # keep track of check status across files + $check_switch_status_across_files = 1 if ($is_check_switch_active and ${$self}{originalBody} ne ${$self}{body}); + } + + # check switch summary across multiple files + if ( $is_check_switch_active and (scalar (@fileNames)) >1 ){ + if($check_switch_status_across_files){ + $logger->info("*check switch across multiple files: differences to report from at least one file"); + } else { + $logger->info("*check switch across multiple files: no differences to report"); + } + } + + # logging of existence check + if ($file_extension_status_across_files>2){ + $logger->warn("*at least one of the files you specified does not exist or could not be read"); + } + + # output the log file information + $self->output_logfile(); + + if ($file_extension_status_across_files>2){ + exit($file_extension_status_across_files); + } # check switch active, and file changed, gives different exit code - if ($is_check_switch_active and ${$self}{originalBody} ne ${$self}{body}){ + if ($check_switch_status_across_files){ exit(1); } } @@ -124,6 +182,7 @@ sub operate_on_file{ $self->put_verbatim_back_in (match=>"just-commands"); $self->make_replacements(when=>"after") if ($is_r_switch_active and !$is_rv_switch_active); ${$self}{body} =~ s/\r\n/\n/sg if $mainSettings{dos2unixlinebreaks}; + $self->check_if_different if ${$self}{overwriteIfDifferent}; } $self->output_indented_text; return @@ -152,23 +211,20 @@ sub output_indented_text{ $logger->info("*Output routine:"); # if -overwrite is active then output to original fileName - if($switches{overwrite}) { + if(${$self}{overwrite}){ $logger->info("Overwriting file ${$self}{fileName}"); open(OUTPUTFILE,">",${$self}{fileName}); print OUTPUTFILE ${$self}{body}; close(OUTPUTFILE); } elsif($switches{outputToFile}) { - $logger->info("Outputting to file $switches{outputToFile}"); - open(OUTPUTFILE,">",$switches{outputToFile}); + $logger->info("Outputting to file ${$self}{outputToFile}"); + open(OUTPUTFILE,">",${$self}{outputToFile}); print OUTPUTFILE ${$self}{body}; close(OUTPUTFILE); } else { $logger->info("Not outputting to file; see -w and -o switches for more options."); } - # output the log file information - $self->output_logfile(); - # output to screen, unless silent mode print ${$self}{body} unless $switches{silentMode}; diff --git a/support/latexindent/LatexIndent/FileExtension.pm b/support/latexindent/LatexIndent/FileExtension.pm index a9ff031493..6dc2b69641 100644 --- a/support/latexindent/LatexIndent/FileExtension.pm +++ b/support/latexindent/LatexIndent/FileExtension.pm @@ -16,7 +16,6 @@ package LatexIndent::FileExtension; # For all communication, please visit: https://github.com/cmhughes/latexindent.pl use strict; use warnings; -use utf8; use PerlIO::encoding; use open ':std', ':encoding(UTF-8)'; use File::Basename; # to get the filename and directory path @@ -65,22 +64,34 @@ sub file_extension_check{ } } unless($fileFound){ - $logger->fatal("*I couldn't find a match for $fileName in fileExtensionPreference (see defaultSettings.yaml)"); - foreach (@fileExtensions ){ - $logger->fatal("I searched for $fileName$_"); + if (defined ${$self}{multipleFiles}){ + $logger->warn("*I couldn't find a match for $fileName in fileExtensionPreference (see defaultSettings.yaml)"); + $logger->warn("moving on, no indendation done for ${$self}{fileName}."); + return 3; + } else { + $logger->fatal("*I couldn't find a match for $fileName in fileExtensionPreference (see defaultSettings.yaml)"); + foreach (@fileExtensions ){ + $logger->fatal("I searched for $fileName$_"); + } + $logger->fatal("but couldn't find any of them.\nConsider updating fileExtensionPreference."); + $logger->fatal("*Exiting, no indendation done."); + $self->output_logfile(); + exit(3); } - $logger->fatal("but couldn't find any of them.\nConsider updating fileExtensionPreference."); - $logger->fatal("*Exiting, no indendation done."); - $self->output_logfile(); - exit(3); } } else { # if the file has a recognised extension, check that the file exists unless( -e $fileName ){ - $logger->fatal("*I couldn't find $fileName, are you sure it exists?"); - $logger->fatal("Exiting, no indendation done."); - $self->output_logfile(); - exit(3); + if (defined ${$self}{multipleFiles}){ + $logger->warn("*I couldn't find $fileName, are you sure it exists?"); + $logger->warn("moving on, no indendation done for ${$self}{fileName}."); + return 3; + } else { + $logger->fatal("*I couldn't find $fileName, are you sure it exists?"); + $logger->fatal("Exiting, no indendation done."); + $self->output_logfile(); + exit(3); + } } } } @@ -93,15 +104,17 @@ sub file_extension_check{ $logger->info("*-o switch active: output file check"); + ${$self}{outputToFile} = $switches{outputToFile}; + if ($fileName eq "-" and $switches{outputToFile} =~ m/^\+/){ $logger->info("STDIN input mode active, -o switch is removing all + symbols"); - $switches{outputToFile} =~ s/\+//g; + ${$self}{outputToFile} =~ s/\+//g; } # the -o file name might begin with a + symbol if($switches{outputToFile} =~ m/^\+(.*)/ and $1 ne "+"){ - $logger->info("-o switch called with + symbol at the beginning: $switches{outputToFile}"); - $switches{outputToFile} = ${$self}{baseName}.$1; - $logger->info("output file is now: $switches{outputToFile}"); + $logger->info("-o switch called with + symbol at the beginning: ${$self}{outputToFile}"); + ${$self}{outputToFile} = ${$self}{baseName}.$1; + $logger->info("output file is now: ${$self}{outputToFile}"); } my $strippedFileExtension = ${$self}{fileExtension}; @@ -109,20 +122,20 @@ sub file_extension_check{ $strippedFileExtension = "tex" if ($strippedFileExtension eq ""); # grab the name, directory, and extension of the output file - my ($name, $dir, $ext) = fileparse($switches{outputToFile}, $strippedFileExtension); + my ($name, $dir, $ext) = fileparse(${$self}{outputToFile}, $strippedFileExtension); # if there is no extension, then add the extension from the file to be operated upon if(!$ext){ $logger->info("-o switch called with file name without extension: $switches{outputToFile}"); - $switches{outputToFile} = $name.($name=~m/\.\z/ ? q() : ".").$strippedFileExtension; - $logger->info("Updated to $switches{outputToFile} as the file extension of the input file is $strippedFileExtension"); + ${$self}{outputToFile} = $name.($name=~m/\.\z/ ? q() : ".").$strippedFileExtension; + $logger->info("Updated to ${$self}{outputToFile} as the file extension of the input file is $strippedFileExtension"); } # the -o file name might end with ++ in which case we wish to search for existence, # and then increment accordingly $name =~ s/\.$//; if($name =~ m/\+\+$/){ - $logger->info("-o switch called with file name ending with ++: $switches{outputToFile}"); + $logger->info("-o switch called with file name ending with ++: ${$self}{outputToFile}"); $name =~ s/\+\+$//; $name = ${$self}{baseName} if ($name eq ""); my $outputFileCounter = 0; @@ -134,7 +147,7 @@ sub file_extension_check{ $fileName = $name.$outputFileCounter.".".$strippedFileExtension; } $logger->info("$fileName does not exist, and will be the output file"); - $switches{outputToFile} = $fileName; + ${$self}{outputToFile} = $fileName; } } @@ -144,10 +157,16 @@ sub file_extension_check{ my $openFilePossible=1; open(MAINFILE, $fileName) or ($openFilePossible=0); if($openFilePossible==0){ - $logger->fatal("*$fileName exists, but could not open it"); - $logger->fatal("Exiting, no indendation done."); - $self->output_logfile(); - exit(4); + if (defined ${$self}{multipleFiles}){ + $logger->warn("*$fileName exists, but could not open it"); + $logger->warn("moving on, no indendation done for $fileName"); + return 4; + } else { + $logger->fatal("*$fileName exists, but could not open it"); + $logger->fatal("Exiting, no indendation done."); + $self->output_logfile(); + exit(4); + } } push(@lines,$_) while(<MAINFILE>); close(MAINFILE); @@ -163,9 +182,18 @@ sub file_extension_check{ ${$self}{body} = join("",@lines); } - # necessary extra storage if check switch is active - if ($is_check_switch_active){ + # necessary extra storage if + # + # check switch is active + # + # or + # + # $switches{overwriteIfDifferent} + # + if ($is_check_switch_active or $switches{overwriteIfDifferent}){ ${$self}{originalBody} = ${$self}{body}; } + + return 0; } 1; diff --git a/support/latexindent/LatexIndent/Item.pm b/support/latexindent/LatexIndent/Item.pm index d9b191d62f..315e2c35e0 100644 --- a/support/latexindent/LatexIndent/Item.pm +++ b/support/latexindent/LatexIndent/Item.pm @@ -35,6 +35,8 @@ our $itemRegExp; sub construct_list_of_items{ my $self = shift; + $listOfItems = q(); + # put together a list of the items while( my ($item,$lookForThisItem)= each %{$mainSettings{itemNames}}){ $listOfItems .= ($listOfItems eq "")?"$item":"|$item" if($lookForThisItem); diff --git a/support/latexindent/LatexIndent/Lines.pm b/support/latexindent/LatexIndent/Lines.pm index edfe811564..d1ee631b08 100644 --- a/support/latexindent/LatexIndent/Lines.pm +++ b/support/latexindent/LatexIndent/Lines.pm @@ -30,6 +30,9 @@ sub lines_body_selected_lines { # strip all space from lines switch $switches{lines} =~ s/\h//sg; + # convert multiple - into single + $switches{lines} =~ s/-+/-/sg; + $logger->info("*-n,--lines switch is active, operating on lines $switches{lines}"); $logger->info("number of lines in file: ".($#lines+1)); $logger->info("*interpretting $switches{lines}"); diff --git a/support/latexindent/LatexIndent/LogFile.pm b/support/latexindent/LatexIndent/LogFile.pm index 692bfddbdb..fa6df78828 100644 --- a/support/latexindent/LatexIndent/LogFile.pm +++ b/support/latexindent/LatexIndent/LogFile.pm @@ -61,6 +61,9 @@ usage: latexindent.pl [options] [file] latexindent.pl -o=outputfile.tex myfile.tex -w, --overwrite overwrite the current file; a backup will be made, but still be careful + -wd, --overwriteIfDifferent + overwrite the current file IF the indented text is different from original; + a backup will be made, but still be careful -s, --silent silent mode: no output will be given to the terminal -t, --trace @@ -103,6 +106,9 @@ usage: latexindent.pl [options] [file] only operate on selected lines; sample usage: latexindent.pl --lines 3-5 myfile.tex latexindent.pl --lines 3-5,7-10 myfile.tex + --GCString + loads the Unicode::GCString module for the align-at-ampersand routine + Note: this requires the Unicode::GCString module to be installed on your system ENDQUOTE ; exit(0); @@ -110,6 +116,7 @@ ENDQUOTE # if we've made it this far, the processing of switches and logging begins my $self = shift; + my @fileNames = @{$_[0]}; $logger = LatexIndent::Logger->new(); @@ -134,7 +141,16 @@ ENDQUOTE $logger->info($time); if (${$self}{fileName} ne "-"){ - $logger->info("Filename: ${$self}{fileName}"); + # multiple filenames or not + if ( (scalar (@fileNames)) >1 ){ + $logger->info("Filenames:"); + foreach (@fileNames) { + $logger->info(" $_"); + } + $logger->info("total number of files: ".(scalar (@fileNames))); + } else { + $logger->info("Filename: ${$self}{fileName}"); + } } else { $logger->info("Reading input from STDIN"); if (-t STDIN) { @@ -155,7 +171,8 @@ ENDQUOTE $logger->info("-tt|--ttrace: TTrace mode active (you have used either -tt or --ttrace)") if($switches{ttrace}); $logger->info("-s|--silent: Silent mode active (you have used either -s or --silent)") if($switches{silentMode}); $logger->info("-d|--onlydefault: Only defaultSettings.yaml will be used (you have used either -d or --onlydefault)") if($switches{onlyDefault}); - $logger->info("-w|--overwrite: Overwrite mode active, will make a back up of ${$self}{fileName} first") if($switches{overwrite}); + $logger->info("-w|--overwrite: Overwrite mode active, will make a back up before overwriting") if($switches{overwrite}); + $logger->info("-wd|--overwriteIfDifferent: will overwrite ONLY if indented text is different") if($switches{overwriteIfDifferent}); $logger->info("-l|--localSettings: Read localSettings YAML file") if($switches{readLocalSettings}); $logger->info("-y|--yaml: YAML settings specified via command line") if($switches{yaml}); $logger->info("-o|--outputfile: output to file") if($switches{outputToFile}); @@ -167,18 +184,58 @@ ENDQUOTE $logger->info("-k|--check mode: will exit with 0 if document body unchanged, 1 if changed") if($switches{check}); $logger->info("-kv|--check mode verbose: as in check mode, but outputs diff to screen") if($switches{checkverbose}); $logger->info("-n|--lines mode: will only operate on specific lines $switches{lines}") if($switches{lines}); + $logger->info("--GCString switch active, loading Unicode::GCString module") if($switches{GCString}); # check if overwrite and outputfile are active similtaneously if($switches{overwrite} and $switches{outputToFile}){ - $logger->info("Options check, -w and -o specified\nYou have called latexindent.pl with both -o and -w\noutput to file) will take priority, and -w (over write) will be ignored"); + $logger->info("*Options check: -w and -o specified"); + $logger->info("You have called latexindent.pl with both -o and -w"); + $logger->info("The -o switch will take priority, and -w (overwrite) will be ignored"); + $switches{overwrite}=0; + } + + # check if overwrite and outputfile are active similtaneously + if($switches{overwrite} and $switches{overwriteIfDifferent}){ + $logger->info("*Options check: -w and -wd specified"); + $logger->info("You have called latexindent.pl with both -w and -wd."); + $logger->info("The -wd switch will take priority, and -w (overwrite) will be ignored"); $switches{overwrite}=0; } - $logger->info("*Directory for backup files and $logfileName: ${$self}{cruftDirectory}"); + # check if overwriteIfDifferent and outputfile are active similtaneously + if($switches{overwriteIfDifferent} and $switches{outputToFile}){ + $logger->info("*Options check: -wd and -o specified"); + $logger->info("You have called latexindent.pl with both -o and -wd"); + $logger->info("The -o switch will take priority, and -wd (overwriteIfDifferent) will be ignored"); + $switches{overwriteIfDifferent}=0; + } + + # multiple files with the -o switch needs care + # + # example + # + # latexindent.pl *.tex -o myfile.tex + # + # would result in only the final file being written to myfile.tex + # + # So, if -o switch does *not* match having a + symbol at the beginning, then + # we ignore it, and turn it off + # + if ( (scalar @fileNames>1) and $switches{outputToFile} and ($switches{outputToFile} !~ m/^h*\+/) ){ + $logger->warn("*-o switch specified as single file, but multiple files given as input"); + $logger->warn("ignoring your specification -o $switches{outputToFile}"); + $logger->warn("perhaps you migh specify it using, for example, -o=++ or -o=+myoutput"); + $switches{outputToFile} =0; + } + + $logger->info("*Directory for backup files and $logfileName:"); + $logger->info("${$self}{cruftDirectory}"); # output location of modules if($FindBin::Script eq 'latexindent.pl' or ($FindBin::Script eq 'latexindent.exe' and $switches{trace} )) { - my @listOfModules = ('FindBin', 'YAML::Tiny', 'File::Copy', 'File::Basename', 'Getopt::Long','File::HomeDir','Unicode::GCString'); + my @listOfModules = ('FindBin', 'YAML::Tiny', 'File::Copy', 'File::Basename', 'Getopt::Long','File::HomeDir'); + push(@listOfModules,'Unicode::GCString') if $switches{GCString}; + $logger->info("*Perl modules are being loaded from the following directories:"); foreach my $moduleName (@listOfModules) { (my $file = $moduleName) =~ s|::|/|g; diff --git a/support/latexindent/LatexIndent/Logger.pm b/support/latexindent/LatexIndent/Logger.pm index d3f9d0f48d..ebad76a2d5 100644 --- a/support/latexindent/LatexIndent/Logger.pm +++ b/support/latexindent/LatexIndent/Logger.pm @@ -26,6 +26,7 @@ our @logFileLines; sub info{ my $self = shift; my $logfileline = shift; + return unless (defined $logfileline); if ($logfileline =~ m/^\*/s){ $logfileline =~ s/^\*/INFO: /s; $logfileline =~ s/^/ /mg; diff --git a/support/latexindent/LatexIndent/ModifyLineBreaks.pm b/support/latexindent/LatexIndent/ModifyLineBreaks.pm index 63f6c2d03f..4d3356183b 100644 --- a/support/latexindent/LatexIndent/ModifyLineBreaks.pm +++ b/support/latexindent/LatexIndent/ModifyLineBreaks.pm @@ -272,6 +272,7 @@ sub verbatim_modify_line_breaks{ ${$self}{body} =~ s/\h*${$child}{id}/$trailingCharacterToken\n${$child}{id}/s; } } + # after text wrap poly-switch check if ($input{when} eq "afterTextWrap"){ $logger->trace("*post text wrap poly-switch check for EndFinishesWithLineBreak") if $is_t_switch_active ; diff --git a/support/latexindent/LatexIndent/Sentence.pm b/support/latexindent/LatexIndent/Sentence.pm index 9370f55886..f2120ee7f8 100644 --- a/support/latexindent/LatexIndent/Sentence.pm +++ b/support/latexindent/LatexIndent/Sentence.pm @@ -192,18 +192,19 @@ sub one_sentence_per_line{ my $trailing = ($5?$5:q()).($6?$6:q()).($7?$7:q()); my $lineBreaksAtEnd = ($6? 1 : ($7?1:0) ); my $trailingComments = q(); - # remove trailing comments from within the body of the sentence if (${$mainSettings{modifyLineBreaks}{oneSentencePerLine}}{removeSentenceLineBreaks}){ + # remove trailing comments from within the body of the sentence while($middle =~ m|$trailingCommentRegExp|){ $middle =~ s|\h*($trailingCommentRegExp)||s; $trailingComments .= $1; } + # remove line breaks from within a sentence + $middle =~ s| + (?!\A) # not at the *beginning* of a match + (\h*)\R # possible horizontal space, then line break + |$1?$1:" ";|esgx } - # remove line breaks from within a sentence - $middle =~ s| - (?!\A) # not at the *beginning* of a match - (\h*)\R # possible horizontal space, then line break - |$1?$1:" ";|esgx if ${$mainSettings{modifyLineBreaks}{oneSentencePerLine}}{removeSentenceLineBreaks}; + $middle =~ s|\h{2,}| |sg if ${$mainSettings{modifyLineBreaks}{oneSentencePerLine}}{multipleSpacesToSingle}; $middle =~ s|$tokens{blanklines}\h*\R?|$tokens{blanklines}\n|sg; $logger->trace("follows: $beginning") if $is_tt_switch_active; $logger->trace("sentence: $middle") if $is_tt_switch_active; diff --git a/support/latexindent/LatexIndent/TrailingComments.pm b/support/latexindent/LatexIndent/TrailingComments.pm index 82ff154c87..8bab5bc130 100644 --- a/support/latexindent/LatexIndent/TrailingComments.pm +++ b/support/latexindent/LatexIndent/TrailingComments.pm @@ -54,6 +54,9 @@ sub add_comment_symbol{ sub remove_trailing_comments{ my $self = shift; + + $commentCounter = 0; + $logger->trace("*Storing trailing comments")if $is_t_switch_active; my $notPreceededBy = qr/${${$mainSettings{fineTuning}}{trailingComments}}{notPreceededBy}/; diff --git a/support/latexindent/LatexIndent/Version.pm b/support/latexindent/LatexIndent/Version.pm index 7727a270e9..dd996edb7f 100644 --- a/support/latexindent/LatexIndent/Version.pm +++ b/support/latexindent/LatexIndent/Version.pm @@ -19,6 +19,6 @@ use warnings; use Exporter qw/import/; our @EXPORT_OK = qw/$versionNumber $versionDate/; -our $versionNumber = '3.16'; -our $versionDate = '2022-03-13'; +our $versionNumber = '3.17'; +our $versionDate = '2022-03-25'; 1 diff --git a/support/latexindent/LatexIndent/Wrap.pm b/support/latexindent/LatexIndent/Wrap.pm index a2b8383d94..45a30fb2d0 100644 --- a/support/latexindent/LatexIndent/Wrap.pm +++ b/support/latexindent/LatexIndent/Wrap.pm @@ -18,6 +18,7 @@ use strict; use warnings; use Text::Wrap; use LatexIndent::Tokens qw/%tokens/; +use LatexIndent::AlignmentAtAmpersand qw/get_column_width/; use LatexIndent::TrailingComments qw/$trailingCommentRegExp/; use LatexIndent::GetYamlSettings qw/%mainSettings/; use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active $is_m_switch_active/; @@ -266,7 +267,7 @@ sub text_wrap{ if($textWrapBlockStorageValue =~m/$verbatimID/s){ # measure length - my $verbatimLength = Unicode::GCString->new($verbatimThing)->columns(); + my $verbatimLength = &get_column_width($verbatimThing); # create temporary ID, and check that it is not contained in the body my $verbatimTmpID = join '' => map $set[rand @set], 1 .. $verbatimLength; diff --git a/support/latexindent/README b/support/latexindent/README index e84183e4ce..f14bb236a2 100644 --- a/support/latexindent/README +++ b/support/latexindent/README @@ -1,5 +1,5 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - latexindent.pl, version 3.16, 2022-03-13 + latexindent.pl, version 3.17, 2022-03-25 PERL script to indent code within environments, and align delimited environments in .tex files. diff --git a/support/latexindent/defaultSettings.yaml b/support/latexindent/defaultSettings.yaml index fabc5f5b6e..06da354c86 100644 --- a/support/latexindent/defaultSettings.yaml +++ b/support/latexindent/defaultSettings.yaml @@ -1,4 +1,4 @@ -# defaultSettings.yaml for latexindent.pl, version 3.16, 2022-03-13 +# defaultSettings.yaml for latexindent.pl, version 3.17, 2022-03-25 # a script that aims to # beautify .tex, .sty, .cls files # @@ -494,6 +494,7 @@ modifyLineBreaks: oneSentencePerLine: manipulateSentences: 0 removeSentenceLineBreaks: 1 + multipleSpacesToSingle: 1 textWrapSentences: 0 # setting to 1 disables main textWrap routine sentenceIndent: "" sentencesFollow: diff --git a/support/latexindent/documentation/latexindent-yaml-schema.json b/support/latexindent/documentation/latexindent-yaml-schema.json index 34c9354f75..27af878680 100644 --- a/support/latexindent/documentation/latexindent-yaml-schema.json +++ b/support/latexindent/documentation/latexindent-yaml-schema.json @@ -2,7 +2,7 @@ "$schema": "http://json-schema.org/schema", "$id": "latexindent-yaml-schema.json", "title": "latexindent.pl YAML schema", - "description": "latexindent.pl YAML schema helper, V3.16 2022-03-13", + "description": "latexindent.pl YAML schema helper, V3.17 2022-03-25", "type": "object", "properties": { "fileExtensionPreference": { diff --git a/support/latexindent/documentation/latexindent.pdf b/support/latexindent/documentation/latexindent.pdf Binary files differindex a6623c6b94..a3bdd29e7f 100644 --- a/support/latexindent/documentation/latexindent.pdf +++ b/support/latexindent/documentation/latexindent.pdf diff --git a/support/latexindent/documentation/latexindent.tex b/support/latexindent/documentation/latexindent.tex index 95fa9d694a..67c9dd83d0 100644 --- a/support/latexindent/documentation/latexindent.tex +++ b/support/latexindent/documentation/latexindent.tex @@ -462,55 +462,55 @@ \lstdefinestyle{textWrapOptions}{ style=yaml-LST, - firstnumber=518,linerange={518-519}, + firstnumber=519,linerange={519-520}, numbers=left, } \lstdefinestyle{textWrapOptionsAll}{ style=yaml-LST, - firstnumber=518,linerange={518-540}, + firstnumber=519,linerange={519-541}, numbers=left, } \lstdefinestyle{oneSentencePerLine}{ style=yaml-LST, - firstnumber=494,linerange={494-517}, + firstnumber=494,linerange={494-518}, numbers=left, } \lstdefinestyle{sentencesFollow}{ style=yaml-LST, - firstnumber=499,linerange={499-507}, + firstnumber=500,linerange={500-508}, numbers=left, } \lstdefinestyle{sentencesBeginWith}{ style=yaml-LST, - firstnumber=508,linerange={508-511}, + firstnumber=509,linerange={509-512}, numbers=left, } \lstdefinestyle{sentencesEndWith}{ style=yaml-LST, - firstnumber=512,linerange={512-517}, + firstnumber=513,linerange={513-518}, numbers=left, } \lstdefinestyle{modifylinebreaksEnv}{ style=yaml-LST, - firstnumber=542,linerange={542-551}, + firstnumber=543,linerange={543-552}, numbers=left, } \lstdefinestyle{replacements}{ style=yaml-LST, - firstnumber=603,linerange={603-611}, + firstnumber=604,linerange={604-612}, numbers=left, } \lstdefinestyle{fineTuning}{ style=yaml-LST, - firstnumber=614,linerange={614-639}, + firstnumber=615,linerange={615-640}, numbers=left, } diff --git a/support/latexindent/documentation/sec-appendices.tex b/support/latexindent/documentation/sec-appendices.tex index 64f49180e9..2b3c9ecccc 100644 --- a/support/latexindent/documentation/sec-appendices.tex +++ b/support/latexindent/documentation/sec-appendices.tex @@ -12,9 +12,7 @@ use strict; use warnings; -use utf8; use PerlIO::encoding; -use Unicode::GCString; use open ':std', ':encoding(UTF-8)'; use Text::Wrap; use Text::Tabs; @@ -63,7 +61,6 @@ sudo apt-get install curl curl -L http://cpanmin.us | perl - App::cpanminus cpanm YAML::Tiny cpanm File::HomeDir -cpanm Unicode::GCString \end{commandshell} \index{cpan} @@ -74,7 +71,6 @@ sudo apt install perl sudo cpan -i App::cpanminus sudo cpanm YAML::Tiny sudo cpanm File::HomeDir -sudo cpanm Unicode::GCString \end{commandshell} or else by running, for example, \begin{commandshell} @@ -91,6 +87,12 @@ sudo apt install texlive-latex-recommended \begin{commandshell} sudo apt install texlive-extra-utils \end{commandshell} + \paragraph{Arch-based distributions} + First install the dependencies + \begin{commandshell} +sudo pacman -S perl cpanminus +\end{commandshell} + then run the latexindent-module-installer.pl file located at helper-scripts/ \paragraph{Alpine} If you are using Alpine, some \texttt{Perl} modules are not build-compatible with Alpine, @@ -99,6 +101,7 @@ sudo apt install texlive-extra-utils these details. \begin{cmhlistings}[style=tcblatex,language=Bash]{\texttt{alpine-install.sh}}{lst:alpine-install} + # Installing perl apk --no-cache add miniperl perl-utils @@ -119,7 +122,6 @@ cpanm -n App::cpanminus cpanm -n File::HomeDir cpanm -n Params::ValidationCompiler cpanm -n YAML::Tiny -cpanm -n Unicode::GCString \end{cmhlistings} Users of NixOS might like to see @@ -134,7 +136,6 @@ brew install cpanm cpanm YAML::Tiny cpanm File::HomeDir -cpanm Unicode::GCString \end{commandshell} \subsubsection{Windows} @@ -150,6 +151,28 @@ cpanm Unicode::GCString latexindent.exe -t myfile.tex \end{dosprompt} + \subsection{The GCString switch}\label{subsec:the-GCString} + If you find that the \texttt{lookForAlignDelims} (as in \cref{subsec:align-at-delimiters}) does not work correctly + for your language, then you may with to use the \texttt{Unicode::GCString} module \announce*{2022-03-25}{Unicode::GCString}. + \index{perl!Unicode GCString module} + \index{switches!--GCString demonstration} + + This can be loaded by calling \texttt{latexindent.pl} with the \texttt{GCString} switch + as in + \begin{commandshell} +latexindent.pl --GCString myfile.tex +\end{commandshell} + In this case, you will need to have the \texttt{Unicode::GCString} installed in your + \texttt{perl} distribution by using, for example, + \begin{commandshell} +cpanm YAML::Tiny +\end{commandshell} + + Note: this switch does \emph{nothing} for \texttt{latexindent.exe} which loads the module + by default. Users of \texttt{latexindent.exe} should not see any difference in behaviour + whether they use this switch or not, as \texttt{latexindent.exe} loads the + \texttt{Unicode::GCString} module. + \section{Updating the path variable}\label{sec:updating-path} \texttt{latexindent.pl} has a few scripts (available at \cite{latexindent-home}) that can update the \texttt{path} variables. Thank you to \cite{jasjuang} for this feature. If @@ -208,6 +231,93 @@ echo %path% To \emph{remove} the directory from your \lstinline!%path%!, run \texttt{remove-from-path.bat} as administrator. + \section{Batches of files}\label{sec:batches} + + You can \announce*{2022-03-25}{batches of files details} instruct \texttt{latexindent.pl} + to operate on multiple files. For example, the following calls are all valid + \begin{commandshell} +latexindent.pl myfile1.tex +latexindent.pl myfile1.tex myfile2.tex +latexindent.pl myfile*.tex + \end{commandshell} + + We note the following features of the script in relation to the switches detailed in + \cref{sec:how:to:use}. + + \subsection{location of indent.log} + If the \texttt{-c} switch is \emph{not} active, then \texttt{indent.log} goes to the directory of the final file called. + + If the \texttt{-c} switch \emph{is} active, then \texttt{indent.log} goes to the + specified directory. + + \subsection{interaction with -w switch} + If the \texttt{-w} switch is active, as in + \begin{commandshell} +latexindent.pl -w myfile*.tex +\end{commandshell} + then files will be overwritten individually. Back-up files can be re-directed via the + \texttt{-c} switch. + + \subsection{interaction with -o switch} + If \texttt{latexindent.pl} is called using the \texttt{-o} switch as in + \begin{commandshell} +latexindent.pl myfile*.tex -o=my-output-file.tex + \end{commandshell} + and there are multiple files to operate upon, then the \texttt{-o} switch is ignored + because there is only \emph{one} output file specified. + + More generally, if the \texttt{-o} switch does \emph{not} have a \texttt{+} symbol at the + beginning, then the \texttt{-o} switch will be ignored, and is turned it off. + + For example + \begin{commandshell} +latexindent.pl myfile*.tex -o=+myfile +\end{commandshell} + \emph{will} work fine because \emph{each} \texttt{.tex} file will output to + \texttt{<basename>myfile.tex} + + Similarly, + \begin{commandshell} +latexindent.pl myfile*.tex -o=++ +\end{commandshell} + \emph{will} work because the `existence check/incrementation' routine will be applied. + + \subsection{interaction with lines switch} + This behaves as expected by attempting to operate on the line numbers specified for each file. See + the examples in \cref{sec:line-switch}. + + \subsection{interaction with check switches} + The exit codes for \texttt{latexindent.pl} are given in \vref{tab:exit-codes}. + + When operating on multiple files with the check switch active, as in + \begin{commandshell} +latexindent.pl myfile*.tex --check + \end{commandshell} + then + \begin{itemize} + \item exit code 0 means that the text from \emph{none} of the files has been changed; + \item exit code 1 means that the text from \emph{at least one} of the files been file changed. + \end{itemize} + + The interaction with \texttt{checkv} switch is as in the check switch, but with verbose + output. + + \subsection{when a file does not exist} + What happens if one of the files can not be operated upon? + \begin{itemize} + \item if at least one of the files does not exist and \texttt{latexindent.pl} has been called + to act upon multiple files, then the exit code is 3; note that \texttt{latexindent.pl} + will try to operate on each file that it is called upon, and will not exit with a fatal + message in this case; + \item if at least one of the files can not be read and \texttt{latexindent.pl} has been called + to act upon multiple files, then the exit code is 4; note that \texttt{latexindent.pl} + will try to operate on each file that it is called upon, and will not exit with a fatal + message in this case; + \item if \texttt{latexindent.pl} has been told to operate on multiple files, and some do not + exist and some cannot be read, then the exit code will be either 3 or 4, depending upon + which it scenario it encountered most recently. + \end{itemize} + \section{latexindent-yaml-schema.json} \texttt{latexindent.pl} @@ -279,7 +389,7 @@ conda run latexindent.pl -vv \section{pre-commit} - Users of \texttt{.git} may be interested \announce*{2022-01-21}{pre-commit for + Users of \texttt{.git} may be interested \announce{2022-01-21}{pre-commit for latexindent.pl} in exploring the \texttt{pre-commit} tool \cite{pre-commithome}, which is supported by \texttt{latexindent.pl}. Thank you to \cite{tdegeusprecommit} for contributing this feature. @@ -296,7 +406,7 @@ python3 -m pip install pre-commit \end{commandshell} I then updated my path via .bashrc so that it includes the line in \cref{lst:bashrc-update}. - \begin{cmhlistings}*[style=tcblatex,language=Bash]{\texttt{.bashrc} update}{lst:bashrc-update} + \begin{cmhlistings}[style=tcblatex,language=Bash]{\texttt{.bashrc} update}{lst:bashrc-update} ... export PATH=$PATH:/home/cmhughes/.local/bin \end{cmhlistings} @@ -362,7 +472,7 @@ conda run latexindent.pl -s myfile.tex \begin{example} We use the local settings given in \cref{lst:.latexindent.yaml}. - \begin{cmhlistings}*[style=tcblatex]{\texttt{.latexindent.yaml}}{lst:.latexindent.yaml} + \begin{cmhlistings}[style=tcblatex]{\texttt{.latexindent.yaml}}{lst:.latexindent.yaml} onlyOneBackUp: 1 modifyLineBreaks: @@ -389,8 +499,7 @@ latexindent.pl -l -m -s -w myfile.tex was specified to only create one back-up file, as \texttt{git} typically takes care of this when you use \texttt{pre-commit}); \item \texttt{-m} to modify line breaks; in addition to \texttt{-s} to suppress command-line - output, - and \texttt{-w} to format files in place. + output, and \texttt{-w} to format files in place. \end{itemize} \end{example} diff --git a/support/latexindent/documentation/sec-default-user-local.tex b/support/latexindent/documentation/sec-default-user-local.tex index 94fbdce46c..d49823eb52 100644 --- a/support/latexindent/documentation/sec-default-user-local.tex +++ b/support/latexindent/documentation/sec-default-user-local.tex @@ -354,7 +354,7 @@ removeTrailingWhitespace: 1 \texttt{afterProcessing} to the value you specify; see \cref{lst:removeTrailingWhitespace-alt}.% -\subsection{Aligning at delimiters} +\subsection{Aligning at delimiters}\label{subsec:align-at-delimiters} \yamltitle{lookForAlignDelims}*{fields} This contains a list of code blocks that are operated upon in a special way by \texttt{latexindent.pl} (see \cref{lst:aligndelims:basic}). In fact, the fields in diff --git a/support/latexindent/documentation/sec-how-to-use.tex b/support/latexindent/documentation/sec-how-to-use.tex index 944a38292c..2ff75c8b1f 100644 --- a/support/latexindent/documentation/sec-how-to-use.tex +++ b/support/latexindent/documentation/sec-how-to-use.tex @@ -1,5 +1,5 @@ % arara: pdflatex: { files: [latexindent]} -\section{How to use the script} +\section{How to use the script}\label{sec:how:to:use} \texttt{latexindent.pl} ships as part of the \TeX Live distribution for Linux and Mac users; \texttt{latexindent.exe} ships as part of the \TeX Live for Windows users. These files are also available from github \cite{latexindent-home} should you wish @@ -48,7 +48,7 @@ latexindent.pl --version \flagbox{-vv, --vversion} \index{switches!-vv, --vversion definition and details} - \announce*{2022-01-08}{vversion switch} + \announce{2022-01-08}{vversion switch} \begin{commandshell} latexindent.pl -vv latexindent.pl --vversion @@ -74,6 +74,13 @@ latexindent.pl myfile.tex \texttt{myfile.tex} will not be changed by \texttt{latexindent.pl} in any way using this command. + You can \announce*{2022-03-25}{batches of files demonstration} instruct + \texttt{latexindent.pl} to operate on multiple (batches) of files, for example + \begin{commandshell} +latexindent.pl myfile1.tex myfile2.tex +\end{commandshell} + Full details are given in \vref{sec:batches}. + \flagbox{-w, --overwrite} \index{switches!-w, --overwrite definition and details} \index{backup files!overwrite switch, -w} @@ -93,6 +100,24 @@ latexindent.pl myfile.tex --overwrite touching your original file; an error message will be given asking you to check the permissions of the backup file. +\flagbox{-wd, --overwriteIfDifferent} + \index{switches!-wd, --overwriteIfDifferent definition and details} + \index{backup files!overwriteIfDifferent switch, -wd} + \announce*{2022-03-25}{overwriteIfDifferent switch} + \begin{commandshell} +latexindent.pl -wd myfile.tex +latexindent.pl --overwriteIfDifferent myfile.tex +latexindent.pl myfile.tex --overwriteIfDifferent +\end{commandshell} + + This \emph{will} overwrite \texttt{myfile.tex} but only \emph{if the indented text is + different from the original}. If the indented text is \emph{not} different from the + original, then \texttt{myfile.tex} will \emph{not} be overwritten. + + All other details from the \texttt{-w} switch are relevant here. If you call + \texttt{latexindent.pl} with both the \texttt{-wd} and the \texttt{-w} switch, then the + \texttt{-w} switch will be deactivated and the \texttt{-wd} switch takes priority. + \flagbox{-o=output.tex,--outputfile=output.tex} \index{switches!-o, --output definition and details} \begin{commandshell} @@ -104,9 +129,12 @@ latexindent.pl --outputfile output.tex myfile.tex This will indent \texttt{myfile.tex} and output it to \texttt{output.tex}, overwriting it (\texttt{output.tex}) if it already exists\footnote{Users of version 2.* should note the - subtle change in syntax}. Note that if \texttt{latexindent.pl} is called with both the - \texttt{-w} and \texttt{-o} switches, then \texttt{-w} will be ignored and \texttt{-o} - will take priority (this seems safer than the other way round). + subtle change in syntax}. + + Note that if \texttt{latexindent.pl} is called with both the \texttt{-w} and \texttt{-o} + switches, then \texttt{-w} will be ignored and \texttt{-o} will take priority (this seems + safer than the other way round). The same is true for the \texttt{-wd} switch, and the + \texttt{-o} switch takes priority over it. Note that using \texttt{-o} as above is equivalent to using \begin{commandshell} @@ -465,6 +493,16 @@ latexindent.pl -lines 5-8 myfile.tex Complete demonstrations are given in \cref{sec:line-switch}. +\flagbox{--GCString} + \index{switches!--GCString} + \begin{commandshell} +latexindent.pl --GCString myfile.tex +\end{commandshell} + \announce*{2022-03-25}{GCString switch} instructs \texttt{latexindent.pl} to load the + \texttt{Unicode::GCString} module. This should only be necessary if you find that the + alignment at ampersand routine (described in \cref{subsec:align-at-delimiters}) does not + work for your language. Further details are given in \cref{subsec:the-GCString}. + \subsection{From arara}\label{sec:arara} Using \texttt{latexindent.pl} from the command line is fine for some folks, but others may find it easier to use from \texttt{arara}; you can find the arara rule for diff --git a/support/latexindent/documentation/subsec-one-sentence-per-line.tex b/support/latexindent/documentation/subsec-one-sentence-per-line.tex index 37a57e8f1a..335990c30f 100644 --- a/support/latexindent/documentation/subsec-one-sentence-per-line.tex +++ b/support/latexindent/documentation/subsec-one-sentence-per-line.tex @@ -10,7 +10,7 @@ \index{regular expressions!lowercase alph a-z} \index{regular expressions!uppercase alph A-Z}% - \cmhlistingsfromfile[style=oneSentencePerLine]{../defaultSettings.yaml}[MLB-TCB,width=.85\linewidth,before=\centering]{\texttt{oneSentencePerLine}}{lst:oneSentencePerLine} + \cmhlistingsfromfile*[style=oneSentencePerLine]{../defaultSettings.yaml}[MLB-TCB,width=.85\linewidth,before=\centering]{\texttt{oneSentencePerLine}}{lst:oneSentencePerLine} \yamltitle{manipulateSentences}{0|1} This is a binary switch that details if \texttt{latexindent.pl} should perform the @@ -55,6 +55,12 @@ latexindent.pl multiple-sentences -m -l=keep-sen-line-breaks.yaml \cref{lst:multiple-sentences} have been removed in \cref{lst:multiple-sentences-mod1}, but have not been removed in \cref{lst:multiple-sentences-mod2}. +\yamltitle{multipleSpacesToSingle}{0|1} + \announce*{2022-03-25}*{multipleSpacesToSingle for oneSentencePerLine} By default, the + one-sentence-per-line routine will convert multiple spaces into single spaces. You can + change this behaviour by changing the switch \texttt{multipleSpacesToSingle} to a value + of \texttt{0}. + The remainder of the settings displayed in \vref{lst:oneSentencePerLine} instruct \texttt{latexindent.pl} on how to define a sentence. From the perspective of \texttt{latexindent.pl} a sentence must: \index{sentences!follow} \index{sentences!begin diff --git a/support/latexindent/documentation/subsec-text-wrap.tex b/support/latexindent/documentation/subsec-text-wrap.tex index 2b4c96539e..61a1c21628 100644 --- a/support/latexindent/documentation/subsec-text-wrap.tex +++ b/support/latexindent/documentation/subsec-text-wrap.tex @@ -1,12 +1,12 @@ % arara: pdflatex: { files: [latexindent]} \subsection{Text Wrapping}\label{subsec:textwrapping} - \announce*{2022-03-13}{text wrap overhaul}\emph{The text wrapping routine has been over-hauled as + \announce{2022-03-13}{text wrap overhaul}\emph{The text wrapping routine has been over-hauled as of V3.16; I hope that the interface is simpler, and most importantly, the results are better}. The complete settings for this feature are given in \cref{lst:textWrapOptionsAll}. - \cmhlistingsfromfile*[style=textWrapOptionsAll]{../defaultSettings.yaml}[MLB-TCB,width=.95\linewidth,before=\centering]{\texttt{textWrapOptions}}{lst:textWrapOptionsAll} + \cmhlistingsfromfile[style=textWrapOptionsAll]{../defaultSettings.yaml}[MLB-TCB,width=.95\linewidth,before=\centering]{\texttt{textWrapOptions}}{lst:textWrapOptionsAll} \subsubsection{Text wrap: overview} An overview of how the text wrapping feature works: @@ -37,7 +37,7 @@ \begin{example} Let's use the sample text given in \cref{lst:textwrap1}. \index{text wrap!quick start} - \cmhlistingsfromfile*{demonstrations/textwrap1.tex}{\texttt{textwrap1.tex}}{lst:textwrap1} + \cmhlistingsfromfile{demonstrations/textwrap1.tex}{\texttt{textwrap1.tex}}{lst:textwrap1} We will change the value of \texttt{columns} in \cref{lst:textwrap1-yaml} and then run the command @@ -47,8 +47,8 @@ latexindent.pl -m -l textwrap1.yaml textwrap1.tex then we receive the output given in \cref{lst:textwrap1-mod1}. \begin{cmhtcbraster}[raster column skip=.1\linewidth] - \cmhlistingsfromfile*{demonstrations/textwrap1-mod1.tex}{\texttt{textwrap1-mod1.tex}}{lst:textwrap1-mod1} - \cmhlistingsfromfile*{demonstrations/textwrap1.yaml}[MLB-TCB]{\texttt{textwrap1.yaml}}{lst:textwrap1-yaml} + \cmhlistingsfromfile{demonstrations/textwrap1-mod1.tex}{\texttt{textwrap1-mod1.tex}}{lst:textwrap1-mod1} + \cmhlistingsfromfile{demonstrations/textwrap1.yaml}[MLB-TCB]{\texttt{textwrap1.yaml}}{lst:textwrap1-yaml} \end{cmhtcbraster} \end{example} @@ -60,7 +60,7 @@ latexindent.pl -m -l textwrap1.yaml textwrap1.tex Starting from the file in \cref{lst:textwrap1-mod1} and using the settings in \cref{lst:textwrap1A-yaml} - \cmhlistingsfromfile*{demonstrations/textwrap1A.yaml}[MLB-TCB]{\texttt{textwrap1A.yaml}}{lst:textwrap1A-yaml} + \cmhlistingsfromfile{demonstrations/textwrap1A.yaml}[MLB-TCB]{\texttt{textwrap1A.yaml}}{lst:textwrap1A-yaml} and running \begin{commandshell} @@ -68,7 +68,7 @@ latexindent.pl -m -l textwrap1A.yaml textwrap1-mod1.tex \end{commandshell} gives the output in \cref{lst:textwrap1-mod1A}. - \cmhlistingsfromfile*{demonstrations/textwrap1-mod1A.tex}{\texttt{textwrap1-mod1A.tex}}{lst:textwrap1-mod1A} + \cmhlistingsfromfile{demonstrations/textwrap1-mod1A.tex}{\texttt{textwrap1-mod1A.tex}}{lst:textwrap1-mod1A} \end{example} \begin{example} @@ -82,8 +82,8 @@ latexindent.pl -m -l textwrap1B.yaml textwrap1-mod1.tex \end{commandshell} gives the output in \cref{lst:textwrap1-mod1B}. \begin{cmhtcbraster}[raster column skip=.1\linewidth] - \cmhlistingsfromfile*{demonstrations/textwrap1B.yaml}[MLB-TCB]{\texttt{textwrap1B.yaml}}{lst:textwrap1B-yaml} - \cmhlistingsfromfile*[showspaces=true]{demonstrations/textwrap1-mod1B.tex}{\texttt{textwrap1-mod1B.tex}}{lst:textwrap1-mod1B} + \cmhlistingsfromfile{demonstrations/textwrap1B.yaml}[MLB-TCB]{\texttt{textwrap1B.yaml}}{lst:textwrap1B-yaml} + \cmhlistingsfromfile[showspaces=true]{demonstrations/textwrap1-mod1B.tex}{\texttt{textwrap1-mod1B.tex}}{lst:textwrap1-mod1B} \end{cmhtcbraster} We note that in \cref{lst:textwrap1-mod1B} the multiple spaces have \emph{not} been condensed into single spaces. \end{example} @@ -92,11 +92,11 @@ latexindent.pl -m -l textwrap1B.yaml textwrap1-mod1.tex We examine the \texttt{blocksFollow} field of \cref{lst:textWrapOptionsAll}. \index{text wrap!blocksFollow} - \begin{example}[label={example:tw:headings}] + \begin{example} Let's use the sample text given in \cref{lst:tw-headings1}. \index{text wrap!blocksFollow!headings} - \cmhlistingsfromfile*{demonstrations/tw-headings1.tex}{\texttt{tw-headings1.tex}}{lst:tw-headings1} + \cmhlistingsfromfile{demonstrations/tw-headings1.tex}{\texttt{tw-headings1.tex}}{lst:tw-headings1} We note that \cref{lst:tw-headings1} contains the heading commands \texttt{section} and \texttt{subsection}. Upon running the command @@ -105,7 +105,7 @@ latexindent.pl -m -l textwrap1.yaml tw-headings1.tex \end{commandshell} then we receive the output given in \cref{lst:tw-headings1-mod1}. - \cmhlistingsfromfile*{demonstrations/tw-headings1-mod1.tex}{\texttt{tw-headings1-mod1.tex}}{lst:tw-headings1-mod1} + \cmhlistingsfromfile{demonstrations/tw-headings1-mod1.tex}{\texttt{tw-headings1-mod1.tex}}{lst:tw-headings1-mod1} We reference \vref{lst:textWrapOptionsAll} and also \vref{lst:indentAfterHeadings}: \begin{itemize} @@ -128,15 +128,16 @@ latexindent.pl -m -l textwrap1.yaml,bf-no-headings.yaml tw-headings1.tex raster left skip=-3.5cm, raster right skip=-2cm, ] - \cmhlistingsfromfile*{demonstrations/bf-no-headings.yaml}[MLB-TCB]{\texttt{bf-no-headings.yaml}}{lst:bf-no-headings-yaml} - \cmhlistingsfromfile*{demonstrations/tw-headings1-mod2.tex}{\texttt{tw-headings1-mod2.tex}}{lst:tw-headings1-mod2} + \cmhlistingsfromfile{demonstrations/bf-no-headings.yaml}[MLB-TCB]{\texttt{bf-no-headings.yaml}}{lst:bf-no-headings-yaml} + \cmhlistingsfromfile{demonstrations/tw-headings1-mod2.tex}{\texttt{tw-headings1-mod2.tex}}{lst:tw-headings1-mod2} \end{cmhtcbraster} \end{example} - \begin{example}[label={example:tw:comments}] - Let's use the sample text given in \cref{lst:tw-comments1}. \index{text wrap!blocksFollow!comments} + \begin{example} + Let's use the sample text given in \cref{lst:tw-comments1}. \index{text + wrap!blocksFollow!comments} - \cmhlistingsfromfile*{demonstrations/tw-comments1.tex}{\texttt{tw-comments1.tex}}{lst:tw-comments1} + \cmhlistingsfromfile{demonstrations/tw-comments1.tex}{\texttt{tw-comments1.tex}}{lst:tw-comments1} We note that \cref{lst:tw-comments1} contains trailing comments. Upon running the command \begin{commandshell} @@ -144,7 +145,7 @@ latexindent.pl -m -l textwrap1.yaml tw-comments1.tex \end{commandshell} then we receive the output given in \cref{lst:tw-comments1-mod1}. - \cmhlistingsfromfile*{demonstrations/tw-comments1-mod1.tex}{\texttt{tw-comments1-mod1.tex}}{lst:tw-comments1-mod1} + \cmhlistingsfromfile{demonstrations/tw-comments1-mod1.tex}{\texttt{tw-comments1-mod1.tex}}{lst:tw-comments1-mod1} With reference to \vref{lst:textWrapOptionsAll} the \texttt{commentOnPreviousLine} field is set to \texttt{1}, which instructs \texttt{latexindent.pl} to find text wrap blocks @@ -160,8 +161,8 @@ latexindent.pl -m -l textwrap1.yaml,bf-no-comments.yaml tw-comments1.tex raster left skip=-3.5cm, raster right skip=-2cm, ] - \cmhlistingsfromfile*{demonstrations/bf-no-comments.yaml}[MLB-TCB]{\texttt{bf-no-comments.yaml}}{lst:bf-no-comments-yaml} - \cmhlistingsfromfile*{demonstrations/tw-comments1-mod2.tex}{\texttt{tw-comments1-mod2.tex}}{lst:tw-comments1-mod2} + \cmhlistingsfromfile{demonstrations/bf-no-comments.yaml}[MLB-TCB]{\texttt{bf-no-comments.yaml}}{lst:bf-no-comments-yaml} + \cmhlistingsfromfile{demonstrations/tw-comments1-mod2.tex}{\texttt{tw-comments1-mod2.tex}}{lst:tw-comments1-mod2} \end{cmhtcbraster} \end{example} @@ -179,7 +180,7 @@ latexindent.pl -m -l textwrap1.yaml,bf-no-comments.yaml tw-comments1.tex Let's use the sample text given in \cref{lst:tw-disp-math1}. \index{text wrap!blocksFollow!other} \index{regular expressions!text wrap!blocksFollow} - \cmhlistingsfromfile*{demonstrations/tw-disp-math1.tex}{\texttt{tw-disp-math1.tex}}{lst:tw-disp-math1} + \cmhlistingsfromfile{demonstrations/tw-disp-math1.tex}{\texttt{tw-disp-math1.tex}}{lst:tw-disp-math1} We note that \cref{lst:tw-disp-math1} contains display math. Upon running the command \begin{commandshell} @@ -187,7 +188,7 @@ latexindent.pl -m -l textwrap1.yaml tw-disp-math1.tex \end{commandshell} then we receive the output given in \cref{lst:tw-disp-math1-mod1}. - \cmhlistingsfromfile*{demonstrations/tw-disp-math1-mod1.tex}{\texttt{tw-disp-math1-mod1.tex}}{lst:tw-disp-math1-mod1} + \cmhlistingsfromfile{demonstrations/tw-disp-math1-mod1.tex}{\texttt{tw-disp-math1-mod1.tex}}{lst:tw-disp-math1-mod1} With reference to \vref{lst:textWrapOptionsAll} the \texttt{other} field is set to \lstinline!\\\]!, which instructs \texttt{latexindent.pl} to find text wrap blocks after @@ -202,8 +203,8 @@ latexindent.pl -m -l textwrap1.yaml,bf-no-disp-math.yaml tw-disp-math1.tex gives the output in \cref{lst:tw-disp-math1-mod2}, in which text wrapping has been instructed \emph{not to happen} following display math. \begin{cmhtcbraster}[raster column skip=.1\linewidth] - \cmhlistingsfromfile*{demonstrations/bf-no-disp-math.yaml}[MLB-TCB]{\texttt{bf-no-disp-math.yaml}}{lst:bf-no-disp-math-yaml} - \cmhlistingsfromfile*{demonstrations/tw-disp-math1-mod2.tex}{\texttt{tw-disp-math1-mod2.tex}}{lst:tw-disp-math1-mod2} + \cmhlistingsfromfile{demonstrations/bf-no-disp-math.yaml}[MLB-TCB]{\texttt{bf-no-disp-math.yaml}}{lst:bf-no-disp-math-yaml} + \cmhlistingsfromfile{demonstrations/tw-disp-math1-mod2.tex}{\texttt{tw-disp-math1-mod2.tex}}{lst:tw-disp-math1-mod2} \end{cmhtcbraster} Naturally, you should feel encouraged to customise this as you see fit. @@ -218,7 +219,7 @@ latexindent.pl -m -l textwrap1.yaml,bf-no-disp-math.yaml tw-disp-math1.tex Let's use the sample text given in \cref{lst:tw-bf-myenv1}. \index{text wrap!blocksFollow!other} \index{regular expressions!text wrap!blocksFollow} - \cmhlistingsfromfile*{demonstrations/tw-bf-myenv1.tex}{\texttt{tw-bf-myenv1.tex}}{lst:tw-bf-myenv1} + \cmhlistingsfromfile{demonstrations/tw-bf-myenv1.tex}{\texttt{tw-bf-myenv1.tex}}{lst:tw-bf-myenv1} We note that \cref{lst:tw-bf-myenv1} contains \texttt{myenv} environment. Upon running the command @@ -227,7 +228,7 @@ latexindent.pl -m -l textwrap1.yaml tw-bf-myenv1.tex \end{commandshell} then we receive the output given in \cref{lst:tw-bf-myenv1-mod1}. - \cmhlistingsfromfile*{demonstrations/tw-bf-myenv1-mod1.tex}{\texttt{tw-bf-myenv1-mod1.tex}}{lst:tw-bf-myenv1-mod1} + \cmhlistingsfromfile{demonstrations/tw-bf-myenv1-mod1.tex}{\texttt{tw-bf-myenv1-mod1.tex}}{lst:tw-bf-myenv1-mod1} We note that we have \emph{not} received much text wrapping. We can turn do better by employing \cref{lst:tw-bf-myenv-yaml} and then run @@ -240,8 +241,8 @@ latexindent.pl -m -l textwrap1.yaml,tw-bf-myenv.yaml tw-bf-myenv1.tex raster left skip=-3.5cm, raster right skip=-2cm, ] - \cmhlistingsfromfile*{demonstrations/tw-bf-myenv.yaml}[MLB-TCB]{\texttt{tw-bf-myenv.yaml}}{lst:tw-bf-myenv-yaml} - \cmhlistingsfromfile*{demonstrations/tw-bf-myenv1-mod2.tex}{\texttt{tw-bf-myenv1-mod2.tex}}{lst:tw-bf-myenv1-mod2} + \cmhlistingsfromfile{demonstrations/tw-bf-myenv.yaml}[MLB-TCB]{\texttt{tw-bf-myenv.yaml}}{lst:tw-bf-myenv-yaml} + \cmhlistingsfromfile{demonstrations/tw-bf-myenv1-mod2.tex}{\texttt{tw-bf-myenv1-mod2.tex}}{lst:tw-bf-myenv1-mod2} \end{cmhtcbraster} \end{example} @@ -254,14 +255,14 @@ latexindent.pl -m -l textwrap1.yaml,tw-bf-myenv.yaml tw-bf-myenv1.tex By default, text wrap blocks can begin with the characters \texttt{a-z} and \texttt{A-Z}. If we start with the file given in \cref{lst:tw-0-9} - \cmhlistingsfromfile*{demonstrations/tw-0-9.tex}{\texttt{tw-0-9.tex}}{lst:tw-0-9} + \cmhlistingsfromfile{demonstrations/tw-0-9.tex}{\texttt{tw-0-9.tex}}{lst:tw-0-9} and run the command \begin{commandshell} latexindent.pl -m -l textwrap1.yaml tw-0-9.tex \end{commandshell} then we receive the output given in \cref{lst:tw-0-9-mod1} in which text wrapping has \emph{not} occured. - \cmhlistingsfromfile*{demonstrations/tw-0-9-mod1.tex}{\texttt{tw-0-9-mod1.tex}}{lst:tw-0-9-mod1} + \cmhlistingsfromfile{demonstrations/tw-0-9-mod1.tex}{\texttt{tw-0-9-mod1.tex}}{lst:tw-0-9-mod1} We can allow paragraphs to begin with \texttt{0-9} characters by using the settings in \cref{lst:bb-0-9-yaml} and running @@ -270,14 +271,14 @@ latexindent.pl -m -l textwrap1.yaml,bb-0-9-yaml tw-0-9.tex \end{commandshell} gives the output in \cref{lst:tw-0-9-mod2}, in which text wrapping \emph{has} happened. \begin{cmhtcbraster}[raster column skip=.1\linewidth,] - \cmhlistingsfromfile*{demonstrations/bb-0-9.yaml}[MLB-TCB]{\texttt{bb-0-9.yaml.yaml}}{lst:bb-0-9-yaml} - \cmhlistingsfromfile*{demonstrations/tw-0-9-mod2.tex}{\texttt{tw-0-9-mod2.tex}}{lst:tw-0-9-mod2} + \cmhlistingsfromfile{demonstrations/bb-0-9.yaml}[MLB-TCB]{\texttt{bb-0-9.yaml.yaml}}{lst:bb-0-9-yaml} + \cmhlistingsfromfile{demonstrations/tw-0-9-mod2.tex}{\texttt{tw-0-9-mod2.tex}}{lst:tw-0-9-mod2} \end{cmhtcbraster} \end{example} \begin{example} Let's now use the file given in \cref{lst:tw-bb-announce1} - \cmhlistingsfromfile*{demonstrations/tw-bb-announce1.tex}{\texttt{tw-bb-announce1.tex}}{lst:tw-bb-announce1} + \cmhlistingsfromfile{demonstrations/tw-bb-announce1.tex}{\texttt{tw-bb-announce1.tex}}{lst:tw-bb-announce1} and run the command \begin{commandshell} latexindent.pl -m -l textwrap1.yaml tw-bb-announce1.tex @@ -285,7 +286,7 @@ latexindent.pl -m -l textwrap1.yaml tw-bb-announce1.tex then we receive the output given in \cref{lst:tw-bb-announce1-mod1} in which text wrapping has \emph{not} occured. - \cmhlistingsfromfile*{demonstrations/tw-bb-announce1-mod1.tex}{\texttt{tw-bb-announce1-mod1.tex}}{lst:tw-bb-announce1-mod1} + \cmhlistingsfromfile{demonstrations/tw-bb-announce1-mod1.tex}{\texttt{tw-bb-announce1-mod1.tex}}{lst:tw-bb-announce1-mod1} We can allow \lstinline!\announce! to be at the beginning of paragraphs by using the settings in \cref{lst:tw-bb-announce-yaml} and running @@ -297,8 +298,8 @@ latexindent.pl -m -l textwrap1.yaml,tw-bb-announce.yaml tw-bb-announce1.tex gives the output in \cref{lst:tw-bb-announce1-mod2}, in which text wrapping \emph{has} happened. \begin{cmhtcbraster}[raster column skip=.1\linewidth,] - \cmhlistingsfromfile*{demonstrations/tw-bb-announce.yaml}[MLB-TCB]{\texttt{tw-bb-announce.yaml}}{lst:tw-bb-announce-yaml} - \cmhlistingsfromfile*{demonstrations/tw-bb-announce1-mod2.tex}{\texttt{tw-bb-announce1-mod2.tex}}{lst:tw-bb-announce1-mod2} + \cmhlistingsfromfile{demonstrations/tw-bb-announce.yaml}[MLB-TCB]{\texttt{tw-bb-announce.yaml}}{lst:tw-bb-announce-yaml} + \cmhlistingsfromfile{demonstrations/tw-bb-announce1-mod2.tex}{\texttt{tw-bb-announce1-mod2.tex}}{lst:tw-bb-announce1-mod2} \end{cmhtcbraster} \end{example} @@ -311,7 +312,7 @@ latexindent.pl -m -l textwrap1.yaml,tw-bb-announce.yaml tw-bb-announce1.tex Let's use the sample text given in \cref{lst:tw-be-equation}. \index{text wrap!blocksFollow!other} \index{regular expressions!text wrap!blocksFollow} - \cmhlistingsfromfile*{demonstrations/tw-be-equation.tex}{\texttt{tw-be-equation.tex}}{lst:tw-be-equation} + \cmhlistingsfromfile{demonstrations/tw-be-equation.tex}{\texttt{tw-be-equation.tex}}{lst:tw-be-equation} We note that \cref{lst:tw-be-equation} contains an environment. Upon running the command \begin{commandshell} @@ -319,7 +320,7 @@ latexindent.pl -m -l textwrap1A.yaml tw-be-equation.tex \end{commandshell} then we receive the output given in \cref{lst:tw-be-equation-mod1}. - \cmhlistingsfromfile*{demonstrations/tw-be-equation-mod1.tex}{\texttt{tw-be-equation-mod1.tex}}{lst:tw-be-equation-mod1} + \cmhlistingsfromfile{demonstrations/tw-be-equation-mod1.tex}{\texttt{tw-be-equation-mod1.tex}}{lst:tw-be-equation-mod1} With reference to \vref{lst:textWrapOptionsAll} the \texttt{other} field is set to \lstinline!\\begin\{|\\\[|\\end\{!, which instructs \texttt{latexindent.pl} to @@ -335,10 +336,10 @@ latexindent.pl -m -l textwrap1A.yaml,tw-be-equation.yaml tw-be-equation.tex gives the output in \cref{lst:tw-be-equation-mod2}, in which text wrapping has been instructed \emph{not} to stop at these statements. - \cmhlistingsfromfile*{demonstrations/tw-be-equation.yaml}[MLB-TCB]{\texttt{tw-be-equation.yaml}}{lst:tw-be-equation-yaml} + \cmhlistingsfromfile{demonstrations/tw-be-equation.yaml}[MLB-TCB]{\texttt{tw-be-equation.yaml}}{lst:tw-be-equation-yaml} \begin{widepage} - \cmhlistingsfromfile*{demonstrations/tw-be-equation-mod2.tex}{\texttt{tw-be-equation-mod2.tex}}{lst:tw-be-equation-mod2} + \cmhlistingsfromfile{demonstrations/tw-be-equation-mod2.tex}{\texttt{tw-be-equation-mod2.tex}}{lst:tw-be-equation-mod2} \end{widepage} Naturally, you should feel encouraged to customise this as you see fit. diff --git a/support/latexindent/documentation/title.tex b/support/latexindent/documentation/title.tex index 82975263d5..d31706f9dc 100644 --- a/support/latexindent/documentation/title.tex +++ b/support/latexindent/documentation/title.tex @@ -8,14 +8,14 @@ sharp corners, enhanced, overlay={\node[anchor=north east,outer sep=2pt] at ([xshift=3cm,yshift=4mm]frame.north east) {\includegraphics[width=3cm]{logo}}; }] - \centering\ttfamily\bfseries latexindent.pl\\[1cm] Version 3.16 + \centering\ttfamily\bfseries latexindent.pl\\[1cm] Version 3.17 \end{tcolorbox} } \author{Chris Hughes \thanks{and contributors! See \vref{sec:contributors}. For all communication, please visit \cite{latexindent-home}.}} -\date{2022-03-13} +\date{2022-03-25} \maketitle \begin{adjustwidth}{1cm}{1cm} \small diff --git a/support/latexindent/latexindent.pl b/support/latexindent/latexindent.pl index 70edb2f4a7..09134e9624 100755 --- a/support/latexindent/latexindent.pl +++ b/support/latexindent/latexindent.pl @@ -1,5 +1,5 @@ #!/usr/bin/env perl -# latexindent.pl, version 3.16, 2022-03-13 +# latexindent.pl, version 3.17, 2022-03-25 # # 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 @@ -39,6 +39,7 @@ GetOptions ( "yaml|y=s"=>\$switches{yaml}, "onlydefault|d"=>\$switches{onlyDefault}, "overwrite|w"=>\$switches{overwrite}, + "overwriteIfDifferent|wd"=>\$switches{overwriteIfDifferent}, "outputfile|o=s"=>\$switches{outputToFile}, "modifylinebreaks|m"=>\$switches{modifyLineBreaks}, "logfile|g=s"=>\$switches{logFileName}, @@ -51,8 +52,12 @@ GetOptions ( "check|k"=>\$switches{check}, "checkv|kv"=>\$switches{checkverbose}, "lines|n=s"=>\$switches{lines}, + "GCString"=>\$switches{GCString}, ); +# conditionally load the GCString module +eval "use Unicode::GCString" if $switches{GCString}; + # check local settings doesn't interfer with reading the file; # this can happen if the script is called as follows: # @@ -71,6 +76,6 @@ if($switches{readLocalSettings} and scalar(@ARGV) < 1) { # allow STDIN as input, if a filename is not present unshift( @ARGV, '-' ) unless @ARGV; -my $document = bless ({name=>"mainDocument",modifyLineBreaksYamlName=>"mainDocument",fileName=>$ARGV[0],switches=>\%switches},"LatexIndent::Document"); -$document->latexindent; +my $document = bless ({name=>"mainDocument",modifyLineBreaksYamlName=>"mainDocument",switches=>\%switches},"LatexIndent::Document"); +$document->latexindent( \@ARGV ); exit(0); |