From ed17b4b97e16c81b6869381411a74466acc81a23 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 24 Jul 2021 20:49:14 +0000 Subject: latexindent (24jul21) git-svn-id: svn://tug.org/texlive/trunk@60045 c570f23f-e606-0410-a88d-b1316a301751 --- .../linked_scripts/latexindent/latexindent.pl | 2 +- Master/bin/win32/latexindent.exe | Bin 6372694 -> 6375580 bytes Master/texmf-dist/doc/support/latexindent/README | 2 +- .../doc/support/latexindent/latexindent.pdf | Bin 942354 -> 946088 bytes Master/texmf-dist/doc/support/latexindent/logo.tex | 8 +- .../sec-conclusions-know-limitations.tex | 25 +-- .../support/latexindent/sec-default-user-local.tex | 72 +++--- .../doc/support/latexindent/sec-fine-tuning.tex | 8 +- .../doc/support/latexindent/sec-the-m-switch.tex | 164 +++++++------- .../texmf-dist/doc/support/latexindent/title.tex | 4 +- .../LatexIndent/AlignmentAtAmpersand.pm | 244 ++++++++++++++++++++- .../scripts/latexindent/LatexIndent/Document.pm | 26 ++- .../scripts/latexindent/LatexIndent/Else.pm | 4 + .../latexindent/LatexIndent/FileContents.pm | 5 +- .../latexindent/LatexIndent/HiddenChildren.pm | 79 ++++++- .../scripts/latexindent/LatexIndent/Indent.pm | 4 +- .../latexindent/LatexIndent/ModifyLineBreaks.pm | 13 +- .../scripts/latexindent/LatexIndent/Verbatim.pm | 59 +++-- .../scripts/latexindent/LatexIndent/Version.pm | 4 +- .../scripts/latexindent/defaultSettings.yaml | 4 +- .../texmf-dist/scripts/latexindent/latexindent.pl | 2 +- 21 files changed, 526 insertions(+), 203 deletions(-) diff --git a/Build/source/texk/texlive/linked_scripts/latexindent/latexindent.pl b/Build/source/texk/texlive/linked_scripts/latexindent/latexindent.pl index 838b15f9dd8..7813b3a6575 100755 --- a/Build/source/texk/texlive/linked_scripts/latexindent/latexindent.pl +++ b/Build/source/texk/texlive/linked_scripts/latexindent/latexindent.pl @@ -1,5 +1,5 @@ #!/usr/bin/env perl -# latexindent.pl, version 3.10, 2021-06-19 +# latexindent.pl, version 3.10.1, 2021-07-23 # # 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 diff --git a/Master/bin/win32/latexindent.exe b/Master/bin/win32/latexindent.exe index 2fd05da1ba8..fe12d7ed69a 100755 Binary files a/Master/bin/win32/latexindent.exe and b/Master/bin/win32/latexindent.exe differ diff --git a/Master/texmf-dist/doc/support/latexindent/README b/Master/texmf-dist/doc/support/latexindent/README index afe8bbbd844..a49f1a231fc 100644 --- a/Master/texmf-dist/doc/support/latexindent/README +++ b/Master/texmf-dist/doc/support/latexindent/README @@ -1,5 +1,5 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - latexindent.pl, version 3.10, 2021-06-19 + latexindent.pl, version 3.10.1, 2021-07-23 PERL script to indent code within environments, and align delimited environments in .tex files. diff --git a/Master/texmf-dist/doc/support/latexindent/latexindent.pdf b/Master/texmf-dist/doc/support/latexindent/latexindent.pdf index f57535e9c7e..09cd1d6f4f7 100644 Binary files a/Master/texmf-dist/doc/support/latexindent/latexindent.pdf and b/Master/texmf-dist/doc/support/latexindent/latexindent.pdf differ diff --git a/Master/texmf-dist/doc/support/latexindent/logo.tex b/Master/texmf-dist/doc/support/latexindent/logo.tex index 5bc31e0a4f3..d80dfec7213 100644 --- a/Master/texmf-dist/doc/support/latexindent/logo.tex +++ b/Master/texmf-dist/doc/support/latexindent/logo.tex @@ -14,8 +14,8 @@ \begin{document} \begin{tikzpicture}[logo/.style={draw=blue,circle,fill=white}] \matrix{ - \node[logo,dash pattern=on .5pt off 1.0pt,thick,draw=purple!75!white]{}; & \node[logo,draw=burntorange]{}; \\ - \node[logo,fill,draw=bakeoffgreen,fill=bakeoffblue]{}; & \node[logo,double,draw=cmhgold,fill=harvestgold]{};\\}; + \node[logo,dash pattern=on .5pt off 1.0pt,thick,draw=purple!75!white]{}; & \node[logo,draw=burntorange]{}; \\ + \node[logo,fill,draw=bakeoffgreen,fill=bakeoffblue]{}; & \node[logo,double,draw=cmhgold,fill=harvestgold]{};\\}; \end{tikzpicture} \end{document} @@ -24,8 +24,8 @@ \pagecolor{white} \begin{tikzpicture}[logo/.style={draw=blue,circle,fill=none,fill opacity=0.75}] \matrix{% - \node[logo,dash pattern=on .5pt off 1.0pt,thick,draw=purple!75!white]{}; & \node[logo,draw=burntorange]{}; \\ - \node[logo,fill,draw=bakeoffgreen,fill=bakeoffblue]{}; & \node[logo,double,draw=cmhgold,fill=harvestgold]{};\\}; + \node[logo,dash pattern=on .5pt off 1.0pt,thick,draw=purple!75!white]{}; & \node[logo,draw=burntorange]{}; \\ + \node[logo,fill,draw=bakeoffgreen,fill=bakeoffblue]{}; & \node[logo,double,draw=cmhgold,fill=harvestgold]{};\\}; \begin{scope}[on background layer] %\node [yshift=0.01em,xshift=0.07em] {\resizebox{1cm}{!}{\color{gray!50!white}\faGithub}}; \node {\resizebox{1cm}{!}{\color{gray!25!white}\faGithub}}; diff --git a/Master/texmf-dist/doc/support/latexindent/sec-conclusions-know-limitations.tex b/Master/texmf-dist/doc/support/latexindent/sec-conclusions-know-limitations.tex index 5f20a13d17a..938a0d6f530 100644 --- a/Master/texmf-dist/doc/support/latexindent/sec-conclusions-know-limitations.tex +++ b/Master/texmf-dist/doc/support/latexindent/sec-conclusions-know-limitations.tex @@ -3,29 +3,16 @@ There are a number of known limitations of the script, and almost certainly quite a few that are \emph{unknown}! - The main limitation is to do with the alignment routine discussed in - \cpageref{lst:aligndelims:advanced}; for example, consider the file given in \cref{lst:matrix2}. - - \cmhlistingsfromfile{demonstrations/matrix2.tex}{\texttt{matrix2.tex}}{lst:matrix2} - - The default output is given in \cref{lst:matrix2-default}, and it is clear that the alignment - routine has not worked as hoped, but it is \emph{expected}. \cmhlistingsfromfile{demonstrations/matrix2-default.tex}{\texttt{matrix2.tex} default output}{lst:matrix2-default} - - The reason for the problem is that when \texttt{latexindent.pl} stores its code blocks - (see \vref{tab:code-blocks}) it uses replacement tokens. The alignment routine is using - the \emph{length of the replacement token} in its measuring -- I hope to be able to address this in the - future. - - There are other limitations to do with the multicolumn alignment routine (see - \vref{lst:tabular2-mod2}); in particular, when working with code blocks in which - multicolumn commands overlap, the algorithm can fail. + For example, with reference to the multicolumn alignment routine in + \vref{lst:tabular2-mod2}), when working with code blocks in which multicolumn commands + overlap, the algorithm can fail. Another limitation is to do with efficiency, particularly when the \texttt{-m} switch is active, as this adds many checks and processes. The current implementation relies upon finding and storing \emph{every} code block (see the discussion on - \cpageref{page:phases}); it is hoped that, in a future version, only - \emph{nested} code blocks will need to be stored in the `packing' phase, and - that this will improve the efficiency of the script. + \cpageref{page:phases}); I hope that, in a future version, only \emph{nested} code + blocks will need to be stored in the `packing' phase, and that this will improve the + efficiency of the script. You can run \texttt{latexindent} on any file;% \announce{2019-07-13}*{ability to call latexindent on any file} if you don't specify an extension, then the extensions that you diff --git a/Master/texmf-dist/doc/support/latexindent/sec-default-user-local.tex b/Master/texmf-dist/doc/support/latexindent/sec-default-user-local.tex index 426c0c9b789..89a0596fd57 100644 --- a/Master/texmf-dist/doc/support/latexindent/sec-default-user-local.tex +++ b/Master/texmf-dist/doc/support/latexindent/sec-default-user-local.tex @@ -12,6 +12,12 @@ \emph{integer} in \emph{this} section, assume that it must be greater than or equal to \texttt{0} unless otherwise stated. + For most of the settings in \texttt{defaultSettings.yaml} that are specified as integers, then + we understand \texttt{0} to represent `off' and \texttt{1} to + represent `on'. For fields that allow values other than \texttt{0} or + \texttt{1}, it is hoped that the specific context and associated commentary + should make it clear which values are allowed. + \yamltitle{fileExtensionPreference}*{fields} \texttt{latexindent.pl} can be called to act on a file without specifying the file extension. For example we can call @@ -109,11 +115,11 @@ copy myfile.bak4 to myfile.bak3 \announce{2021-03-14}*{no longer using log4perl} Some of the options% - \announce*{2021-06-19}*{logFilePreferences updated to include Dumper options}for Perl's \texttt{Dumper} module can - be specified in \cref{lst:logFilePreferences}; see \cite{dumper} and - \cite{dumperdemo} for more information. These options will mostly be helpful for - those calling \texttt{latexindent.pl} with the \texttt{-tt} option described - in \cref{sec:commandline}. + \announce*{2021-06-19}*{logFilePreferences updated to include Dumper options}for Perl's + \texttt{Dumper} module can be specified in \cref{lst:logFilePreferences}; see + \cite{dumper} and \cite{dumperdemo} for more information. These options + will mostly be helpful for those calling \texttt{latexindent.pl} with the + \texttt{-tt} option described in \cref{sec:commandline}. \subsection{Verbatim code blocks} \yamltitle{verbatimEnvironments}*{fields} @@ -139,6 +145,11 @@ copy myfile.bak4 to myfile.bak3 breaking routines (only relevant if the \texttt{-m} is active, see \vref{sec:modifylinebreaks}). + With reference to \cref{lst:verbatimCommands}, by default \texttt{latexindent.pl} looks for + \lstinline|\verb| immediately followed by another character, and then it takes the + body as anything up to the next occurrence of the character; this means that, for + example, \lstinline|\verb!x+3!| is treated as a \texttt{verbatimCommands}. + \yamltitle{noIndentBlock}*{fields} If you have a block of code that you don't want \texttt{latexindent.pl} to touch (even if \index{verbatim!noIndentBlock} it is \emph{not} a verbatim-like environment) then @@ -153,17 +164,18 @@ copy myfile.bak4 to myfile.bak3 \cmhlistingsfromfile{demonstrations/noindentblock.tex}{\texttt{noIndentBlock.tex}}{lst:noIndentBlockdemo} - Important note: it is assumed that the \texttt{noindent} block statements appear on - their own line. + Important note: it is assumed that the \texttt{noindent} block statements specified + in this way appear on their own line. The% \announce*{2021-06-19}{noIndentBlock specified as regex} \texttt{noIndentBlock} fields can also be specified in terms of \texttt{begin} and - \texttt{end} fields. We begin with the file given in \cref{lst:noIndentBlock1} + \texttt{end} fields. We use the code in \cref{lst:noIndentBlock1} to demonstrate + this feature. \cmhlistingsfromfile*{demonstrations/noindentblock1.tex}{\texttt{noIndentBlock1.tex}}{lst:noIndentBlock1} - The settings given in \cref{lst:noindent1,lst:noindent2} are equivalent + The settings given in \cref{lst:noindent1,lst:noindent2} are equivalent: \begin{cmhtcbraster}[raster columns=3, raster left skip=-3.5cm, @@ -186,7 +198,9 @@ latexindent.pl -l noindent2.yaml noindent1 The \texttt{begin}, \texttt{body} and \texttt{end} fields for \texttt{noIndentBlock} are all \emph{regular expressions}. If the \texttt{body} field is not specified, then it takes a default value of - \lstinline!.*?! which is written explicitly in \cref{lst:noindent1}. + \lstinline!.*?! which is written explicitly in \cref{lst:noindent1}. In this + context, + we interpret \lstinline!.*?! in words as \emph{the fewest number of characters (possibly none) until the `end' field is reached}. The \texttt{lookForThis} field is optional, and can take the values 0 (off) or 1 (on); by default, it is assumed to be 1 (on). @@ -518,8 +532,8 @@ latexindent.pl aligned1.tex -l sba4.yaml \item \cref{lst:sba3} demonstrates the new \emph{advanced} way to specify \texttt{spacesBeforeAmpersand}, and for us to set the \texttt{default} value that sets the number of spaces before - ampersands which are \emph{not} in leading blank columns. The default - value is \texttt{1}. + ampersands which are \emph{not} in leading blank columns. The + default value is \texttt{1}. We note that \texttt{leadingBlankColumn} has not been specified in \cref{lst:sba3}, and it will inherit the value from \texttt{default}; @@ -1168,33 +1182,33 @@ latexindent.pl mult-nested.tex -l=max-indentation1 \caption{Code blocks known to \texttt{latexindent.pl}}\label{tab:code-blocks} \begin{tabular}{m{.3\linewidth}@{\hspace{.25cm}}m{.4\linewidth}@{\hspace{.25cm}}m{.2\linewidth}} \toprule - Code block & characters allowed in name & example \\ + Code block & characters allowed in name & example \\ \midrule - environments & \lstinline!a-zA-Z@\*0-9_\\! & + environments & \lstinline!a-zA-Z@\*0-9_\\! & \begin{lstlisting}[,nolol=true,] \begin{myenv} body of myenv \end{myenv} \end{lstlisting} \\\cmidrule{2-3} - optionalArguments & \emph{inherits} name from parent (e.g environment name) & + optionalArguments & \emph{inherits} name from parent (e.g environment name) & \begin{lstlisting}[,nolol=true,] [ opt arg text ] \end{lstlisting} \\\cmidrule{2-3} - mandatoryArguments & \emph{inherits} name from parent (e.g environment name) & + mandatoryArguments & \emph{inherits} name from parent (e.g environment name) & \begin{lstlisting}[,nolol=true,] { mand arg text } \end{lstlisting} \\\cmidrule{2-3} - commands & \lstinline!+a-zA-Z@\*0-9_\:! & \lstinline!\mycommand!$\langle$\itshape{arguments}$\rangle$ \\\cmidrule{2-3} - keyEqualsValuesBracesBrackets & \lstinline!a-zA-Z@\*0-9_\/.\h\{\}:\#-! & \lstinline!my key/.style=!$\langle$\itshape{arguments}$\rangle$ \\\cmidrule{2-3} - namedGroupingBracesBrackets & \lstinline!0-9\.a-zA-Z@\*>0, measureThis=> ($numberOfAmpersands>0 ? ${$self}{measureRow} : 0) }); + # possible hidden children, see https://github.com/cmhughes/latexindent.pl/issues/85 + if ( (${$self}{measureHiddenChildren} or ${$self}{measureVerbatim} ) + and $column =~m/.*?$tokens{beginOfToken}/s){ + $self->hidden_child_cell_row_width($column,$rowCounter,$columnCounter); + } + # store the maximum column width $maxColumnWidth[$columnCounter] = (defined $maxColumnWidth[$columnCounter] ? @@ -424,15 +435,16 @@ sub align_at_ampersand{ # \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}; + my $lengthOfBegin = ${$self}{begin}; if( (${$self}{begin} eq '{' | ${$self}{begin} eq '[') and ${$self}{parentBegin}){ - $partToMeasure = ${$self}{parentBegin}."{"; + $lengthOfBegin = ${$self}{parentBegin}."{"; } - ${$self}{indentation} = " " x Unicode::GCString->new($partToMeasure)->columns(); + ${$self}{indentation} = " " x Unicode::GCString->new($lengthOfBegin)->columns(); $logger->trace("Adjusting indentation of ${$self}{name} in AlignAtAmpersand routine") if($is_t_switch_active); } } @@ -530,6 +542,10 @@ sub main_formatting { # objective (2): calculate row width and update maximumRowWidth # objective (2): calculate row width and update maximumRowWidth my $rowWidth = Unicode::GCString->new($tmpRow)->columns(); + + # 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}); + ${$formattedBody[$rowCount]}{rowWidth} = $rowWidth; # update the maximum row width @@ -538,6 +554,19 @@ sub main_formatting { ${$self}{maximumRowWidth} = $rowWidth; } } + + # log file information + if($is_tt_switch_active and ${$self}{measureHiddenChildren}){ + $logger->info('*FamilyTree after align for ampersand'); + $logger->trace(Dumper(\%familyTree)) if($is_tt_switch_active); + + $rowCount = -1; + # row loop + foreach my $row (@cellStorage) { + $rowCount++; + $logger->trace("row $rowCount row width: ${$formattedBody[$rowCount]}{rowWidth}"); + } + } } sub dont_measure{ @@ -1344,4 +1373,211 @@ sub double_back_slash_else{ logName=>"double-back-slash-block (for align at ampersand, see lookForAlignDelims)", ); } + +# possible hidden children, see test-cases/alignment/issue-162.tex and friends +# +# \begin{align} +# A & =\begin{array}{cc} %