diff options
32 files changed, 726 insertions, 301 deletions
diff --git a/Build/source/texk/texlive/linked_scripts/latexindent/latexindent.pl b/Build/source/texk/texlive/linked_scripts/latexindent/latexindent.pl index ef24db27b25..838b15f9dd8 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.9.3, 2021-05-07 +# latexindent.pl, version 3.10, 2021-06-19 # # 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 Binary files differindex b6f417c1045..2fd05da1ba8 100755 --- a/Master/bin/win32/latexindent.exe +++ b/Master/bin/win32/latexindent.exe diff --git a/Master/texmf-dist/doc/support/latexindent/README b/Master/texmf-dist/doc/support/latexindent/README index 225e4ba5f34..afe8bbbd844 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.9.3, 2021-05-07 + latexindent.pl, version 3.10, 2021-06-19 PERL script to indent code within environments, and align delimited environments in .tex files. diff --git a/Master/texmf-dist/doc/support/latexindent/appendices.tex b/Master/texmf-dist/doc/support/latexindent/appendices.tex index c60445b1b70..b6f1e9615c0 100644 --- a/Master/texmf-dist/doc/support/latexindent/appendices.tex +++ b/Master/texmf-dist/doc/support/latexindent/appendices.tex @@ -23,6 +23,7 @@ use YAML::Tiny; use File::Copy; use File::Basename; use File::HomeDir; +use Encode; use Getopt::Long; use Data::Dumper; use List::Util qw(max); @@ -228,6 +229,38 @@ TRACE: Searching myenv for optional and mandatory arguments Notice that the information given about \texttt{myenv} is `framed' using \texttt{+++++} and \lstinline!-----! respectively. + \section{Encoding indentconfig.yaml}\label{app:encoding} + In relation to \vref{sec:indentconfig}, Windows users that encounter encoding issues with + \texttt{indentconfig.yaml}, may wish to run the following command in either + \texttt{cmd.exe} or \texttt{powershell.exe}: + \begin{dosprompt} +chcp + \end{dosprompt} + They may receive the following result + \begin{dosprompt} +Active code page: 936 + \end{dosprompt} + and can then use the settings given in \cref{lst:indentconfig-encoding1} within their + \texttt{indentconfig.yaml}, where 936 is the result of the \texttt{chcp} command. + + \cmhlistingsfromfile*{demonstrations/encoding1.yaml}[yaml-TCB]{\texttt{encoding} demonstration for \texttt{indentconfig.yaml}}{lst:indentconfig-encoding1} + + \section{dos2unix linebreak adjustment} + + \yamltitle{dos2unixlinebreaks}*{integer} + If you use \texttt{latexindent.pl} on a dos-based Windows file on Linux + \announce*{2021-06-19}{dos2unix linebreaks} then you may find that trailing horizontal space is not removed + as you hope. + + In such a case, you may wish to try setting \texttt{dos2unixlinebreaks} to 1 and employing, + for example, the following command. + + \begin{commandshell} +latexindent.pl -y="dos2unixlinebreaks:1" myfile.tex +\end{commandshell} + + See \cite{bersbersbers} for further dertails. + \section{Differences from Version 2.2 to 3.0}\label{app:differences} There are a few (small) changes to the interface when comparing Version 2.2 to Version 3.0. Explicitly, in previous versions you might have run, for example, diff --git a/Master/texmf-dist/doc/support/latexindent/latexindent.pdf b/Master/texmf-dist/doc/support/latexindent/latexindent.pdf Binary files differindex a6d1c74fa59..f57535e9c7e 100644 --- a/Master/texmf-dist/doc/support/latexindent/latexindent.pdf +++ b/Master/texmf-dist/doc/support/latexindent/latexindent.pdf diff --git a/Master/texmf-dist/doc/support/latexindent/latexindent.tex b/Master/texmf-dist/doc/support/latexindent/latexindent.tex index 22aecf1b78d..2691cfa9ec7 100644 --- a/Master/texmf-dist/doc/support/latexindent/latexindent.tex +++ b/Master/texmf-dist/doc/support/latexindent/latexindent.tex @@ -321,175 +321,175 @@ \lstdefinestyle{logFilePreferences}{ style=yaml-LST, - firstnumber=85,linerange={85-91}, + firstnumber=85,linerange={85-99}, numbers=left, } \lstdefinestyle{verbatimEnvironments}{ style=yaml-LST, - firstnumber=95,linerange={95-98}, + firstnumber=103,linerange={103-106}, numbers=left, } \lstdefinestyle{verbatimCommands}{ style=yaml-LST, - firstnumber=101,linerange={101-103}, + firstnumber=109,linerange={109-111}, numbers=left, } \lstdefinestyle{noIndentBlock}{ style=yaml-LST, - firstnumber=108,linerange={108-110}, + firstnumber=116,linerange={116-118}, numbers=left, } \lstdefinestyle{removeTrailingWhitespace}{ style=yaml-LST, - firstnumber=113,linerange={113-115}, + firstnumber=147,linerange={147-149}, numbers=left, } \lstdefinestyle{fileContentsEnvironments}{ style=yaml-LST, - firstnumber=119,linerange={119-121}, + firstnumber=122,linerange={122-124}, numbers=left, } \lstdefinestyle{lookForPreamble}{ style=yaml-LST, - firstnumber=127,linerange={127-131}, + firstnumber=130,linerange={130-134}, numbers=left, } \lstdefinestyle{lookForAlignDelims}{ style=yaml-LST, - firstnumber=144,linerange={144-160}, + firstnumber=152,linerange={152-168}, numbers=left, } \lstdefinestyle{indentAfterItems}{ style=yaml-LST, - firstnumber=217,linerange={217-221}, + firstnumber=225,linerange={225-229}, numbers=left, } \lstdefinestyle{itemNames}{ style=yaml-LST, - firstnumber=227,linerange={227-229}, + firstnumber=235,linerange={235-237}, numbers=left, } \lstdefinestyle{specialBeginEnd}{ style=yaml-LST, - firstnumber=233,linerange={233-246}, + firstnumber=241,linerange={241-254}, numbers=left, } \lstdefinestyle{indentAfterHeadings}{ style=yaml-LST, - firstnumber=256,linerange={256-265}, + firstnumber=264,linerange={264-273}, numbers=left, } \lstdefinestyle{noAdditionalIndentGlobalEnv}{ style=yaml-LST, - firstnumber=314,linerange={314-315}, + firstnumber=322,linerange={322-323}, numbers=left, } \lstdefinestyle{noAdditionalIndentGlobal}{ style=yaml-LST, - firstnumber=314,linerange={314-326}, + firstnumber=322,linerange={322-334}, numbers=left, } \lstdefinestyle{indentRulesGlobalEnv}{ style=yaml-LST, - firstnumber=330,linerange={330-331}, + firstnumber=338,linerange={338-339}, numbers=left, } \lstdefinestyle{indentRulesGlobal}{ style=yaml-LST, - firstnumber=330,linerange={330-342}, + firstnumber=338,linerange={338-350}, numbers=left, } \lstdefinestyle{commandCodeBlocks}{ style=yaml-LST, - firstnumber=345,linerange={345-360}, + firstnumber=353,linerange={353-368}, numbers=left, } \lstdefinestyle{modifylinebreaks}{ style=yaml-LST, - firstnumber=472,linerange={472-474}, + firstnumber=483,linerange={483-485}, numbers=left, } \lstdefinestyle{textWrapOptions}{ style=yaml-LST, - firstnumber=499,linerange={499-500}, + firstnumber=510,linerange={510-511}, numbers=left, } \lstdefinestyle{textWrapOptionsAll}{ style=yaml-LST, - firstnumber=499,linerange={499-515}, + firstnumber=510,linerange={510-527}, numbers=left, } \lstdefinestyle{removeParagraphLineBreaks}{ style=yaml-LST, - firstnumber=516,linerange={516-530}, + firstnumber=528,linerange={528-542}, numbers=left, } \lstdefinestyle{paragraphsStopAt}{ style=yaml-LST, - firstnumber=531,linerange={531-540}, + firstnumber=543,linerange={543-552}, numbers=left, } \lstdefinestyle{oneSentencePerLine}{ style=yaml-LST, - firstnumber=475,linerange={475-498}, + firstnumber=486,linerange={486-509}, numbers=left, } \lstdefinestyle{sentencesFollow}{ style=yaml-LST, - firstnumber=480,linerange={480-488}, + firstnumber=491,linerange={491-499}, numbers=left, } \lstdefinestyle{sentencesBeginWith}{ style=yaml-LST, - firstnumber=489,linerange={489-492}, + firstnumber=500,linerange={500-503}, numbers=left, } \lstdefinestyle{sentencesEndWith}{ style=yaml-LST, - firstnumber=493,linerange={493-498}, + firstnumber=504,linerange={504-509}, numbers=left, } \lstdefinestyle{modifylinebreaksEnv}{ style=yaml-LST, - firstnumber=541,linerange={541-550}, + firstnumber=553,linerange={553-562}, numbers=left, } \lstdefinestyle{replacements}{ style=yaml-LST, - firstnumber=602,linerange={602-610}, + firstnumber=614,linerange={614-622}, numbers=left, } \lstdefinestyle{fineTuning}{ style=yaml-LST, - firstnumber=613,linerange={613-634}, + firstnumber=625,linerange={625-648}, numbers=left, } 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 a768d0ba6a8..5f20a13d17a 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 @@ -31,7 +31,7 @@ \announce{2019-07-13}*{ability to call latexindent on any file} if you don't specify an extension, then the extensions that you specify in \lstinline[breaklines=true]!fileExtensionPreference! (see \vref{lst:fileExtensionPreference}) will be consulted. If you find a case in which the script struggles, please feel free to report it at - \cite{latexindent-home}, and in the meantime, consider using a \texttt{noIndentBlock} (see \cpageref{lst:noIndentBlockdemo}). + \cite{latexindent-home}, and in the meantime, consider using a \texttt{noIndentBlock} (see \cpageref{lst:noIndentBlock}). I hope that this script is useful to some; if you find an example where the script does not behave as you think it should, the best way to contact me is to report an issue on 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 2e5afbcdae2..426c0c9b789 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 @@ -33,6 +33,7 @@ latexindent.pl myfile \index{backup files!extension settings} +\subsection{Backup and log file preferences} \yamltitle{backupExtension}*{extension name} If you call \texttt{latexindent.pl} with the \texttt{-w} switch (to overwrite @@ -89,7 +90,7 @@ copy myfile.bak4 to myfile.bak3 amalgamated settings in the log file by switching \texttt{showAmalgamatedSettings} to \texttt{1}, if you wish. - \cmhlistingsfromfile[style=logFilePreferences,]*{../defaultSettings.yaml}[width=.9\linewidth,before=\centering,yaml-TCB]{\texttt{logFilePreferences}}{lst:logFilePreferences} + \cmhlistingsfromfile*[style=logFilePreferences,]*{../defaultSettings.yaml}[width=.9\linewidth,before=\centering,yaml-TCB]{\texttt{logFilePreferences}}{lst:logFilePreferences} When% \announce{2018-01-13}{showDecorationStartCodeBlockTrace feature for log file} either of the @@ -105,8 +106,16 @@ copy myfile.bak4 to myfile.bak3 Note: \texttt{latexindent.pl} no longer uses the \texttt{log4perl} module to handle the creation of the logfile.% - \announce*{2021-03-14}*{no longer using log4perl} + \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}. + +\subsection{Verbatim code blocks} \yamltitle{verbatimEnvironments}*{fields} A field that contains a list of environments that you would like left completely alone -- @@ -142,41 +151,58 @@ copy myfile.bak4 to myfile.bak3 you use them with a comment symbol, \lstinline!%!, followed by as many spaces (possibly none) as you like; see \cref{lst:noIndentBlockdemo} for example. - \begin{cmhlistings}[style=demo,escapeinside={(*@}{@*)}]{\texttt{noIndentBlock} demonstration}{lst:noIndentBlockdemo} -%(*@@*) \begin{noindent} - this code - won't - be touched - by - latexindent.pl! -%(*@@*)\end{noindent} - \end{cmhlistings} + \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. -\yamltitle{removeTrailingWhitespace}*{fields}\label{yaml:removeTrailingWhitespace} + 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} - Trailing white space can be removed both \emph{before} and - \emph{after} processing the document, as detailed in \cref{lst:removeTrailingWhitespace}; - each of the fields can take the values \texttt{0} or - \texttt{1}. See \vref{lst:removeTWS-before,lst:env-mlb5-modAll,lst:env-mlb5-modAll-remove-WS} for before and after results. Thanks - to \cite{vosskuhle} for providing this feature. + \cmhlistingsfromfile*{demonstrations/noindentblock1.tex}{\texttt{noIndentBlock1.tex}}{lst:noIndentBlock1} - \begin{minipage}{.4\textwidth} - \cmhlistingsfromfile[style=removeTrailingWhitespace]*{../defaultSettings.yaml}[before=\centering,yaml-TCB]{removeTrailingWhitespace}{lst:removeTrailingWhitespace} - \end{minipage}% - \hfill - \begin{minipage}{.5\textwidth} - \begin{yaml}[numbers=none]{removeTrailingWhitespace (alt)}[before=\centering]{lst:removeTrailingWhitespace-alt} -removeTrailingWhitespace: 1 -\end{yaml} - \end{minipage}% + The settings given in \cref{lst:noindent1,lst:noindent2} are equivalent - You can specify \texttt{removeTrailingWhitespace} simply as \texttt{0} or - \texttt{1}, if you wish; in this case,% - \announce{2017-06-28}{removeTrailingWhitespace} \texttt{latexindent.pl} will set both \texttt{beforeProcessing} and - \texttt{afterProcessing} to the value you specify; see \cref{lst:removeTrailingWhitespace-alt}. + \begin{cmhtcbraster}[raster columns=3, + raster left skip=-3.5cm, + raster right skip=-2cm, + raster column skip=.03\linewidth] + \cmhlistingsfromfile*{demonstrations/noindent1.yaml}[yaml-TCB]{\texttt{noindent1.yaml}}{lst:noindent1} + \cmhlistingsfromfile*{demonstrations/noindent2.yaml}[yaml-TCB]{\texttt{noindent2.yaml}}{lst:noindent2} + \cmhlistingsfromfile*{demonstrations/noindent3.yaml}[yaml-TCB]{\texttt{noindent3.yaml}}{lst:noindent3} + \end{cmhtcbraster} + + Upon running the commands + \begin{commandshell} +latexindent.pl -l noindent1.yaml noindent1 +latexindent.pl -l noindent2.yaml noindent1 +\end{commandshell} + then we receive the output given in \cref{lst:noIndentBlock1-mod1}. + + \cmhlistingsfromfile*{demonstrations/noindentblock1-mod1.tex}{\texttt{noIndentBlock1.tex} using \cref{lst:noindent1} or \cref{lst:noindent2}}{lst:noIndentBlock1-mod1} + + 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}. + + 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). + + Using \cref{lst:noindent3} demonstrates setting \texttt{lookForThis} to 0 (off); + running the command + \begin{commandshell} +latexindent.pl -l noindent3.yaml noindent1 +\end{commandshell} + gives the output in \cref{lst:noIndentBlock1-mod3}. + + \cmhlistingsfromfile*{demonstrations/noindentblock1-mod3.tex}{\texttt{noIndentBlock1.tex} using \cref{lst:noindent3}}{lst:noIndentBlock1-mod3} + + We will demonstrate this feature later in the documentation in \cref{lst:href3}. + +\subsection{filecontents and preamble} \yamltitle{fileContentsEnvironments}*{field} Before \texttt{latexindent.pl} determines the difference between preamble (if any) and @@ -221,18 +247,43 @@ postfoothook=\end{mdframed}, \index{indentation!defaultIndent description} +\subsection{Indentation and horizontal space} \yamltitle{defaultIndent}*{horizontal space} - This is the default indentation (\lstinline!\t! means a tab, and is the default - value) used in the absence of other details for the command or environment we are working - with; see \texttt{indentRules} in \vref{sec:noadd-indent-rules} for more details. + This is the default indentation used in the absence of other details for the code block + with which we are working. The default value is \lstinline!\t! which means a tab; + we will explore customisation beyond \texttt{defaultIndent} in \vref{sec:noadd-indent-rules}. If you're interested in experimenting with \texttt{latexindent.pl} then you can \emph{remove} all indentation by setting \texttt{defaultIndent: ""}. +\yamltitle{removeTrailingWhitespace}*{fields}\label{yaml:removeTrailingWhitespace} + + Trailing white space can be removed both \emph{before} and + \emph{after} processing the document, as detailed in \cref{lst:removeTrailingWhitespace}; + each of the fields can take the values \texttt{0} or + \texttt{1}. See \vref{lst:removeTWS-before,lst:env-mlb5-modAll,lst:env-mlb5-modAll-remove-WS} for before and after results. Thanks + to \cite{vosskuhle} for providing this feature. + + \begin{minipage}{.4\textwidth} + \cmhlistingsfromfile[style=removeTrailingWhitespace]*{../defaultSettings.yaml}[before=\centering,yaml-TCB]{removeTrailingWhitespace}{lst:removeTrailingWhitespace} + \end{minipage}% + \hfill + \begin{minipage}{.5\textwidth} + \begin{yaml}[numbers=none]{removeTrailingWhitespace (alt)}[before=\centering]{lst:removeTrailingWhitespace-alt} +removeTrailingWhitespace: 1 +\end{yaml} + \end{minipage}% + + You can specify \texttt{removeTrailingWhitespace} simply as \texttt{0} or + \texttt{1}, if you wish; in this case,% + \announce{2017-06-28}{removeTrailingWhitespace} \texttt{latexindent.pl} will set both \texttt{beforeProcessing} and + \texttt{afterProcessing} to the value you specify; see \cref{lst:removeTrailingWhitespace-alt}. + +\subsection{Aligning at delimiters} \yamltitle{lookForAlignDelims}*{fields} - This contains a list of environments and/or commands that are operated upon in a special - way by \texttt{latexindent.pl} (see \cref{lst:aligndelims:basic}). In fact, the fields in \texttt{lookForAlignDelims} can - actually take two different forms: the \emph{basic} version is shown in + 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 \texttt{lookForAlignDelims} can actually take + two different forms: the \emph{basic} version is shown in \cref{lst:aligndelims:basic} and the \emph{advanced} version in \cref{lst:aligndelims:advanced}; we will discuss each in turn. \index{delimiters!advanced settings of lookForAlignDelims} @@ -247,10 +298,9 @@ lookForAlignDelims: ... \end{yaml} - The environments specified in this field will be operated on in a special way by - \texttt{latexindent.pl}. In particular, it will try and align each column by its - alignment tabs. It does have some limitations (discussed further in - \cref{sec:knownlimitations}), but in many cases it will produce results such as those in + Specifying code blocks in this field instructs \texttt{latexindent.pl} to try and align + each column by its alignment delimiters. It does have some limitations (discussed further + in \cref{sec:knownlimitations}), but in many cases it will produce results such as those in \cref{lst:tabularbefore:basic,lst:tabularafter:basic}. If you find that \texttt{latexindent.pl} does not perform satisfactorily on such @@ -291,7 +341,8 @@ lookForAlignDelims: should be aligned (default: 1); \item \texttt{spacesBeforeDoubleBackSlash}: optionally,% \announce{2018-01-13}*{update to spacesBeforeDoubleBackSlash in ampersand alignment} specifies the number (integer $\geq$ 0) of spaces - to be inserted before \lstinline!\\! (default: 1). \footnote{Previously this only activated if \texttt{alignDoubleBackSlash} was set to \texttt{0}.} + to be inserted before \lstinline!\\! (default: 1); + %\footnote{Previously this only activated if \texttt{alignDoubleBackSlash} was set to \texttt{0}.} \item \announce{2017-06-19}{multiColumnGrouping} \texttt{multiColumnGrouping}: binary switch (0 or 1) that details if \texttt{latexindent.pl} should group columns above and below a \lstinline!\multicolumn! command (default: 0); @@ -407,12 +458,104 @@ latexindent.pl tabular2.tex -l tabular2.yaml,tabular8.yaml output is the same as \cref{lst:tabular2-mod2}; \item in \cref{lst:tabular2-mod7} the \lstinline!\\! \emph{have} been aligned, and because \texttt{spacesBeforeDoubleBackSlash} is set to \texttt{0}, there are - no spaces ahead of them; the output is otherwise the same as \cref{lst:tabular2-mod2}. + no spaces ahead of them; the output is otherwise the same as \cref{lst:tabular2-mod2}; \item in \cref{lst:tabular2-mod8} the cells have been \emph{right}-justified; note that cells above and below the \lstinline!\multicol! statements have still been group correctly, because of the settings in \cref{lst:tabular2YAML}. \end{itemize} +\subsubsection{lookForAlignDelims: spacesBeforeAmpersand} + The \texttt{spacesBeforeAmpersand}% + \announce*{2021-06-19}*{spacesBeforeAmpersand leading blank column upgrade} can be specified in a few different + ways. The \emph{basic} form is demonstrated in \cref{lst:tabular4YAML}, but we + can customise the behaviour further by specifying if we would like this value to change + if it encounters a \emph{leading blank column}; that is, when the first column contains only + zero-width entries. We refer to this as the \emph{advanced} form. + + We demonstrate this feature in relation to \cref{lst:aligned1}; upon running the + following command + \begin{commandshell} +latexindent.pl aligned1.tex -o=+-default +\end{commandshell} + then we receive the default output given in \cref{lst:aligned1-default}. + + \begin{cmhtcbraster} + \cmhlistingsfromfile*{demonstrations/aligned1.tex}{\texttt{aligned1.tex}}{lst:aligned1} + \cmhlistingsfromfile*{demonstrations/aligned1-default.tex}{\texttt{aligned1-default.tex}}{lst:aligned1-default} + \end{cmhtcbraster} + + The settings in \crefrange{lst:sba1}{lst:sba4} are all equivlanent; we have used the not-yet + discussed \texttt{noAdditionalIndent} field (see \vref{sec:noadd-indent-rules}) which will assist + in the demonstration in what follows. + \begin{cmhtcbraster}[raster columns=2, ] + \cmhlistingsfromfile*{demonstrations/sba1.yaml}[yaml-TCB]{\texttt{sba1.yaml}}{lst:sba1} + \cmhlistingsfromfile*{demonstrations/sba2.yaml}[yaml-TCB]{\texttt{sba2.yaml}}{lst:sba2} + \cmhlistingsfromfile*{demonstrations/sba3.yaml}[yaml-TCB]{\texttt{sba3.yaml}}{lst:sba3} + \cmhlistingsfromfile*{demonstrations/sba4.yaml}[yaml-TCB]{\texttt{sba4.yaml}}{lst:sba4} + \end{cmhtcbraster} + Upon running the following commands + \begin{commandshell} +latexindent.pl aligned1.tex -l sba1.yaml +latexindent.pl aligned1.tex -l sba2.yaml +latexindent.pl aligned1.tex -l sba3.yaml +latexindent.pl aligned1.tex -l sba4.yaml +\end{commandshell} + then we receive the (same) output given in \cref{lst:aligned1-mod1}; we note that there is + \emph{one space} before each ampersand. + + \begin{cmhtcbraster} + \cmhlistingsfromfile*{demonstrations/aligned1-mod1.tex}{\texttt{aligned1-mod1.tex}}{lst:aligned1-mod1} + \end{cmhtcbraster} + + We note in particular: + \begin{itemize} + \item \cref{lst:sba1} demonstrates the \emph{basic} form for + \texttt{lookForAlignDelims}; in this case, + the default values are specified as in \vref{lst:aligndelims:advanced}; + \item \cref{lst:sba2} demonstrates the \emph{advanced} form for + \texttt{lookForAlignDelims} + and specified \texttt{spacesBeforeAmpersand}. The default value is \texttt{1}; + \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}. + + We note that \texttt{leadingBlankColumn} has not been specified in \cref{lst:sba3}, + and it will inherit the value from \texttt{default}; + \item \cref{lst:sba4} demonstrates spaces to be used before amperands for + \emph{leading blank columns}. + We note that \emph{default} has not been specified, and it will be set to + \texttt{1} by default. + \end{itemize} + We can customise the space before the ampersand in the \emph{leading blank column} of + \cref{lst:aligned1-mod1} by using either of \cref{lst:sba5,lst:sba6}, which are equivalent. + + \begin{cmhtcbraster} + \cmhlistingsfromfile*{demonstrations/sba5.yaml}[yaml-TCB]{\texttt{sba5.yaml}}{lst:sba5} + \cmhlistingsfromfile*{demonstrations/sba6.yaml}[yaml-TCB]{\texttt{sba6.yaml}}{lst:sba6} + \end{cmhtcbraster} + + Upon running + \begin{commandshell} +latexindent.pl aligned1.tex -l sba5.yaml +latexindent.pl aligned1.tex -l sba6.yaml +\end{commandshell} + then we receive the (same) output given in \cref{lst:aligned1-mod5}. We note that the + space before the ampersand in the \emph{leading blank column} has been set to + \texttt{0} by \cref{lst:sba6}. + + We can demonstrated this feature further using the settings in \cref{lst:sba7} + which give the output in \cref{lst:aligned1-mod7}. + + \begin{cmhtcbraster}[raster columns=3, + raster left skip=-3.75cm, + raster right skip=-2cm,] + \cmhlistingsfromfile*{demonstrations/aligned1-mod5.tex}{\texttt{aligned1-mod5.tex}}{lst:aligned1-mod5} + \cmhlistingsfromfile*{demonstrations/aligned1-mod7.tex}{\texttt{aligned1.tex} using \cref{lst:sba7}}{lst:aligned1-mod7} + \cmhlistingsfromfile*{demonstrations/sba7.yaml}[yaml-TCB]{\texttt{sba7.yaml}}{lst:sba7} + \end{cmhtcbraster} +\subsubsection{lookForAlignDelims: alignFinalDoubleBackSlash} We explore% \announce{2020-03-21}{alignFinalDoubleBackSlash demonstration} the \texttt{alignFinalDoubleBackSlash} feature by using the file in \cref{lst:tabular4}. Upon @@ -479,7 +622,7 @@ latexindent.pl matrix1.tex (see \vref{sec:noadd-indent-rules}), these comment-marked blocks are considered \texttt{environments}. -\subsection{lookForAlignDelims: the dontMeasure feature}\label{sec:dontMeasure} +\subsubsection{lookForAlignDelims: the dontMeasure feature}\label{sec:dontMeasure} The% \announce{2020-03-21}{don't measure feature} \texttt{lookForAlignDelims} field can, optionally, receive the \texttt{dontMeasure} option which can be specified @@ -586,7 +729,7 @@ latexindent.pl tabular-DM.tex -l=dontMeasure6.yaml \cmhlistingsfromfile{demonstrations/dontMeasure6.yaml}[yaml-TCB]{\texttt{dontMeasure6.yaml}}{lst:dontMeasure6} \end{cmhtcbraster} -\subsection{lookForAlignDelims: the delimiterRegEx and delimiterJustification feature}\label{sec:delimiter-reg-ex} +\subsubsection{lookForAlignDelims: the delimiterRegEx and delimiterJustification feature}\label{sec:delimiter-reg-ex} The delimiter alignment% \announce{2020-03-21}{delimiterRegEx feature} will, by default, align code blocks at the ampersand character. The behaviour is controlled by the @@ -707,6 +850,7 @@ latexindent.pl tabbing1.tex -l=delimiterRegEx5.yaml -o=+-mod5 Note that in \cref{lst:tabbing1-mod5} the second set of delimiters have been \emph{right aligned} -- it is quite subtle! +\subsection{Indent after items, specials and headings} \yamltitle{indentAfterItems}*{fields} The environment names specified in \texttt{indentAfterItems} tell \texttt{latexindent.pl} to look for \lstinline!\item! commands; if these switches are set to @@ -906,10 +1050,15 @@ latexindent.pl special-align.tex -l edge-node2.yaml -o=+-mod2 \index{regular expressions!horizontal space \textbackslash{h}} \begin{cmhtcbraster}[ raster left skip=-3.5cm,] - \cmhlistingsfromfile{demonstrations/edge-node2.yaml}[yaml-TCB]{\texttt{edge-node2.yaml}}{lst:edge-node2} + \cmhlistingsfromfile*{demonstrations/edge-node2.yaml}[yaml-TCB]{\texttt{edge-node2.yaml}}{lst:edge-node2} \cmhlistingsfromfile{demonstrations/special-align-mod2.tex}{\texttt{special-align.tex} using \cref{lst:edge-node2}}{lst:special-align-mod2} \end{cmhtcbraster} + The \texttt{lookForThis} field can be considered + optional;% + \announce*{2021-06-19}*{lookForThis optional for specialBeginEnd} by default, it is + assumed to be 1, which is demonstrated in \cref{lst:edge-node2}. + \yamltitle{indentAfterHeadings}*{fields} This field enables the user to specify indentation rules that take effect after heading commands such as \lstinline!\part!, \lstinline!\chapter!, @@ -1065,19 +1214,19 @@ mand arg text \[ ... \] - \end{lstlisting} \\\cmidrule{2-3} + \end{lstlisting} \\\cmidrule{2-3} afterHeading & User specified, see \vref{lst:indentAfterHeadings} & \begin{lstlisting}[,morekeywords={chapter},nolol=true,] \chapter{title} ... \section{title} - \end{lstlisting} \\\cmidrule{2-3} + \end{lstlisting} \\\cmidrule{2-3} filecontents & User specified, see \vref{lst:fileContentsEnvironments} & \begin{lstlisting}[,nolol=true,] \begin{filecontents} ... \end{filecontents} - \end{lstlisting} \\ + \end{lstlisting} \\ \bottomrule \end{tabular} \end{widepage} diff --git a/Master/texmf-dist/doc/support/latexindent/sec-fine-tuning.tex b/Master/texmf-dist/doc/support/latexindent/sec-fine-tuning.tex index ccd04ffb47a..928b3a0909e 100644 --- a/Master/texmf-dist/doc/support/latexindent/sec-fine-tuning.tex +++ b/Master/texmf-dist/doc/support/latexindent/sec-fine-tuning.tex @@ -29,7 +29,7 @@ \end{warning} \begin{widepage} - \cmhlistingsfromfile[style=fineTuning]*{../defaultSettings.yaml}[width=0.95\linewidth,before=\centering,yaml-TCB]{\texttt{fineTuning}}{lst:fineTuning} + \cmhlistingsfromfile*[style=fineTuning]*{../defaultSettings.yaml}[width=.95\linewidth,before=\centering,yaml-TCB]{\texttt{fineTuning}}{lst:fineTuning} \end{widepage} The fields given in \cref{lst:fineTuning} are all \emph{regular expressions}. This manual @@ -171,6 +171,63 @@ latexindent.pl -m -y='modifyLineBreaks:oneSentencePerLine:manipulateSentences: 1 \end{commandshell} gives the output shown in \cref{lst:finetuning3-mod1}. - \cmhlistingsfromfile*{demonstrations/finetuning3.tex}{\texttt{finetuning3.tex}}{lst:finetuning3} - \cmhlistingsfromfile*{demonstrations/finetuning3-mod1.tex}{\texttt{finetuning3.tex} using -y switch}{lst:finetuning3-mod1} + \cmhlistingsfromfile{demonstrations/finetuning3.tex}{\texttt{finetuning3.tex}}{lst:finetuning3} + \cmhlistingsfromfile{demonstrations/finetuning3-mod1.tex}{\texttt{finetuning3.tex} using -y switch}{lst:finetuning3-mod1} + \end{example} + + \begin{example} + We can tweak the \texttt{fineTuning} for how trailing comments are classified. For motivation, let's consider + the code given in \cref{lst:finetuning4} + + \cmhlistingsfromfile*{demonstrations/finetuning4.tex}{\texttt{finetuning4.tex}}{lst:finetuning4} + + We will compare the settings given in \cref{lst:href1,lst:href2}. + + \begin{cmhtcbraster}[raster column skip=.01\linewidth, + raster left skip=0cm, + raster right skip=-0.5cm,] + \cmhlistingsfromfile*[style=yaml-LST]*{demonstrations/href1.yaml}[MLB-TCB]{\texttt{href1.yaml}}{lst:href1} + \cmhlistingsfromfile*[style=yaml-LST]*{demonstrations/href2.yaml}[MLB-TCB]{\texttt{href2.yaml}}{lst:href2} + \end{cmhtcbraster} + + Upon running the following commands + \begin{commandshell} +latexindent.pl -m finetuning4.tex -o=+-mod1 -l=href1 +latexindent.pl -m finetuning4.tex -o=+-mod2 -l=href2 +\end{commandshell} + we receive the respective output in \cref{lst:finetuning4-mod1,lst:finetuning4-mod2}. + + \begin{widepage} + \cmhlistingsfromfile*{demonstrations/finetuning4-mod1.tex}{\texttt{finetuning4.tex} using \cref{lst:href1}}{lst:finetuning4-mod1} + + \cmhlistingsfromfile*{demonstrations/finetuning4-mod2.tex}{\texttt{finetuning4.tex} using \cref{lst:href2}}{lst:finetuning4-mod2} + \end{widepage} + + We note that in: + \begin{itemize} + \item \cref{lst:finetuning4-mod1} the trailing comments are assumed to be everything following the + first comment symbol, which has meant that everything following it has been moved to the + end of the line; this is undesirable, clearly! + \item \cref{lst:finetuning4-mod2} has fine-tuned the trailing comment matching, and says that + \lstinline!%! cannot + be immediately preceeded by the words `Handbook', `for' or `Spoken', which means that + none of the \lstinline!%! symbols have been treated as trailing comments, and + the output is desirable. + \end{itemize} + + Another approach to this situation, which does not use \texttt{fineTuning}, is to use \texttt{noIndentBlock} + which we discussed in \vref{lst:noIndentBlock}; + using the settings in \cref{lst:href3} and running the command + \begin{commandshell} +latexindent.pl -m finetuning4.tex -o=+-mod3 -l=href3 +\end{commandshell} + then we receive the same output given in \cref{lst:finetuning4-mod2}; see also \texttt{paragraphsStopAt} + in \vref{lst:paragraphsStopAt}. + + \cmhlistingsfromfile*[style=yaml-LST]*{demonstrations/href3.yaml}[MLB-TCB]{\texttt{href3.yaml}}{lst:href3} + + With reference to the \texttt{body} field in \cref{lst:href3}, we note that \lstinline![^}]*?! can + be interpreted as: the fewest number of zero or more characters that are not right braces. This + is an example of character class. + \index{regular expressions!character class demonstration} \end{example} diff --git a/Master/texmf-dist/doc/support/latexindent/sec-how-to-use.tex b/Master/texmf-dist/doc/support/latexindent/sec-how-to-use.tex index 0760d467ef2..ba35a043280 100644 --- a/Master/texmf-dist/doc/support/latexindent/sec-how-to-use.tex +++ b/Master/texmf-dist/doc/support/latexindent/sec-how-to-use.tex @@ -206,7 +206,7 @@ latexindent.pl myfile.tex -l=first.yaml,second.yaml,third.yaml and if it is called with the \texttt{-l} switch and it finds \texttt{localSettings.yaml} in the same directory as \texttt{myfile.tex}, then, if not found, it looks for \texttt{localSettings.yaml} (and friends, see \vref{sec:localsettings}) in the current working directory, then these - \announce*{2021-03-14}*{-l switch: localSettings and friends} settings will be added to the indentation scheme. Information + \announce{2021-03-14}*{-l switch: localSettings and friends} settings will be added to the indentation scheme. Information will be given in \texttt{indent.log} on the success or failure of loading \texttt{localSettings.yaml}. @@ -317,7 +317,7 @@ latexindent.pl myfile.tex -g other.log if you wish to change the name of this file, simply call the script with your chosen name after the \texttt{-g} switch as demonstrated above. - \announce*{2021-05-07}{log file creation updated} If \texttt{latexindent.pl} can not open the log file that you + \announce{2021-05-07}{log file creation updated} If \texttt{latexindent.pl} can not open the log file that you specify, then the script will operate, and no log file will be produced; this might be helpful to users who wish to specify the following, for example \begin{commandshell} diff --git a/Master/texmf-dist/doc/support/latexindent/sec-indent-config-and-settings.tex b/Master/texmf-dist/doc/support/latexindent/sec-indent-config-and-settings.tex index 40216948a77..ddce5c806bf 100644 --- a/Master/texmf-dist/doc/support/latexindent/sec-indent-config-and-settings.tex +++ b/Master/texmf-dist/doc/support/latexindent/sec-indent-config-and-settings.tex @@ -81,11 +81,23 @@ lookForAlignDelims: will tell you so in \texttt{indent.log}. \end{warning} + If you find that% + \announce*{2021-06-19}{encoding option for indentconfig.yaml} + \texttt{latexindent.pl} does not read your YAML file, then it might be as a result of the + default commandline encoding not being UTF-8; normally this will only occcur for Windows + users. In this case, you might like to explore the \texttt{encoding} option for + \texttt{indentconfig.yaml} as demonstrated in \cref{lst:indentconfig-encoding}. + + \cmhlistingsfromfile*{demonstrations/encoding.yaml}[yaml-TCB]{The \texttt{encoding} option for \texttt{indentconfig.yaml}}{lst:indentconfig-encoding} + + Thank you to \cite{qiancy98} for this contribution; please see + \vref{app:encoding} and details within \cite{encoding} for further information. + \subsection{localSettings.yaml and friends}\label{sec:localsettings} The \texttt{-l} switch tells \texttt{latexindent.pl} to look for \texttt{localSettings.yaml} and/or friends in the \emph{same directory} as \texttt{myfile.tex}. For% - \announce*{2021-03-14}*{-l switch: localSettings and friends} + \announce{2021-03-14}*{-l switch: localSettings and friends} example, if you use the following command \index{switches!-l demonstration} \begin{commandshell} @@ -138,8 +150,8 @@ verbatimEnvironments: You% \announce{2017-08-21}{demonstration of the -y switch} may use the \texttt{-y} switch to load your settings; for example, if you wished to - specify the settings from \cref{lst:localSettings} using the \texttt{-y} switch, - then you could use the following command: + specify the settings from \cref{lst:localSettings} using the \texttt{-y} + switch, then you could use the following command: \index{verbatim!verbatimEnvironments demonstration (-y switch)} \begin{commandshell} latexindent.pl -y="verbatimEnvironments:cmhenvironment:0;myenv:1" myfile.tex diff --git a/Master/texmf-dist/doc/support/latexindent/sec-the-m-switch.tex b/Master/texmf-dist/doc/support/latexindent/sec-the-m-switch.tex index 13ee49d1b48..c77ed24ec41 100644 --- a/Master/texmf-dist/doc/support/latexindent/sec-the-m-switch.tex +++ b/Master/texmf-dist/doc/support/latexindent/sec-the-m-switch.tex @@ -1901,17 +1901,17 @@ latexindent.pl -m pmatrix3.tex -l DBS3.yaml \toprule Code block & Sample & \multicolumn{2}{c}{Poly-switch mapping} \\ \midrule - environment & \verb!before words!$\BeginStartsOnOwnLine$ & $\BeginStartsOnOwnLine$ & BeginStartsOnOwnLine \\ - & \verb!\begin{myenv}!$\BodyStartsOnOwnLine$ & $\BodyStartsOnOwnLine$ & BodyStartsOnOwnLine \\ - & \verb!body of myenv!$\EndStartsOnOwnLine$ & $\EndStartsOnOwnLine$ & EndStartsOnOwnLine \\ - & \verb!\end{myenv}!$\EndFinishesWithLineBreak$ & $\EndFinishesWithLineBreak$ & EndFinishesWithLineBreak \\ - & \verb!after words! & & \\ + environment & \verb!before words!$\BeginStartsOnOwnLine$ & $\BeginStartsOnOwnLine$ & BeginStartsOnOwnLine \\ + & \verb!\begin{myenv}!$\BodyStartsOnOwnLine$ & $\BodyStartsOnOwnLine$ & BodyStartsOnOwnLine \\ + & \verb!body of myenv!$\EndStartsOnOwnLine$ & $\EndStartsOnOwnLine$ & EndStartsOnOwnLine \\ + & \verb!\end{myenv}!$\EndFinishesWithLineBreak$ & $\EndFinishesWithLineBreak$ & EndFinishesWithLineBreak \\ + & \verb!after words! & & \\ \cmidrule{2-4} - ifelsefi & \verb!before words!$\BeginStartsOnOwnLine$ & $\BeginStartsOnOwnLine$ & IfStartsOnOwnLine \\ - & \verb!\if...!$\BodyStartsOnOwnLine$ & $\BodyStartsOnOwnLine$ & BodyStartsOnOwnLine \\ - & \verb!body of if/or statement!$\OrStartsOnOwnLine$ & $\OrStartsOnOwnLine$ & OrStartsOnOwnLine % + ifelsefi & \verb!before words!$\BeginStartsOnOwnLine$ & $\BeginStartsOnOwnLine$ & IfStartsOnOwnLine \\ + & \verb!\if...!$\BodyStartsOnOwnLine$ & $\BodyStartsOnOwnLine$ & BodyStartsOnOwnLine \\ + & \verb!body of if/or statement!$\OrStartsOnOwnLine$ & $\OrStartsOnOwnLine$ & OrStartsOnOwnLine % \announce{2018-04-27}{new ifElseFi code block poly-switches} \\ - & \verb!\or!$\OrFinishesWithLineBreak$ & $\OrFinishesWithLineBreak$ & OrFinishesWithLineBreak \\ + & \verb!\or!$\OrFinishesWithLineBreak$ & $\OrFinishesWithLineBreak$ & OrFinishesWithLineBreak \\ & \verb!body of if/or statement!$\ElseStartsOnOwnLine$ & $\ElseStartsOnOwnLine$ & ElseStartsOnOwnLine \\ & \verb!\else!$\ElseFinishesWithLineBreak$ & $\ElseFinishesWithLineBreak$ & ElseFinishesWithLineBreak \\ & \verb!body of else statement!$\EndStartsOnOwnLine$ & $\EndStartsOnOwnLine$ & FiStartsOnOwnLine \\ diff --git a/Master/texmf-dist/doc/support/latexindent/title.tex b/Master/texmf-dist/doc/support/latexindent/title.tex index 7545c5d4934..06bbb12c359 100644 --- a/Master/texmf-dist/doc/support/latexindent/title.tex +++ b/Master/texmf-dist/doc/support/latexindent/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.9.3 + \centering\ttfamily\bfseries latexindent.pl\\[1cm] Version 3.10 \end{tcolorbox} } \author{Chris Hughes \thanks{and contributors! See \vref{sec:contributors}. For all communication, please visit \cite{latexindent-home}.}} -\date{2021-05-07} +\date{2021-06-19} \maketitle \begin{adjustwidth}{1cm}{1cm} \small diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm index 993423ab2ea..45307a90b61 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm @@ -388,7 +388,12 @@ sub align_at_ampersand{ ){ ${$_}{row} = (${$_}{unformattedRow} ne "" ? ${$_}{unformattedRow}:q()).(${$_}{trailingComment}?${$_}{trailingComment}:q()); } - + + # spaces for leadingBlankColumn in operation + if(${$self}{leadingBlankColumn}>-1){ + $padding = " " x (${$self}{leadingBlankColumn}); + ${$_}{row} =~ s/^\h*/$padding/s; + } } # delete the original body @@ -738,6 +743,19 @@ sub individual_padding{ ${$cell}{delimiterLength} = $maxDelimiterWidth[$j]; } + # to keep leadingBlankColumn on, we need to check: + # + # - are we in the first column? + # - is leadingBlankColumn 0 or more? + # - cell width of first column equal 0? + # - are we measuring this cell? + # + # see test-cases/alignment/issue-275a.tex and the associated logfile + # + if ($j==0 and ${$self}{leadingBlankColumn}>-1 and ${$cell}{width} > 0 and ${$cell}{measureThis}==1){ + ${$self}{leadingBlankColumn} = -1; + } + # there are some cells that shouldn't be accounted for in measuring, # for example {ccc} next if !${$cell}{measureThis}; @@ -748,6 +766,7 @@ sub individual_padding{ max($maximumColumnWidths[$j],${$cell}{width}) : ${$cell}{width}); + } # update the maximum number of columns @@ -1288,14 +1307,14 @@ sub pretty_print_cell_info{ $logger->trace("*cell information: $thingToPrint"); - $logger->trace("minimum multi col span: ",join(",",@minMultiColSpan)) if(@minMultiColSpan); + $logger->trace("minimum multi col span: ".join(",",@minMultiColSpan)) if(@minMultiColSpan); foreach my $row (@cellStorage) { my $tmpLogFileLine = q(); foreach my $cell (@$row) { $tmpLogFileLine .= ${$cell}{$thingToPrint}."\t"; } - $logger->trace(' ', $tmpLogFileLine) if($is_t_switch_active); + $logger->trace(' '. $tmpLogFileLine) if($is_t_switch_active); } if($thingToPrint eq "type"){ diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/BlankLines.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/BlankLines.pm index abd1ed73a3c..2622e9ad905 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/BlankLines.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/BlankLines.pm @@ -27,18 +27,6 @@ sub protect_blank_lines{ return unless $is_m_switch_active; my $self = shift; - # the text wrap routine, under some circumstances, can - # cause new blank lines that haven't been awarded a token; see, for example, - # test-cases/maxLineChars/multi-object-all.tex -l=multi-object2.yaml -m - # we can circumvent this by forcing blank lines to be protected if - # the text wrap option is active, which allows us to remove blank - # lines from wrapped text - if(ref ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns} eq "HASH" - or ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}>0 ){ - ${$masterSettings{modifyLineBreaks}}{preserveBlankLines} = 1; - } - - unless(${$masterSettings{modifyLineBreaks}}{preserveBlankLines}){ $logger->trace("*Blank lines will not be protected (preserveBlankLines=0)") if $is_t_switch_active; return diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm index 863d4d7d009..b6e609edc07 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm @@ -21,8 +21,8 @@ use utf8; use open ':std', ':encoding(UTF-8)'; # gain access to subroutines in the following modules -use LatexIndent::Switches qw/storeSwitches %switches $is_m_switch_active $is_t_switch_active $is_tt_switch_active $is_r_switch_active $is_rr_switch_active $is_rv_switch_active/; -use LatexIndent::LogFile qw/processSwitches $logger/; +use LatexIndent::Switches qw/store_switches %switches $is_m_switch_active $is_t_switch_active $is_tt_switch_active $is_r_switch_active $is_rr_switch_active $is_rv_switch_active/; +use LatexIndent::LogFile qw/process_switches $logger/; use LatexIndent::Logger qw/@logFileLines/; use LatexIndent::Replacement qw/make_replacements/; use LatexIndent::GetYamlSettings qw/yaml_read_settings yaml_modify_line_breaks_settings yaml_get_indentation_settings_for_this_object yaml_poly_switch_get_every_or_custom_value yaml_get_indentation_information yaml_get_object_attribute_for_indentation_settings yaml_alignment_at_ampersand_settings yaml_get_textwrap_removeparagraphline_breaks %masterSettings yaml_get_columns/; @@ -74,8 +74,9 @@ sub new{ sub latexindent{ my $self = shift; - $self->storeSwitches; - $self->processSwitches; + $self->store_switches; + $self->process_switches; + $self->yaml_read_settings; $self->file_extension_check; $self->operate_on_file; } @@ -103,6 +104,7 @@ sub operate_on_file{ $self->dodge_double_backslash; $self->remove_leading_space; $self->process_body_of_text; + ${$self}{body} =~ s/\r\n/\n/sg if $masterSettings{dos2unixlinebreaks}; $self->remove_trailing_whitespace(when=>"after"); $self->condense_blank_lines; $self->unprotect_blank_lines; @@ -112,6 +114,7 @@ sub operate_on_file{ $self->put_trailing_comments_back_in; $self->put_verbatim_back_in (match=>"just-commands"); $self->make_replacements(when=>"after") if ($is_r_switch_active and !$is_rv_switch_active); + ${$self}{body} =~ s/\r\n/\n/sg if $masterSettings{dos2unixlinebreaks}; } $self->output_indented_text; return diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm index 5a367c784fc..26d8014f5a4 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm @@ -23,7 +23,6 @@ use LatexIndent::LogFile qw/$logger/; use LatexIndent::Braces qw/$braceBracketRegExpBasic/; use LatexIndent::Special qw/$specialBeginAndBracesBracketsBasicRegExp/; use LatexIndent::Heading qw/$allHeadingsRegexp/; -use Data::Dumper; use Exporter qw/import/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 our @EXPORT_OK = qw/check_for_else_statement/; diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm index c658acedf27..44388abbf33 100755 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm @@ -25,7 +25,6 @@ use LatexIndent::Braces qw/$braceBracketRegExpBasic/; use LatexIndent::IfElseFi qw/$ifElseFiBasicRegExp/; use LatexIndent::Heading qw/$allHeadingsRegexp/; use LatexIndent::Special qw/$specialBeginAndBracesBracketsBasicRegExp/; -use Data::Dumper; use Exporter qw/import/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 our @EXPORT_OK = qw/find_environments $environmentBasicRegExp construct_environments_regexp/; diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm index cbb20e51483..d870f16c417 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm @@ -42,80 +42,82 @@ sub find_file_contents_environments_and_preamble{ $logger->trace('*Searching for FILE CONTENTS environments (see fileContentsEnvironments)') if $is_t_switch_active; $logger->trace(Dumper(\%{$masterSettings{fileContentsEnvironments}})) if($is_tt_switch_active); while( my ($fileContentsEnv,$yesno)= each %{$masterSettings{fileContentsEnvironments}}){ - if($yesno){ - $logger->trace("looking for $fileContentsEnv environments") if $is_t_switch_active; - - # the trailing * needs some care - if($fileContentsEnv =~ m/\*$/){ - $fileContentsEnv =~ s/\*$//; - $fileContentsEnv .= '\*'; - } - - my $fileContentsRegExp = qr/ - ( - \\begin\{ - $fileContentsEnv - \} - ) - ( - .*? - ) - ( - \\end\{$fileContentsEnv\} - \h* - ) - (\R)? - /sx; - - while( ${$self}{body} =~ m/$fileContentsRegExp/sx){ - - # create a new Environment object - my $fileContentsBlock = LatexIndent::FileContents->new( begin=>$1, - body=>$2, - end=>$3, - name=>$fileContentsEnv, - linebreaksAtEnd=>{ - begin=>0, - body=>0, - end=>$4?1:0, - }, - modifyLineBreaksYamlName=>"filecontents", - ); - # give unique id - $fileContentsBlock->create_unique_id; - - # text wrapping can make the ID split across lines - ${$fileContentsBlock}{idRegExp} = ${$fileContentsBlock}{id}; - - if($is_m_switch_active){ - my $IDwithLineBreaks = join("\\R?\\h*",split(//,${$fileContentsBlock}{id})); - ${$fileContentsBlock}{idRegExp} = qr/$IDwithLineBreaks/s; - } - - # the replacement text can be just the ID, but the ID might have a line break at the end of it - $fileContentsBlock->get_replacement_text; - # count body line breaks - $fileContentsBlock->count_body_line_breaks; - - # the above regexp, when used below, will remove the trailing linebreak in ${$self}{linebreaksAtEnd}{end} - # so we compensate for it here - $fileContentsBlock->adjust_replacement_text_line_breaks_at_end; - - # store the fileContentsBlock, and determine location afterwards - push(@fileContentsStorageArray,$fileContentsBlock); + if(!$yesno){ + $logger->trace(" *not* looking for $fileContentsEnv as $fileContentsEnv:$yesno"); + next; + } - # log file output - $logger->trace("FILECONTENTS environment found: $fileContentsEnv"); + $logger->trace("looking for $fileContentsEnv environments") if $is_t_switch_active; - # remove the environment block, and replace with unique ID - ${$self}{body} =~ s/$fileContentsRegExp/${$fileContentsBlock}{replacementText}/sx; + # the trailing * needs some care + if($fileContentsEnv =~ m/\*$/){ + $fileContentsEnv =~ s/\*$//; + $fileContentsEnv .= '\*'; + } - $logger->trace("replaced with ID: ${$fileContentsBlock}{id}") if $is_tt_switch_active; - } - } else { - $logger->trace("*not* looking for $fileContentsEnv as $fileContentsEnv:$yesno"); - } + my $fileContentsRegExp = qr/ + ( + \\begin\{ + $fileContentsEnv + \} + ) + ( + .*? + ) + ( + \\end\{$fileContentsEnv\} + \h* + ) + (\R)? + /sx; + + while( ${$self}{body} =~ m/$fileContentsRegExp/sx){ + + # create a new Environment object + my $fileContentsBlock = LatexIndent::FileContents->new( begin=>$1, + body=>$2, + end=>$3, + name=>$fileContentsEnv, + linebreaksAtEnd=>{ + begin=>0, + body=>0, + end=>$4?1:0, + }, + modifyLineBreaksYamlName=>"filecontents", + ); + # give unique id + $fileContentsBlock->create_unique_id; + + # text wrapping can make the ID split across lines + ${$fileContentsBlock}{idRegExp} = ${$fileContentsBlock}{id}; + + if($is_m_switch_active){ + my $IDwithLineBreaks = join("\\R?\\h*",split(//,${$fileContentsBlock}{id})); + ${$fileContentsBlock}{idRegExp} = qr/$IDwithLineBreaks/s; + } + + # the replacement text can be just the ID, but the ID might have a line break at the end of it + $fileContentsBlock->get_replacement_text; + + # count body line breaks + $fileContentsBlock->count_body_line_breaks; + + # the above regexp, when used below, will remove the trailing linebreak in ${$self}{linebreaksAtEnd}{end} + # so we compensate for it here + $fileContentsBlock->adjust_replacement_text_line_breaks_at_end; + + # store the fileContentsBlock, and determine location afterwards + push(@fileContentsStorageArray,$fileContentsBlock); + + # log file output + $logger->trace("FILECONTENTS environment found: $fileContentsEnv")if $is_t_switch_active; + + # remove the environment block, and replace with unique ID + ${$self}{body} =~ s/$fileContentsRegExp/${$fileContentsBlock}{replacementText}/sx; + + $logger->trace("replaced with ID: ${$fileContentsBlock}{id}") if $is_tt_switch_active; + } } # determine if body of document contains \begin{document} -- if it does, then assume @@ -171,7 +173,7 @@ sub find_file_contents_environments_and_preamble{ $logger->trace("replaced with ID: ${$preamble}{replacementText}") if $is_tt_switch_active; # indentPreamble set to 1 if($masterSettings{indentPreamble}){ - $logger->trace("storing ${$preamble}{id} for indentation (see indentPreamble)"); + $logger->trace("storing ${$preamble}{id} for indentation (see indentPreamble)") if $is_tt_switch_active; $needToStorePreamble = 1; } else { # indentPreamble set to 0 @@ -188,18 +190,18 @@ sub find_file_contents_environments_and_preamble{ my $indentThisChild = 0; # verbatim children go in special hash if($preamble ne '' and ${$preamble}{body} =~ m/${$_}{id}/){ - $logger->trace("filecontents (${$_}{id}) is within preamble"); + $logger->trace("filecontents (${$_}{id}) is within preamble") if $is_t_switch_active; # indentPreamble set to 1 if($masterSettings{indentPreamble}){ - $logger->trace("storing ${$_}{id} for indentation (indentPreamble is 1)"); + $logger->trace("storing ${$_}{id} for indentation (indentPreamble is 1)") if $is_t_switch_active; $indentThisChild = 1; } else { # indentPreamble set to 0 - $logger->trace("Storing ${$_}{id} as a VERBATIM object (indentPreamble is 0)"); + $logger->trace("Storing ${$_}{id} as a VERBATIM object (indentPreamble is 0)") if $is_t_switch_active; ${$self}{verbatim}{${$_}{id}}=$_; } } else { - $logger->trace("storing ${$_}{id} for indentation (${$_}{name} found outside of preamble)"); + $logger->trace("storing ${$_}{id} for indentation (${$_}{name} found outside of preamble)") if $is_t_switch_active; $indentThisChild = 1; } # store the child, if necessary diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm index 4be1d3a97bf..f28fdd6525c 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm @@ -16,6 +16,7 @@ package LatexIndent::GetYamlSettings; # For all communication, please visit: https://github.com/cmhughes/latexindent.pl use strict; use warnings; +use Data::Dumper; use LatexIndent::Switches qw/%switches $is_m_switch_active $is_t_switch_active $is_tt_switch_active/; use YAML::Tiny; # interpret defaultSettings.yaml and other potential settings files use File::Basename; # to get the filename and directory path @@ -47,6 +48,7 @@ our @alignAtAmpersandInformation = ( {name=>"lookForAlignDelims",yamlname=>"de {name=>"dontMeasure",default=>0}, {name=>"delimiterRegEx",default=>"(?<!\\\\)(&)"}, {name=>"delimiterJustification",default=>"left"}, + {name=>"leadingBlankColumn",default=>-1}, ); sub yaml_read_settings{ @@ -56,7 +58,8 @@ sub yaml_read_settings{ $defaultSettings = YAML::Tiny->read( "$FindBin::RealBin/defaultSettings.yaml" ) if ( -e "$FindBin::RealBin/defaultSettings.yaml" ); # grab the logger object - $logger->info("*YAML settings read: defaultSettings.yaml\nReading defaultSettings.yaml from $FindBin::RealBin/defaultSettings.yaml"); + $logger->info("*YAML settings read: defaultSettings.yaml"); + $logger->info("Reading defaultSettings.yaml from $FindBin::RealBin/defaultSettings.yaml"); # if latexindent.exe is invoked from TeXLive, then defaultSettings.yaml won't be in # the same directory as it; we need to navigate to it @@ -71,6 +74,8 @@ sub yaml_read_settings{ # master yaml settings is a hash, global to this module our %masterSettings = %{$defaultSettings->[0]}; + &yaml_update_dumper_settings(); + # scalar to read user settings my $userSettings; @@ -107,7 +112,34 @@ sub yaml_read_settings{ # output the contents of indentconfig to the log file $logger->info(Dump \%{$userSettings->[0]}); - @absPaths = @{$userSettings->[0]->{paths}}; + # change the encoding of the paths according to the field `encoding` + if($userSettings and (ref($userSettings->[0]) eq 'HASH') and $userSettings->[0]->{encoding}){ + use Encode; + my $encoding = $userSettings->[0]->{encoding}; + my $encodingObject = find_encoding($encoding); + # Check if the encoding is valid. + if (ref($encodingObject)) + { + $logger->info("*Encoding of the paths is $encoding"); + foreach (@{$userSettings->[0]->{paths}}) + { + my $temp = $encodingObject->encode("$_"); + $logger->info("Transform file encoding: $_ -> $temp"); + push(@absPaths,$temp); + } + } + else + { + $logger->warn("*encoding \"$encoding\" not found"); + $logger->warn("Ignore this setting and will take the default encoding."); + @absPaths = @{$userSettings->[0]->{paths}}; + } + } + else # No such setting, and will take the default + { + # $logger->info("*Encoding of the paths takes the default."); + @absPaths = @{$userSettings->[0]->{paths}}; + } } else { $logger->warn("*The paths field cannot be read from $indentconfig; this means it is either empty or contains invalid YAML"); $logger->warn("See https://latexindentpl.readthedocs.io/en/latest/sec-indent-config-and-settings.html for an example"); @@ -240,14 +272,16 @@ sub yaml_read_settings{ if (ref $secondLevelValue eq "HASH"){ # if masterSettings already contains a *scalar* value in secondLevelKey # then we need to delete it (test-cases/headings-first.tex with indentRules1.yaml first demonstrated this) - if(ref $masterSettings{$firstLevelKey}{$secondLevelKey} ne "HASH"){ + if(defined $masterSettings{$firstLevelKey}{$secondLevelKey} + and ref $masterSettings{$firstLevelKey}{$secondLevelKey} ne "HASH"){ $logger->trace("*masterSettings{$firstLevelKey}{$secondLevelKey} currently contains a *scalar* value, but it needs to be updated with a hash (see $settings); deleting the scalar") if($is_t_switch_active); delete $masterSettings{$firstLevelKey}{$secondLevelKey} ; } while(my ($thirdLevelKey,$thirdLevelValue) = each %{$secondLevelValue}) { if (ref $thirdLevelValue eq "HASH"){ # similarly for third level - if (ref $masterSettings{$firstLevelKey}{$secondLevelKey}{$thirdLevelKey} ne "HASH"){ + if (defined $masterSettings{$firstLevelKey}{$secondLevelKey}{$thirdLevelKey} + and ref $masterSettings{$firstLevelKey}{$secondLevelKey}{$thirdLevelKey} ne "HASH"){ $logger->trace("*masterSettings{$firstLevelKey}{$secondLevelKey}{$thirdLevelKey} currently contains a *scalar* value, but it needs to be updated with a hash (see $settings); deleting the scalar") if($is_t_switch_active); delete $masterSettings{$firstLevelKey}{$secondLevelKey}{$thirdLevelKey} ; } @@ -328,6 +362,9 @@ sub yaml_read_settings{ $logger->info("specifies $settings but this file does not exist - unable to read settings from this file"); } } + + &yaml_update_dumper_settings(); + } # read settings from -y|--yaml switch @@ -519,7 +556,10 @@ sub yaml_read_settings{ $logger->info("Updating masterSettings with $parent: $child: $grandchild: $greatgrandchild: $value"); $masterSettings{$parent}{$child}{$grandchild}{$greatgrandchild} = $value; } + + &yaml_update_dumper_settings(); } + } # some users may wish to see showAmalgamatedSettings @@ -527,7 +567,7 @@ sub yaml_read_settings{ # from the default in various user files if($masterSettings{logFilePreferences}{showAmalgamatedSettings}){ $logger->info("Amalgamated/overall settings to be used:"); - $logger->info(Dump \%masterSettings); + $logger->info(Dumper(\%masterSettings)); } return; @@ -611,6 +651,8 @@ sub yaml_alignment_at_ampersand_settings{ # spacesBeforeDoubleBackSlash: 2 return unless ${$masterSettings{lookForAlignDelims}}{$name}; + $logger->trace("alignAtAmpersand settings for $name (see lookForAlignDelims)") if($is_t_switch_active); + if(ref ${$masterSettings{lookForAlignDelims}}{$name} eq "HASH"){ # specified as a hash, e.g # @@ -621,7 +663,57 @@ sub yaml_alignment_at_ampersand_settings{ # spacesBeforeDoubleBackSlash: 2 foreach (@alignAtAmpersandInformation){ my $yamlname = (defined ${$_}{yamlname} ? ${$_}{yamlname}: ${$_}{name}); - ${$self}{${$_}{name}} = (defined ${${$masterSettings{lookForAlignDelims}}{$name}}{$yamlname} ) ? ${${$masterSettings{lookForAlignDelims}}{$name}}{$yamlname} : ${$_}{default}; + + # each of the following cases need to be allowed: + # + # lookForAlignDelims: + # aligned: + # spacesBeforeAmpersand: + # default: 1 + # leadingBlankColumn: 0 + # + # lookForAlignDelims: + # aligned: + # spacesBeforeAmpersand: + # leadingBlankColumn: 0 + # + # lookForAlignDelims: + # aligned: + # spacesBeforeAmpersand: + # default: 0 + # + # approach: + # - update masterSettings to have the relevant information: leadingBlankColumn and/or default + # - delete the spacesBeforeAmpersand hash + # + if ($yamlname eq "spacesBeforeAmpersand" + and ref(${${$masterSettings{lookForAlignDelims}}{$name}}{spacesBeforeAmpersand}) eq "HASH"){ + $logger->trace("spacesBeforeAmpersand settings for $name") if $is_t_switch_active; + + # lookForAlignDelims: + # aligned: + # spacesBeforeAmpersand: + # leadingBlankColumn: 0 + if(defined ${${${$masterSettings{lookForAlignDelims}}{$name}}{spacesBeforeAmpersand}}{leadingBlankColumn}){ + $logger->trace("spacesBeforeAmpersand: leadingBlankColumn specified for $name") if $is_t_switch_active; + ${${$masterSettings{lookForAlignDelims}}{$name}}{leadingBlankColumn} + = ${${${$masterSettings{lookForAlignDelims}}{$name}}{spacesBeforeAmpersand}}{leadingBlankColumn}; + } + + # lookForAlignDelims: + # aligned: + # spacesBeforeAmpersand: + # default: 0 + if(defined ${${${$masterSettings{lookForAlignDelims}}{$name}}{spacesBeforeAmpersand}}{default}){ + ${${$masterSettings{lookForAlignDelims}}{$name}}{spacesBeforeAmpersand} + = ${${${$masterSettings{lookForAlignDelims}}{$name}}{spacesBeforeAmpersand}}{default}; + } else { + # deleting spacesBeforeAmpersand hash allows spacesBeforeAmpersand + # to pull from the default values @alignAtAmpersandInformation + delete ${${$masterSettings{lookForAlignDelims}}{$name}}{spacesBeforeAmpersand}; + } + } + ${$self}{ ${$_}{name} } = (defined ${${$masterSettings{lookForAlignDelims}}{$name}}{$yamlname} ) ? ${${$masterSettings{lookForAlignDelims}}{$name}}{$yamlname} : ${$_}{default}; } } else { # specified as a scalar, e.g @@ -991,4 +1083,16 @@ sub yaml_get_object_attribute_for_indentation_settings{ return "body"; } +sub yaml_update_dumper_settings{ + + # log file preferences + $Data::Dumper::Terse = ${$masterSettings{logFilePreferences}{Dumper}}{Terse}; + $Data::Dumper::Indent = ${$masterSettings{logFilePreferences}{Dumper}}{Indent}; + $Data::Dumper::Useqq = ${$masterSettings{logFilePreferences}{Dumper}}{Useqq}; + $Data::Dumper::Deparse = ${$masterSettings{logFilePreferences}{Dumper}}{Deparse}; + $Data::Dumper::Quotekeys = ${$masterSettings{logFilePreferences}{Dumper}}{Quotekeys}; + $Data::Dumper::Sortkeys = ${$masterSettings{logFilePreferences}{Dumper}}{Sortkeys}; + $Data::Dumper::Pair = ${$masterSettings{logFilePreferences}{Dumper}}{Pair}; + +} 1; diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Heading.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Heading.pm index 208dfa9715e..0c42f166a62 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Heading.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Heading.pm @@ -22,7 +22,6 @@ use LatexIndent::TrailingComments qw/$trailingCommentRegExp/; use LatexIndent::GetYamlSettings qw/%masterSettings/; use LatexIndent::LogFile qw/$logger/; use LatexIndent::Special qw/$specialBeginBasicRegExp/; -use Data::Dumper; use Exporter qw/import/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 our @EXPORT_OK = qw/find_heading construct_headings_levels $allHeadingsRegexp/; diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm index e7e363b04c6..4cbab6efea9 100755 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm @@ -22,7 +22,6 @@ use LatexIndent::TrailingComments qw/$trailingCommentRegExp/; use LatexIndent::Switches qw/$is_m_switch_active $is_t_switch_active $is_tt_switch_active/; use LatexIndent::LogFile qw/$logger/; use LatexIndent::Heading qw/$allHeadingsRegexp/; -use Data::Dumper; use Exporter qw/import/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 our @EXPORT_OK = qw/find_ifelsefi construct_ifelsefi_regexp $ifElseFiBasicRegExp/; diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/KeyEqualsValuesBraces.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/KeyEqualsValuesBraces.pm index 590d9acb8c5..6eb4f703dd6 100755 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/KeyEqualsValuesBraces.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/KeyEqualsValuesBraces.pm @@ -21,7 +21,6 @@ use LatexIndent::GetYamlSettings qw/%masterSettings/; use LatexIndent::TrailingComments qw/$trailingCommentRegExp/; use LatexIndent::Switches qw/$is_m_switch_active $is_t_switch_active $is_tt_switch_active/; use LatexIndent::LogFile qw/$logger/; -use Data::Dumper; use Exporter qw/import/; our @ISA = "LatexIndent::Command"; # class inheritance, Programming Perl, pg 321 our @EXPORT_OK = qw/construct_key_equals_values_regexp $key_equals_values_bracesRegExp $key_equals_values_bracesRegExpTrailingComment/; diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm index ca8376daa9a..5b44822829d 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm @@ -21,10 +21,10 @@ use File::Basename; # to get the filename and directory path use Exporter qw/import/; use LatexIndent::Switches qw/%switches/; use LatexIndent::Version qw/$versionNumber $versionDate/; -our @EXPORT_OK = qw/processSwitches $logger/; +our @EXPORT_OK = qw/process_switches $logger/; our $logger; -sub processSwitches{ +sub process_switches{ # -v switch is just to show the version number if($switches{version}) { print $versionNumber,", ",$versionDate,"\n"; @@ -152,14 +152,11 @@ ENDQUOTE (my $file = $moduleName) =~ s|::|/|g; $logger->info($INC{$file .'.pm'}); } - $logger->info("*Latex Indent perl modules are being loaded from, for example:"); + $logger->info("*LatexIndent perl modules are being loaded from, for example:"); (my $file = 'LatexIndent::Document') =~ s|::|/|g; $logger->info($INC{$file .'.pm'}); } - # read the YAML settings - $self->yaml_read_settings; - return; } diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Replacement.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Replacement.pm index 1bc51caed2d..0d79a39f0c6 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Replacement.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Replacement.pm @@ -21,7 +21,6 @@ use LatexIndent::TrailingComments qw/$trailingCommentRegExp/; use LatexIndent::GetYamlSettings qw/%masterSettings/; use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active $is_rr_switch_active/; use LatexIndent::LogFile qw/$logger/; -use Data::Dumper; use Exporter qw/import/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 our @EXPORT_OK = qw/make_replacements/; diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm index 8898697d0f3..4e1a8020b34 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm @@ -36,9 +36,17 @@ our $specialBeginBasicRegExp; sub construct_special_begin{ my $self = shift; + $logger->trace("*Constructing specialBeginEnd regex (see specialBeginEnd)") if $is_t_switch_active; + # put together a list of the begin terms in special while( my ($specialName,$BeginEnd)= each %{$masterSettings{specialBeginEnd}}){ if(ref($BeginEnd) eq "HASH"){ + if (not defined ${$BeginEnd}{lookForThis}){ + ${$BeginEnd}{lookForThis} = 1; + ${${$masterSettings{specialBeginEnd}}{$specialName}}{lookForThis} = 1; + $logger->trace("setting lookForThis:1 for $specialName (lookForThis not specified)") if $is_t_switch_active; + } + # only append the regexps if lookForThis is 1 $specialBegins .= ($specialBegins eq ""?q():"|").${$BeginEnd}{begin} if(${$BeginEnd}{lookForThis}=~m/\d/s and ${$BeginEnd}{lookForThis} == 1); } @@ -48,45 +56,49 @@ sub construct_special_begin{ while( my ($specialName,$BeginEnd)= each %{$masterSettings{specialBeginEnd}}){ # only append the regexps if lookForThis is 1 - if( (ref($BeginEnd) eq "HASH") and ${$BeginEnd}{lookForThis}=~m/\d/s and ${$BeginEnd}{lookForThis} == 1){ + if( ref($BeginEnd) eq "HASH" ){ + if ( ${$BeginEnd}{lookForThis}=~m/\d/s and ${$BeginEnd}{lookForThis} == 0 ){ + $logger->trace("The specialBeginEnd regexps won't include anything from $specialName (lookForThis: 0)") if $is_t_switch_active ; + next; + } + } else { + next; + } - # the overall regexp - $specialAllMatchesRegExp .= ($specialAllMatchesRegExp eq ""?q():"|") - .qr/ + # the overall regexp + $specialAllMatchesRegExp .= ($specialAllMatchesRegExp eq ""?q():"|") + .qr/ + ${$BeginEnd}{begin} + (?: # cluster-only (), don't capture + (?! + (?:$specialBegins) # cluster-only (), don't capture + ). # any character, but not anything in $specialBegins + )*? + ${$BeginEnd}{end} + /sx; + + # store the individual special regexp + $individualSpecialRegExps{$specialName} = qr/ + ( ${$BeginEnd}{begin} + \h* + (\R*)? + ) + ( (?: # cluster-only (), don't capture (?! (?:$specialBegins) # cluster-only (), don't capture ). # any character, but not anything in $specialBegins )*? - ${$BeginEnd}{end} - /sx; - - # store the individual special regexp - $individualSpecialRegExps{$specialName} = qr/ - ( - ${$BeginEnd}{begin} - \h* - (\R*)? - ) - ( - (?: # cluster-only (), don't capture - (?! - (?:$specialBegins) # cluster-only (), don't capture - ). # any character, but not anything in $specialBegins - )*? - (\R*)? - ) - ( - ${$BeginEnd}{end} - ) - (\h*) - (\R)? - /sx - - } else { - $logger->trace("*The special regexps won't include anything from $specialName (see lookForThis)") if $is_t_switch_active ; - } + (\R*)? + ) + ( + ${$BeginEnd}{end} + ) + (\h*) + (\R)? + /sx + } # move $$ to the beginning @@ -176,7 +188,7 @@ sub find_special{ ${@{${$self}{children}}[-1]}{replacementText}.($8?$8:q()).($9?$9:q()); /xseg; - $self->wrap_up_tasks; + $self->wrap_up_tasks; } } } diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Switches.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Switches.pm index d738a4b36b6..e5e93b1de0c 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Switches.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Switches.pm @@ -17,7 +17,7 @@ package LatexIndent::Switches; use strict; use warnings; use Exporter qw/import/; -our @EXPORT_OK = qw/%switches storeSwitches $is_m_switch_active $is_t_switch_active $is_tt_switch_active $is_r_switch_active $is_rr_switch_active $is_rv_switch_active/; +our @EXPORT_OK = qw/%switches store_switches $is_m_switch_active $is_t_switch_active $is_tt_switch_active $is_r_switch_active $is_rr_switch_active $is_rv_switch_active/; our %switches; our $is_m_switch_active; our $is_t_switch_active; @@ -26,7 +26,7 @@ our $is_r_switch_active; our $is_rr_switch_active; our $is_rv_switch_active; -sub storeSwitches{ +sub store_switches{ my $self = shift; # copy document switches into hash local to this module diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/TrailingComments.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/TrailingComments.pm index 6ec052a0f3b..262201e76a0 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/TrailingComments.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/TrailingComments.pm @@ -28,7 +28,9 @@ our $commentCounter = 0; our $trailingCommentRegExp; sub construct_trailing_comment_regexp{ - $trailingCommentRegExp = qr/(?<!\\)%$tokens{trailingComment}\d+$tokens{endOfToken}/; + my $notPreceededBy = qr/${${$masterSettings{fineTuning}}{trailingComments}}{notPreceededBy}/; + + $trailingCommentRegExp = qr/$notPreceededBy%$tokens{trailingComment}\d+$tokens{endOfToken}/; } sub add_comment_symbol{ @@ -54,9 +56,11 @@ sub remove_trailing_comments{ my $self = shift; $logger->trace("*Storing trailing comments")if $is_t_switch_active; + my $notPreceededBy = qr/${${$masterSettings{fineTuning}}{trailingComments}}{notPreceededBy}/; + # perform the substitution ${$self}{body} =~ s/ - (?<!\\) # not preceeded by a \ + $notPreceededBy # not preceeded by a \ % # % ( \h*? # followed by possible horizontal space @@ -110,13 +114,14 @@ sub put_trailing_comments_back_in{ # replace the line-broken trailing comment ID with a non-broken trailing comment ID ${$self}{body} =~ s/%\R?$trailingcommentIDwithLineBreaksRegExp/%$trailingcommentID/s; } + my $notPreceededBy = qr/${${$masterSettings{fineTuning}}{trailingComments}}{notPreceededBy}/; if(${$self}{body} =~ m/%$trailingcommentID ( - (?! # not immediately preceeded by - (?<!\\) # \ - % # % + (?! # not immediately preceeded by + $notPreceededBy # \ + % # % ).*? - ) # captured into $1 + ) # captured into $1 (\h*)?$ /mx and $1 ne ''){ $logger->trace("Comment not at end of line $trailingcommentID, moving it to end of line")if $is_t_switch_active; diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm index 6149ca52361..1657f415212 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm @@ -30,64 +30,100 @@ sub find_noindent_block{ my $self = shift; # noindent block - $logger->trace('*Searching for NOINDENTBLOCk environments (see noIndentBlock)') if $is_t_switch_active; + $logger->trace('*Searching for NOINDENTBLOCk (see noIndentBlock)') if $is_t_switch_active; $logger->trace(Dumper(\%{$masterSettings{noIndentBlock}})) if($is_tt_switch_active); while( my ($noIndentBlock,$yesno)= each %{$masterSettings{noIndentBlock}}){ - if($yesno){ - $logger->trace("looking for $noIndentBlock:$yesno environments") if $is_t_switch_active; + + # integrity check on the field for noIndentBlock + if ( ref($yesno) eq "HASH" ){ + if (not defined ${$yesno}{begin}){ + $logger->trace(" *not* looking for $noIndentBlock as $noIndentBlock:begin not specified") if $is_t_switch_active; + next; + } elsif (not defined ${$yesno}{end}) { + $logger->trace(" *not* looking for $noIndentBlock as $noIndentBlock:end not specified") if $is_t_switch_active; + next; + } elsif (defined ${$yesno}{lookForThis} and !${$yesno}{lookForThis}){ + $logger->trace(" *not* looking for $noIndentBlock as lookForThis: 0") if $is_t_switch_active; + next; + } + } elsif( ref($yesno) ne "HASH" and !$yesno ){ + $logger->trace(" *not* looking for $noIndentBlock as $noIndentBlock:$yesno") if $is_t_switch_active; + next; + } + + # if we've made it this far, then we're good to go + my $noIndentRegExp; + + if (ref($yesno) eq "HASH"){ + # default value of body + if (not defined ${$yesno}{body}){ + $logger->trace("looking for regex based $noIndentBlock, begin: ${$yesno}{begin}, end: ${$yesno}{end}") if $is_t_switch_active; + $logger->trace("body not specified for $noIndentBlock, setting default .*?") if $is_t_switch_active; + ${$yesno}{body} = qr/.*?/sx; + } else { + $logger->trace("looking for regex based $noIndentBlock") if $is_t_switch_active; + $logger->trace("begin: ${$yesno}{begin}") if $is_t_switch_active; + $logger->trace("body: ${$yesno}{body}") if $is_t_switch_active; + $logger->trace("end: ${$yesno}{end}") if $is_t_switch_active; + } + + $noIndentRegExp = qr/ + (${$yesno}{begin}) + (${$yesno}{body}) + (${$yesno}{end}) + /sx; + } else { + $logger->trace("looking for $noIndentBlock:$yesno noIndentBlock") if $is_t_switch_active; (my $noIndentBlockSpec = $noIndentBlock) =~ s/\*/\\*/sg; - my $noIndentRegExp = qr/ + $noIndentRegExp = qr/ ( (?!<\\) % (?:\h|(?!<\\)%)* # possible horizontal spaces \\begin\{ - $noIndentBlockSpec # environment name captured into $2 + $noIndentBlockSpec \} # % \begin{noindentblock} statement - ) + ) # begin captured into $1 ( .*? - ) # non-greedy match (body) + ) # non-greedy match (body) into $2 ( (?!<\\) % # % (?:\h|(?!<\\)%)* # possible horizontal spaces \\end\{$noIndentBlockSpec\} # \end{noindentblock} - ) # % \end{<something>} statement + ) # % \end{<something>} statement into $3 /sx; - - while( ${$self}{body} =~ m/$noIndentRegExp/sx){ - - # create a new Verbatim object - my $noIndentBlockObj = LatexIndent::Verbatim->new( begin=>$1, - body=>$2, - end=>$3, - name=>$noIndentBlock, - type=>"noindentblock", - modifyLineBreaksYamlName=>"verbatim", - ); - - # give unique id - $noIndentBlockObj->create_unique_id; - - # verbatim children go in special hash - ${$self}{verbatim}{${$noIndentBlockObj}{id}}=$noIndentBlockObj; - - # log file output - $logger->trace("*NOINDENTBLOCK environment found: $noIndentBlock") if $is_t_switch_active; - - # remove the environment block, and replace with unique ID - ${$self}{body} =~ s/$noIndentRegExp/${$noIndentBlockObj}{id}/sx; - - $logger->trace("replaced with ID: ${$noIndentBlockObj}{id}") if $is_t_switch_active; - - # possible decoration in log file - $logger->trace(${$masterSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}) if ${$masterSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}; - } - } else { - $logger->trace("*not* looking for $noIndentBlock as $noIndentBlock:$yesno") if $is_t_switch_active; - } + } + while( ${$self}{body} =~ m/$noIndentRegExp/sx){ + + # create a new Verbatim object + my $noIndentBlockObj = LatexIndent::Verbatim->new( begin=>$1, + body=>$2, + end=>$3, + name=>$noIndentBlock, + type=>"noindentblock", + modifyLineBreaksYamlName=>"verbatim", + ); + + # give unique id + $noIndentBlockObj->create_unique_id; + + # verbatim children go in special hash + ${$self}{verbatim}{${$noIndentBlockObj}{id}}=$noIndentBlockObj; + + # log file output + $logger->trace("NOINDENTBLOCK found: $noIndentBlock") if $is_t_switch_active; + + # remove the environment block, and replace with unique ID + ${$self}{body} =~ s/$noIndentRegExp/${$noIndentBlockObj}{id}/sx; + + $logger->trace("replaced with ID: ${$noIndentBlockObj}{id}") if $is_t_switch_active; + + # possible decoration in log file + $logger->trace(${$masterSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}) if ${$masterSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}; + } } return; } diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm index 20cbab26721..eb1b1226dce 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.9.3'; -our $versionDate = '2021-05-07'; +our $versionNumber = '3.10'; +our $versionDate = '2021-06-19'; 1 diff --git a/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml b/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml index 2a927de5354..1d4c3704840 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.9.3, 2021-05-07 +# defaultSettings.yaml for latexindent.pl, version 3.10, 2021-06-19 # a script that aims to # beautify .tex, .sty, .cls files # @@ -89,6 +89,14 @@ logFilePreferences: showDecorationFinishCodeBlockTrace: 0 endLogFileWith: '--------------' showGitHubInfoFooter: 1 + Dumper: + Terse: 1 + Indent: 1 + Useqq: 1 + Deparse: 1 + Quotekeys: 0 + Sortkeys: 1 + Pair: " => " # verbatim environments specified # in this field will not be changed at all! @@ -109,11 +117,6 @@ noIndentBlock: noindent: 1 cmhtest: 1 -# remove trailing whitespace from all lines -removeTrailingWhitespace: - beforeProcessing: 0 - afterProcessing: 1 - # \begin{document} and \end{document} are treated differently # by latexindent within filecontents environments fileContentsEnvironments: @@ -140,6 +143,11 @@ preambleCommandsBeforeEnvironments: 0 # default value of indentation defaultIndent: "\t" +# remove trailing whitespace from all lines +removeTrailingWhitespace: + beforeProcessing: 0 + afterProcessing: 1 + # name of code blocks that should have their body aligned at ampersand delimiters lookForAlignDelims: tabular: @@ -359,6 +367,9 @@ commandCodeBlocks: amalgamate: 1 - '@ifnextchar\[' +# change dos line breaks into unix +dos2unixlinebreaks: 0 + # modifyLineBreaks will only be searched if the -m # switch is active # @@ -498,6 +509,7 @@ modifyLineBreaks: other: 0 textWrapOptions: columns: 0 + # huge: overflow # forbid mid-word line breaks separator: "" perCodeBlockBasis: 0 all: 0 @@ -628,6 +640,8 @@ fineTuning: arguments: before: '(?:#\d\h*;?,?\/?)+|\<.*?\>' between: '_|\^|\*' + trailingComments: + notPreceededBy: '(?<!\\)' modifyLineBreaks: betterFullStop: '(?:\.\)(?!\h*[a-z]))|(?:(?<!(?:(?:e\.g)|(?:i\.e)|(?:etc))))\.(?!(?:[a-z]|[A-Z]|\-|~|\,|[0-9]))' doubleBackSlash: '\\\\(?:\h*\[\h*\d+\h*[a-zA-Z]+\h*\])?' diff --git a/Master/texmf-dist/scripts/latexindent/latexindent.pl b/Master/texmf-dist/scripts/latexindent/latexindent.pl index ef24db27b25..838b15f9dd8 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.9.3, 2021-05-07 +# latexindent.pl, version 3.10, 2021-06-19 # # 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 |