summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/latexindent
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2020-11-06 21:53:13 +0000
committerKarl Berry <karl@freefriends.org>2020-11-06 21:53:13 +0000
commitdfba327ead142f0b6bc2d4cc326dc5accd491b0a (patch)
treebf11614cdb9196d5ee2ee8188932fc6b1348338d /Master/texmf-dist/scripts/latexindent
parentc94a02c2dfcdf9763957eefe2f80c61b25e4c96d (diff)
latexindent (6nov20)
git-svn-id: svn://tug.org/texlive/trunk@56869 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/latexindent')
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm30
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm9
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm12
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm8
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm5
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm6
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm4
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/defaultSettings.yaml44
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/latexindent.pl2
9 files changed, 101 insertions, 19 deletions
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm
index deb2d75032a..993423ab2ea 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm
@@ -400,6 +400,36 @@ sub align_at_ampersand{
# if the \end{} statement didn't originally have a line break before it, we need to remove the final
# line break added by the above
${$self}{body} =~ s/\h*\R$//s if !${$self}{linebreaksAtEnd}{body};
+
+ # if the \begin{} statement doesn't finish with a line break, then we adjust the indentation
+ # to be the length of the begin statement.
+ #
+ # example:
+ #
+ # \begin{align*}1&2\\
+ # 3&4\\
+ # 5 & 6
+ # \end{align*}
+ #
+ # goes to
+ #
+ # \begin{align*}1 & 2 \\
+ # 3 & 4 \\
+ # 5 & 6
+ # \end{align*}
+ #
+ # see https://github.com/cmhughes/latexindent.pl/issues/223 for example
+ if (!${${$self}{linebreaksAtEnd}}{begin}
+ and ${$cellStorage[0][0]}{type} eq "X"
+ and ${$cellStorage[0][0]}{measureThis}){
+
+ my $partToMeasure = ${$self}{begin};
+ if( (${$self}{begin} eq '{' | ${$self}{begin} eq '[') and ${$self}{parentBegin}){
+ $partToMeasure = ${$self}{parentBegin}."{";
+ }
+ ${$self}{indentation} = " " x Unicode::GCString->new($partToMeasure)->columns();
+ $logger->trace("Adjusting indentation of ${$self}{name} in AlignAtAmpersand routine") if($is_t_switch_active);
+ }
}
sub main_formatting {
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm
index 96450fdaaf2..385a3fcb47b 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm
@@ -118,6 +118,15 @@ sub find_opt_mand_arguments{
$arguments->find_round_brackets;
}
+ # we need to store the parent begin in each of the arguments, for example, see
+ # test-cases/texexchange/112343-morbusg.tex
+ # which has an alignment delimiter in the first line
+ if (${$self}{lookForAlignDelims}){
+ foreach (@{${$arguments}{children}}){
+ ${$_}{parentBegin} = ${$self}{begin};
+ }
+ }
+
# examine *first* child
# situation: parent BodyStartsOnOwnLine >= 1, but first child has BeginStartsOnOwnLine == 0 || BeginStartsOnOwnLine == undef
# problem: the *body* of parent actually starts after the arguments
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm
index addcdaf3f17..e46eccf3809 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm
@@ -20,6 +20,7 @@ use LatexIndent::Switches qw/%switches $is_m_switch_active $is_t_switch_active $
use YAML::Tiny; # interpret defaultSettings.yaml and other potential settings files
use File::Basename; # to get the filename and directory path
use File::HomeDir;
+use Cwd;
use Log::Log4perl qw(get_logger :levels);
use Exporter qw/import/;
our @EXPORT_OK = qw/yaml_read_settings yaml_modify_line_breaks_settings yaml_get_indentation_settings_for_this_object yaml_poly_switch_get_every_or_custom_value yaml_get_indentation_information yaml_get_object_attribute_for_indentation_settings yaml_alignment_at_ampersand_settings yaml_get_textwrap_removeparagraphline_breaks %masterSettings yaml_get_columns/;
@@ -169,6 +170,7 @@ sub yaml_read_settings{
push(@localSettings,$switches{readLocalSettings}) if($switches{readLocalSettings});
}
+ my $workingFileLocation = dirname (${$self}{fileName});
# add local settings to the paths, if appropriate
foreach (@localSettings) {
# check for an extension (.yaml)
@@ -180,8 +182,14 @@ sub yaml_read_settings{
# if the -l switch is called on its own, or else with +
# and latexindent.pl is called from a different directory, then
# we need to account for this
- if($_ eq "localSettings.yaml"){
- $_ = dirname (${$self}{fileName})."/".$_;
+ if($_ eq "localSettings.yaml" ){
+ # check for existence in the directory of the file.
+ if ( (-e $workingFileLocation."/".$_) ) {
+ $_ = $workingFileLocation."/".$_;
+ # otherwise we fallback to the current directory
+ } elsif( (-e cwd()."/".$_) ){
+ $_ = cwd()."/".$_;
+ }
}
# check for existence and non-emptiness
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm
index eb36db21082..ffb4d3f7375 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm
@@ -108,9 +108,6 @@ sub indent_begin{
sub indent_body{
my $self = shift;
- # grab the indentation of the object
- my $indentation = ${$self}{indentation};
-
# output to the logfile
$logger->trace("Body (${$self}{name}) before indentation:\n${$self}{body}") if $is_tt_switch_active;
@@ -123,6 +120,11 @@ sub indent_body{
# some objects can format their body to align at the & character
$self->align_at_ampersand if ${$self}{lookForAlignDelims};
+ # grab the indentation of the object
+ # NOTE: we need this here, as ${$self}{indentation} can be updated by the align_at_ampersand routine,
+ # see https://github.com/cmhughes/latexindent.pl/issues/223 for example
+ my $indentation = ${$self}{indentation};
+
# possibly remove paragraph line breaks
$self->remove_paragraph_line_breaks if ($is_m_switch_active and ${$self}{removeParagraphLineBreaks} and !${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{beforeTextWrap});
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm
index 763ca6e39e6..205d72031e3 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm
@@ -62,8 +62,9 @@ usage: latexindent.pl [options] [file][.tex|.sty|.cls|.bib|...]
-t, --trace
tracing mode: verbose information given to the log file
-l, --local[=myyaml.yaml]
- use localSettings.yaml (assuming it exists in the directory of your file);
- alternatively, use myyaml.yaml, if it exists; sample usage:
+ use localSettings.yaml (assuming it exists in the directory of your file,
+ or in the current working directory); alternatively, use myyaml.yaml, if it exists;
+ sample usage:
latexindent.pl -l some.yaml myfile.tex
latexindent.pl -l=another.yaml myfile.tex
latexindent.pl -l=some.yaml,another.yaml myfile.tex
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm
index de630a584b3..8b00c52272c 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm
@@ -168,7 +168,7 @@ sub modify_line_breaks_end{
# possibly modify line break *after* \end{statement}
if(defined $_ and $_>=1
- and !${$self}{linebreaksAtEnd}{end}){
+ and !${$self}{linebreaksAtEnd}{end} and ${$self}{end} ne ''){
# if the <end> statement doesn't finish with a line break,
# then we have different actions based upon the value of EndFinishesWithLineBreak:
# EndFinishesWithLineBreak == 1 just add a new line
@@ -187,7 +187,7 @@ sub modify_line_breaks_end{
$logger->trace("Even though $EndStringLogFile == 2, ${$self}{end} is immediately followed by a %, so not adding another; not adding line break.") if $is_t_switch_active;
} else {
# otherwise, create a trailing comment, and tack it on
- $logger->trace("Adding a % immediately after, ${$self}{end} ($EndStringLogFile==2)") if $is_t_switch_active;
+ $logger->trace("Adding a % immediately after ${$self}{end} ($EndStringLogFile==2)") if $is_t_switch_active;
my $trailingCommentToken = "%".$self->add_comment_symbol;
${$self}{end} =~ s/\h*$//s;
${$self}{replacementText} .= "$trailingCommentToken\n";
@@ -312,6 +312,8 @@ sub text_wrap{
}
$Text::Wrap::huge = ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{huge} if ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{huge};
$Text::Wrap::break = ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{break} if ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{break};
+ $Text::Wrap::unexpand = ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{unexpand} if ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{unexpand};
+ $Text::Wrap::tabstop = ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{tabstop} if ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{tabstop};
${$self}{body} = wrap('','',${$self}{body});
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm
index b2c63ba4579..a5dd88c0277 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm
@@ -19,6 +19,6 @@ use warnings;
use Exporter qw/import/;
our @EXPORT_OK = qw/$versionNumber $versionDate/;
-our $versionNumber = '3.8.2';
-our $versionDate = '2020-06-10';
+our $versionNumber = '3.8.3';
+our $versionDate = '2020-11-06';
1
diff --git a/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml b/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml
index 86b5113e9e0..d4ed8f0c805 100755
--- a/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml
+++ b/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml
@@ -1,4 +1,4 @@
-# defaultSettings.yaml for latexindent.pl, version 3.8.2, 2020-06-10
+# defaultSettings.yaml for latexindent.pl, version 3.8.3, 2020-11-06
# a script that aims to
# beautify .tex, .sty, .cls files
#
@@ -165,19 +165,49 @@ lookForAlignDelims:
tabu: 1
array: 1
matrix: 1
- bmatrix: 1
- Bmatrix: 1
- pmatrix: 1
- vmatrix: 1
- Vmatrix: 1
+ listabla: 1
+ # amsmath
align: 1
align*: 1
alignat: 1
alignat*: 1
aligned: 1
+ bmatrix: 1
+ Bmatrix: 1
cases: 1
+ flalign: 1
+ flalign*: 1
+ pmatrix: 1
+ vmatrix: 1
+ Vmatrix: 1
+ # mathtools
+ cases*: 1
dcases: 1
- listabla: 1
+ dcases*: 1
+ rcases: 1
+ rcases*: 1
+ drcases: 1
+ drcases*: 1
+ # nicematrix
+ NiceMatrix: 1
+ pNiceMatrix: 1
+ bNiceMatrix: 1
+ BNiceMatrix: 1
+ vNiceMatrix: 1
+ VNiceMatrix: 1
+ NiceArray: 1
+ pNiceArrayC: 1
+ bNiceArrayC: 1
+ BNiceArrayC: 1
+ vNiceArrayC: 1
+ VNiceArrayC: 1
+ NiceArrayCwithDelims: 1
+ pNiceArrayRC: 1
+ bNiceArrayRC: 1
+ BNiceArrayRC: 1
+ vNiceArrayRC: 1
+ VNiceArrayRC: 1
+ NiceArrayRCwithDelims: 1
# if you want the script to look for \item commands
# and format it, as follows (for example),
diff --git a/Master/texmf-dist/scripts/latexindent/latexindent.pl b/Master/texmf-dist/scripts/latexindent/latexindent.pl
index c54ad5c980d..f38d6c3fb53 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.8.2, 2020-06-10
+# latexindent.pl, version 3.8.3, 2020-11-06
#
# 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