diff options
Diffstat (limited to 'Master/texmf-dist')
13 files changed, 371 insertions, 148 deletions
diff --git a/Master/texmf-dist/doc/support/latexindent/README b/Master/texmf-dist/doc/support/latexindent/README index f3a55f4978e..a55d4c72804 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.1, 2017-05-27 + latexindent.pl, version 3.2, 2017-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/latexindent.pdf b/Master/texmf-dist/doc/support/latexindent/latexindent.pdf Binary files differindex 3bf881f5e4c..1df40469213 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 7ef945c18ac..8dffa3fa4e6 100644 --- a/Master/texmf-dist/doc/support/latexindent/latexindent.tex +++ b/Master/texmf-dist/doc/support/latexindent/latexindent.tex @@ -135,12 +135,14 @@ listing options={#1}, } -\DeclareTCBInputListing[use counter=lstlisting]{\cmhlistingsfromfile}{O{} m O{} m m}{% +% \cmhlistingsfromfile uses listings library +% \cmhlistingsfromfile* uses minted library +\DeclareTCBInputListing[use counter=lstlisting]{\cmhlistingsfromfile}{s O{} m O{} m m}{% cmhlistings, - listing file={#2}, - listing options={#1}, - title={\color{black}{\scshape Listing \thetcbcounter}: ~#4},label={#5}, - #3, + listing file={#3}, + IfBooleanTF={#1}{minted options={obeytabs=true,showtabs=true,tabsize=4,showspaces=false,#2}}{listing options={#2}}, + title={\color{black}{\scshape Listing \thetcbcounter}: ~#5},label={#6}, + #4, } % command shell @@ -209,112 +211,134 @@ \lstdefinestyle{logFilePreferences}{ style=yaml-LST, - firstnumber=79,linerange={79-83},numbers=left + firstnumber=79,linerange={79-83}, + numbers=left, } \lstdefinestyle{verbatimEnvironments}{ style=yaml-LST, - firstnumber=87,linerange={87-90},numbers=left + firstnumber=87,linerange={87-90}, + numbers=left, } \lstdefinestyle{verbatimCommands}{ style=yaml-LST, - firstnumber=93,linerange={93-95},numbers=left + firstnumber=93,linerange={93-95}, + numbers=left, } \lstdefinestyle{noIndentBlock}{ style=yaml-LST, - firstnumber=101,linerange={101-103},numbers=left + firstnumber=101,linerange={101-103}, + numbers=left, } \lstdefinestyle{removeTrailingWhitespace}{ style=yaml-LST, - firstnumber=106,linerange={106-108},numbers=left + firstnumber=106,linerange={106-108}, + numbers=left, } \lstdefinestyle{fileContentsEnvironments}{ style=yaml-LST, - firstnumber=112,linerange={112-114},numbers=left + firstnumber=112,linerange={112-114}, + numbers=left, } \lstdefinestyle{lookForPreamble}{ style=yaml-LST, - firstnumber=120,linerange={120-124},numbers=left + firstnumber=120,linerange={120-124}, + numbers=left, } \lstdefinestyle{indentAfterItems}{ style=yaml-LST, - firstnumber=172,linerange={172-176},numbers=left + firstnumber=174,linerange={174-178}, + numbers=left, } \lstdefinestyle{itemNames}{ style=yaml-LST, - firstnumber=182,linerange={182-184},numbers=left + firstnumber=184,linerange={184-186}, + numbers=left, } \lstdefinestyle{specialBeginEnd}{ style=yaml-LST, - firstnumber=188,linerange={188-200},numbers=left + firstnumber=190,linerange={190-202}, + numbers=left, } \lstdefinestyle{indentAfterHeadings}{ style=yaml-LST, - firstnumber=210,linerange={210-219},numbers=left + firstnumber=212,linerange={212-221}, + numbers=left, } \lstdefinestyle{noAdditionalIndentGlobalEnv}{ style=yaml-LST, - firstnumber=265,linerange={265-266},numbers=left + firstnumber=267,linerange={267-268}, + numbers=left, } \lstdefinestyle{noAdditionalIndentGlobal}{ style=yaml-LST, - firstnumber=265,linerange={265-277},numbers=left + firstnumber=267,linerange={267-279}, + numbers=left, } \lstdefinestyle{indentRulesGlobalEnv}{ style=yaml-LST, - firstnumber=281,linerange={281-282},numbers=left + firstnumber=283,linerange={283-284}, + numbers=left, } \lstdefinestyle{indentRulesGlobal}{ style=yaml-LST, - firstnumber=281,linerange={281-293},numbers=left + firstnumber=283,linerange={283-295}, + numbers=left, } \lstdefinestyle{commandCodeBlocks}{ style=yaml-LST, - firstnumber=296,linerange={296-304},numbers=left + firstnumber=298,linerange={298-306}, + numbers=left, } \lstdefinestyle{modifylinebreaks}{ style=yaml-LST, - firstnumber=374,linerange={374-376},numbers=left + firstnumber=376,linerange={376-378}, + numbers=left, } \lstdefinestyle{textWrapOptions}{ style=yaml-LST, - firstnumber=377,linerange={377-378},numbers=left + firstnumber=379,linerange={379-380}, + numbers=left, } \lstdefinestyle{textWrapOptionsAll}{ style=yaml-LST, - firstnumber=377,linerange={377-379},numbers=left + firstnumber=379,linerange={379-381}, + numbers=left, } \lstdefinestyle{removeParagraphLineBreaks}{ style=yaml-LST, - firstnumber=380,linerange={380-392},numbers=left + firstnumber=382,linerange={382-394}, + numbers=left, } \lstdefinestyle{paragraphsStopAt}{ style=yaml-LST, - firstnumber=393,linerange={393-401},numbers=left + firstnumber=395,linerange={395-403}, + numbers=left, } \lstdefinestyle{modifylinebreaksEnv}{ style=yaml-LST, - firstnumber=402,linerange={402-411},numbers=left + firstnumber=404,linerange={404-413}, + numbers=left, } % stars around contributors @@ -515,7 +539,7 @@ 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.1 + \centering\ttfamily\bfseries latexindent.pl\\[1cm] Version 3.2 \end{tcolorbox} } \author{Chris Hughes \thanks{and contributors! See \vref{sec:contributors}. For @@ -552,7 +576,6 @@ \input{subsubsec-no-add-remaining-code-blocks} \stopcontents[noAdditionalIndent] \input{subsec-commands-and-their-options} -\clearpage \input{sec-the-m-switch} \input{subsec-partnering-poly-switches} \input{subsec-conflicting-poly-switches} @@ -560,17 +583,3 @@ \input{references} \input{appendices} \end{document} - -\subsection{The phases of \texttt{latexindent.pl}} - With these rules in mind, let's study a few test cases: - - latexindent.pl environments-line-break-conflict.tex -s -t -m -o environments-line-break-conflict-mod1.tex -l=env-conflicts-mod1.yaml - latexindent.pl environments-line-break-conflict-nested.tex -s -t -m -o environments-line-break-conflict-nested-mod-2.tex -l=env-conflicts-mod2.yaml - latexindent.pl environments-line-break-conflict-nested.tex -s -t -m -o environments-line-break-conflict-nested-mod-3.tex -l=env-conflicts-mod3.yaml - environments-first-opt-args.tex, see all of the different examples in test-cases.sh - environments-second-opt-args.tex provides some interesting cases too - - The \lstinline!\fi! command knows to insert a space, so as to give, for example, \lstinline!\fi! text, and avoid things such as \lstinline!\fitext! - - from yaml - 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 f8bf01b60fb..ff99480cc80 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 @@ -235,7 +235,8 @@ lookForAlignDelims: \cmhlistingsfromfile[style=yaml-LST]{demonstrations/tabular.yaml}[yaml-TCB]{\texttt{tabular.yaml}}{lst:aligndelims:advanced} Note that you can use a mixture of the basic and advanced form: in \cref{lst:aligndelims:advanced} \texttt{tabular} and \texttt{tabularx} - are advanced and \texttt{longtable} is basic. When using the advanced form, each field should receive at least 1 sub-field, and \emph{can} (but does not have to) receive up to 3 fields: + are advanced and \texttt{longtable} is basic. When using the advanced form, each field should receive at least 1 sub-field, and \emph{can} + (but does not have to) receive any of the following fields: \begin{itemize} \item \texttt{delims}: switch equivalent to simply specifying, for example, \texttt{tabular: 1} in the basic version shown in \cref{lst:aligndelims:basic} (default: 1); @@ -243,6 +244,10 @@ lookForAlignDelims: \item \texttt{spacesBeforeDoubleBackSlash}: optionally, specifies the number of spaces to be inserted before (non-aligned) \lstinline!\\!. In order to use this field, \texttt{alignDoubleBackSlash} needs to be set to 0 (default: 0). + \item \texttt{multiColumnGrouping}: details if \texttt{latexindent.pl} should group columns + underneath a \lstinline!\multicolumn! command (default: 0); + \item \texttt{alignRowsWithoutMaxDelims}: details if rows that do not contain the + maximum number of delimeters should be formatted so as to have the ampersands aligned (default: 1). \end{itemize} Assuming that you have the settings in \cref{lst:aligndelims:advanced} saved in \texttt{tabular.yaml}, and the code @@ -276,6 +281,44 @@ latexindent.pl -l tabular1.yaml tabular1.tex \cmhlistingsfromfile[style=yaml-LST]{demonstrations/tabular1.yaml}[yaml-TCB]{\texttt{tabular1.yaml}}{lst:tabular1YAML} \end{minipage}% + Now consider the file \texttt{tabular2.tex} in \cref{lst:tabular2}, which contains a \lstinline!\multicolumn! command, and + the YAML files in \cref{lst:tabular2YAML,lst:tabular3YAML}. + + \cmhlistingsfromfile*[showspaces=false,showtabs=false]{demonstrations/tabular2.tex}{\texttt{tabular2.tex}}{lst:tabular2} + \begin{minipage}{.45\textwidth} + \cmhlistingsfromfile[style=yaml-LST]{demonstrations/tabular2.yaml}[yaml-TCB]{\texttt{tabular2.yaml}}{lst:tabular2YAML} + \end{minipage}% + \hfill + \begin{minipage}{.45\textwidth} + \cmhlistingsfromfile[style=yaml-LST]{demonstrations/tabular3.yaml}[yaml-TCB]{\texttt{tabular3.yaml}}{lst:tabular3YAML} + \end{minipage}% + + On running the commands + \begin{commandshell} +latexindent.pl tabular2.tex +latexindent.pl -s tabular2.tex -l tabular2.yaml +latexindent.pl -s tabular2.tex -l tabular3.yaml + \end{commandshell} + we obtain the respective outputs given in \cref{lst:tabular2-default,lst:tabular2-mc,lst:tabular2-no-max}. + + \begin{widepage} + \cmhlistingsfromfile*[showspaces=false,showtabs=false]{demonstrations/tabular2-default.tex}{\texttt{tabular2-default.tex}}{lst:tabular2-default} + \cmhlistingsfromfile*[showspaces=false,showtabs=false]{demonstrations/tabular2-mc.tex}{\texttt{tabular2-mc.tex}}{lst:tabular2-mc} + \cmhlistingsfromfile*[showspaces=false,showtabs=false]{demonstrations/tabular2-no-max.tex}{\texttt{tabular2-no-max.tex}}{lst:tabular2-no-max} + \end{widepage} + + Notice in particular: + \begin{itemize} + \item in both \cref{lst:tabular2-default,lst:tabular2-mc} all rows have been aligned at the ampersand, even + those that do not contain the maximum number of ampersands (3 ampersands, in this case); + \item in \cref{lst:tabular2-default} the columns have been aligned at the ampersand; + \item in \cref{lst:tabular2-mc} the \lstinline!\multicolumn! command has grouped the $2$ columns beneath \emph{and} above it, + because \texttt{multiColumnGrouping} is set to $1$ in \cref{lst:tabular2YAML}; + \item in \cref{lst:tabular2-no-max} rows~3 and~6 have \emph{not} been aligned at the ampersand, because + \texttt{alignRowsWithoutMaxDelims} has been to set to $0$ in \cref{lst:tabular3YAML}; however, + the \lstinline!\\! \emph{have} still been aligned. + \end{itemize} + As of Version 3.0, the alignment routine works on mandatory and optional arguments within commands, and also within `special' code blocks (see \texttt{specialBeginEnd} on \cpageref{yaml:specialBeginEnd}); for example, assuming that you have a command called \lstinline!\matrix! and that it is populated within \texttt{lookForAlignDelims} (which it is, by default), and that you @@ -426,7 +469,7 @@ latexindent.pl headings1.tex -l=headings1.yaml of these are shown in \cref{tab:code-blocks}. \begin{longtable}{m{.3\linewidth}@{\hspace{.25cm}}m{.4\linewidth}@{}m{.2\linewidth}} - \caption{Code blocks known to \texttt{latexindent.pl}}\label{tab:code-blocks}\\ + \caption{Code blocks known to \texttt{latexindent.pl}}\label{tab:code-blocks} \\ \toprule Code block & characters allowed in name & example \\ \midrule @@ -462,31 +505,31 @@ mand arg text \else ... \fi - \end{lstlisting}\\\cmidrule{2-3} + \end{lstlisting} \\\cmidrule{2-3} items & User specified, see \vref{lst:indentafteritems,lst:itemNames} & \begin{lstlisting}[,nolol=true,] \begin{enumerate} \item ... \end{enumerate} - \end{lstlisting}\\\cmidrule{2-3} + \end{lstlisting} \\\cmidrule{2-3} specialBeginEnd & User specified, see \vref{lst:specialBeginEnd} & \begin{lstlisting}[,nolol=true,] \[ ... \] - \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{longtable} 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 7e8ddcd50fd..091f9154203 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 @@ -670,11 +670,11 @@ latexindent.pl -m env-mlb6.tex -l env-mlb9.yaml,env-mlb10.yaml,env-mlb11.yaml,en modified using \texttt{latexindent.pl}. \begin{longtable}{m{.2\textwidth}@{\hspace{.75cm}}m{.35\textwidth}@{}m{.4\textwidth}} - \caption{Poly-switch mappings for all code-block types}\label{tab:poly-switch-mapping}\\ + \caption{Poly-switch mappings for all code-block types}\label{tab:poly-switch-mapping} \\ \toprule - Code block & Sample & Poly-switch mapping \\ + Code block & Sample & Poly-switch mapping \\ \midrule - environment & + environment & \begin{lstlisting}[escapeinside={(*@}{@*)},nolol=true] before words(*@$\BeginStartsOnOwnLine$@*) \begin{myenv}(*@$\BodyStartsOnOwnLine$@*) @@ -682,7 +682,7 @@ body of myenv(*@$\EndStartsOnOwnLine$@*) \end{myenv}(*@$\EndFinishesWithLineBreak$@*) after words \end{lstlisting} - & + & \begin{tabular}[t]{c@{~}l@{}} $\BeginStartsOnOwnLine$ & BeginStartsOnOwnLine \\ $\BodyStartsOnOwnLine$ & BodyStartsOnOwnLine \\ @@ -691,7 +691,7 @@ after words \end{tabular} \\ \cmidrule{2-3} - ifelsefi & + ifelsefi & \begin{lstlisting}[escapeinside={(*@}{@*)},nolol=true] before words(*@$\BeginStartsOnOwnLine$@*) \if...(*@$\BodyStartsOnOwnLine$@*) @@ -701,7 +701,7 @@ body of else statement(*@$\EndStartsOnOwnLine$@*) \fi(*@$\EndFinishesWithLineBreak$@*) after words \end{lstlisting} - & + & \begin{tabular}[t]{c@{~}l@{}} $\BeginStartsOnOwnLine$ & IfStartsOnOwnLine \\ $\BodyStartsOnOwnLine$ & BodyStartsOnOwnLine \\ @@ -712,7 +712,7 @@ after words \end{tabular} \\ \cmidrule{2-3} - optionalArguments & + optionalArguments & \begin{lstlisting}[escapeinside={(*@}{@*)},nolol=true] ...(*@$\BeginStartsOnOwnLine$@*) [(*@$\BodyStartsOnOwnLine$@*) @@ -720,7 +720,7 @@ body of opt arg(*@$\EndStartsOnOwnLine$@*) ](*@$\EndFinishesWithLineBreak$@*) ... \end{lstlisting} - & + & \begin{tabular}[t]{c@{~}l@{}} $\BeginStartsOnOwnLine$ & LSqBStartsOnOwnLine\footnote{LSqB stands for Left Square Bracket} \\ $\BodyStartsOnOwnLine$ & OptArgBodyStartsOnOwnLine \\ @@ -729,7 +729,7 @@ body of opt arg(*@$\EndStartsOnOwnLine$@*) \end{tabular} \\ \cmidrule{2-3} - mandatoryArguments & + mandatoryArguments & \begin{lstlisting}[escapeinside={(*@}{@*)},nolol=true] ...(*@$\BeginStartsOnOwnLine$@*) {(*@$\BodyStartsOnOwnLine$@*) @@ -737,7 +737,7 @@ body of mand arg(*@$\EndStartsOnOwnLine$@*) }(*@$\EndFinishesWithLineBreak$@*) ... \end{lstlisting} - & + & \begin{tabular}[t]{c@{~}l@{}} $\BeginStartsOnOwnLine$ & LCuBStartsOnOwnLine\footnote{LCuB stands for Left Curly Brace} \\ $\BodyStartsOnOwnLine$ & MandArgBodyStartsOnOwnLine \\ @@ -746,26 +746,26 @@ body of mand arg(*@$\EndStartsOnOwnLine$@*) \end{tabular} \\ \cmidrule{2-3} - commands & + commands & \begin{lstlisting}[escapeinside={(*@}{@*)},morekeywords={mycommand},nolol=true,] before words(*@$\BeginStartsOnOwnLine$@*) \mycommand(*@$\BodyStartsOnOwnLine$@*) (*@$\langle$\itshape{arguments}$\rangle$@*) \end{lstlisting} - & + & \begin{tabular}[t]{c@{~}l@{}} $\BeginStartsOnOwnLine$ & CommandStartsOnOwnLine \\ $\BodyStartsOnOwnLine$ & CommandNameFinishesWithLineBreak \\ \end{tabular} \\ \cmidrule{2-3} - namedGroupingBraces Brackets & + namedGroupingBraces Brackets & \begin{lstlisting}[escapeinside={(*@}{@*)},morekeywords={myname},nolol=true,] before words(*@$\BeginStartsOnOwnLine$@*) myname(*@$\BodyStartsOnOwnLine$@*) (*@$\langle$\itshape{braces/brackets}$\rangle$@*) \end{lstlisting} - & + & \begin{tabular}[t]{c@{~}l@{}} $\BeginStartsOnOwnLine$ & NameStartsOnOwnLine \\ $\BodyStartsOnOwnLine$ & NameFinishesWithLineBreak \\ @@ -778,7 +778,7 @@ before words(*@$\BeginStartsOnOwnLine$@*) key(*@$\EqualsStartsOnOwnLine$@*)=(*@$\BodyStartsOnOwnLine$@*) (*@$\langle$\itshape{braces/brackets}$\rangle$@*) \end{lstlisting} - & + & \begin{tabular}[t]{c@{~}l@{}} $\BeginStartsOnOwnLine$ & KeyStartsOnOwnLine \\ $\EqualsStartsOnOwnLine$ & EqualsStartsOnOwnLine \\ @@ -786,20 +786,20 @@ key(*@$\EqualsStartsOnOwnLine$@*)=(*@$\BodyStartsOnOwnLine$@*) \end{tabular} \\ \cmidrule{2-3} - items & + items & \begin{lstlisting}[escapeinside={(*@}{@*)},nolol=true] before words(*@$\BeginStartsOnOwnLine$@*) \item(*@$\BodyStartsOnOwnLine$@*) ... \end{lstlisting} - & + & \begin{tabular}[t]{c@{~}l@{}} $\BeginStartsOnOwnLine$ & ItemStartsOnOwnLine \\ $\BodyStartsOnOwnLine$ & ItemFinishesWithLineBreak \\ \end{tabular} \\ \cmidrule{2-3} - specialBeginEnd & + specialBeginEnd & \begin{lstlisting}[escapeinside={(*@}{@*)},nolol=true] before words(*@$\BeginStartsOnOwnLine$@*) \[(*@$\BodyStartsOnOwnLine$@*) @@ -807,7 +807,7 @@ body of special(*@$\EndStartsOnOwnLine$@*) \](*@$\EndFinishesWithLineBreak$@*) after words \end{lstlisting} - & + & \begin{tabular}[t]{c@{~}l@{}} $\BeginStartsOnOwnLine$ & SpecialBeginStartsOnOwnLine \\ $\BodyStartsOnOwnLine$ & SpecialBodyStartsOnOwnLine \\ diff --git a/Master/texmf-dist/doc/support/latexindent/subsubsec-no-add-remaining-code-blocks.tex b/Master/texmf-dist/doc/support/latexindent/subsubsec-no-add-remaining-code-blocks.tex index 42794f11f71..7c1302bdc53 100644 --- a/Master/texmf-dist/doc/support/latexindent/subsubsec-no-add-remaining-code-blocks.tex +++ b/Master/texmf-dist/doc/support/latexindent/subsubsec-no-add-remaining-code-blocks.tex @@ -37,7 +37,7 @@ This type of code block is mostly motivated by tikz-based code; we define this code block as follows: \begin{itemize} \item it must immediately follow either \emph{horizontal space} OR \emph{one or more line breaks} OR \lstinline!{! OR \lstinline![! - OR \lstinline!$!; + OR \lstinline!$! OR \lstinline!)! OR \lstinline!(!; \item the name may contain the characters detailed in \vref{tab:code-blocks}; \item then at least one set of curly braces or square brackets (comments and line breaks allowed throughout). \end{itemize} diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm index 195909ac280..14f141b060c 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm @@ -106,8 +106,7 @@ sub modify_line_breaks_settings{ } sub tasks_particular_to_each_object{ - my $self = shift; -# $self->remove_leading_space; + return; } sub create_unique_id{ @@ -130,7 +129,8 @@ sub align_at_ampersand{ } # create an array of zeros - my @columnSizes = (0) x ($maximumNumberOfAmpersands+1); + my @maximumColumnWidth = (0) x ($maximumNumberOfAmpersands+1); + my @maximumColumnWidthMC = (0) x ($maximumNumberOfAmpersands+1); # array for the new body my @formattedBody; @@ -144,29 +144,56 @@ sub align_at_ampersand{ $endPiece = $1; } + # remove any trailing comments + my $trailingComments; + if($_ =~ m/$trailingCommentRegExp/ ){ + $_ =~ s/($trailingCommentRegExp)//; + $trailingComments = $1; + } + + # count the number of ampersands in the current row my $numberOfAmpersands = () = $_ =~ /(?<!\\)&/g; - if($numberOfAmpersands == $maximumNumberOfAmpersands){ - # remove any trailing comments - my $trailingComments; - if($_ =~ m/$trailingCommentRegExp/ ){ - $_ =~ s/($trailingCommentRegExp)//; - $trailingComments = $1; - } + + # switch for multiColumGrouping + my $multiColumnGrouping = ($_ =~ m/\\multicolumn/ and ${$self}{multiColumnGrouping}); + my $alignRowsWithoutMaxDelims = ${$self}{alignRowsWithoutMaxDelims}; + + # by default, the stripped row is simply the current row + my $strippedRow = $_; + + # loop through the columns + my $columnCount = 0; + + # format switch off by default + my $formatRow = 0; + + # store the column sizes for measuring and comparison purposes + my @columnSizes = (); + + # we will store the columns in each row + my @columns; + + # need to have at least one ampersand, or contain a \multicolumn command + if( ($_ =~ m/(?<!\\)&/ and ( ($numberOfAmpersands == $maximumNumberOfAmpersands)||$multiColumnGrouping||$alignRowsWithoutMaxDelims ) ) + or + ($multiColumnGrouping and $alignRowsWithoutMaxDelims) ){ + # remove space at the beginning of a row, surrounding &, and at the end of the row + $_ =~ s/(?<!\\)\h*(?<!\\)&\h*/&/g; + $_ =~ s/^\h*//g; + $_ =~ s/\h*$//g; # if the line finishes with an &, then add an empty space, # otherwise the column count is off $_ .= ($_ =~ m/(?<!\\)&$/ ? " ":q()); - # loop through the columns - my $columnCount = 0; - my $strippedRow = ''; - foreach my $column (split(/(?<!\\)&/,$_)){ - # remove leading space - $column =~ s/^\h*//; - - # remove trailing space - $column =~ s/\h*$//; + # store the columns, which are either split by & + # or otherwise simply the current line, if for example, the current line simply + # contains \multicolumn{8}... \\ (see test-cases/texexchange/366841-zarko.tex, for example) + @columns = ($_ =~ m/(?<!\\)&/ ? split(/(?<!\\)&/,$_) : $_); + # empty the white-space-stripped row + $strippedRow = ''; + foreach my $column (@columns){ # if a column has finished with a \ then we need to add a trailing space, # otherwise the \ can be put next to &. See test-cases/texexchange/112343-gonzalo for example $column .= ($column =~ m/\\$/ ? " ": q()); @@ -175,93 +202,230 @@ sub align_at_ampersand{ # reference: http://www.perl.com/pub/2012/05/perlunicook-unicode-column-width-for-printing.html my $gcs = Unicode::GCString->new($column); my $columnWidth = $gcs->columns(); - $columnSizes[$columnCount] = $columnWidth if($columnWidth > $columnSizes[$columnCount]); + + # multicolumn cells need a bit of special care + if($multiColumnGrouping and $column =~ m/\\multicolumn\{(\d+)\}/ and $1>1){ + $maximumColumnWidthMC[$columnCount] = $columnWidth if( defined $maximumColumnWidthMC[$columnCount] and ($columnWidth > $maximumColumnWidthMC[$columnCount]) ); + $columnWidth = 1 if($multiColumnGrouping and ($column =~ m/\\multicolumn\{(\d+)\}/)); + } + + # store the maximum column width + $maximumColumnWidth[$columnCount] = $columnWidth if( defined $maximumColumnWidth[$columnCount] and ($columnWidth > $maximumColumnWidth[$columnCount]) ); # put the row back together, using " " if the column is empty $strippedRow .= ($columnCount>0 ? "&" : q() ).($columnWidth > 0 ? $column: " "); + # store the column width + $columnSizes[$columnCount] = $columnWidth; + # move on to the next column - $columnCount++; + if($multiColumnGrouping and ($column =~ m/\\multicolumn\{(\d+)\}/)){ + # columns that are within the multiCol statement receive a width of -1 + for my $i (($columnCount+1)..($columnCount+$1)){ + $columnSizes[$i] = -1; + } + # update the columnCount to account for the multiColSpan + $columnCount += $1; + } else { + $columnCount++; + } } - # store the information - push(@formattedBody,{ - row=>$strippedRow, - format=>1, - endPiece=>($endPiece ? $endPiece :q() ), - trailingComment=>($trailingComments ? $trailingComments :q() )}); - } else { - # otherwise simply store the row - push(@formattedBody,{ - row=>$_.($endPiece ? $endPiece : q() ), - format=>0}); + # toggle the formatting switch + $formatRow = 1; + } elsif($endPiece and ${$self}{alignDoubleBackSlash}){ + # otherwise a row could contain no ampersands, but would still desire + # the \\ to be aligned, see test-cases/alignment/multicol-no-ampersands.tex + @columns = $_; + $formatRow = 1; } + + # store the information + push(@formattedBody,{ + row=>$strippedRow, + format=>$formatRow, + multiColumnGrouping=>$multiColumnGrouping, + columnSizes=>\@columnSizes, + columns=>\@columns, + endPiece=>($endPiece ? $endPiece :q() ), + trailingComment=>($trailingComments ? $trailingComments :q() )}); } # output some of the info so far to the log file - $self->logger("Column sizes of horizontally stripped formatted block (${$self}{name}): @columnSizes") if $is_t_switch_active; - - # README: printf( formatting, expression) - # - # formatting has the form %-50s & %-20s & %-19s - # (the numbers have been made up for example) - # the - symbols mean that each column should be left-aligned - # the numbers represent how wide each column is - # the s represents string - # the & needs to be inserted - - # join up the maximum string lengths using "s %-" - my $fmtstring = join("s & %-",@columnSizes); - - # add %- to the beginning and an s to the end - $fmtstring = "%-".$fmtstring."s "; + $self->logger("Maximum column sizes of horizontally stripped formatted block (${$self}{name}): @maximumColumnWidth") if $is_t_switch_active; + $self->logger("align at ampersand: ${$self}{lookForAlignDelims}") if $is_t_switch_active; + $self->logger("align at \\\\: ${$self}{alignDoubleBackSlash}") if $is_t_switch_active; + $self->logger("spaces before \\\\: ${$self}{spacesBeforeDoubleBackSlash}") if $is_t_switch_active; + $self->logger("multi column grouping: ${$self}{multiColumnGrouping}") if $is_t_switch_active; + $self->logger("align rows without maximum delimeters: ${$self}{alignRowsWithoutMaxDelims}") if $is_t_switch_active; + + # acount for multicolumn grouping, if the appropriate switch is set + if(${$self}{multiColumnGrouping}){ + foreach(@formattedBody){ + if(${$_}{format} and ${$_}{row} !~ m/^\h*$/){ + + # set a columnCount, which will vary depending on multiColumnGrouping settings or not + my $columnCount=0; + + # loop through the columns + foreach my $column (@{${$_}{columns}}){ + # calculate the width of the current column + my $gcs = Unicode::GCString->new($column); + my $columnWidth = $gcs->columns(); + + # check for multiColumnGrouping + if(${$_}{multiColumnGrouping} and $column =~ m/\\multicolumn\{(\d+)\}/ and $1>1){ + my $multiColSpan = $1; + + # for example, \multicolumn{3}{c}{<stuff>} spans 3 columns, so + # the maximum column needs to account for this (subtract 1 because of 0 index in perl arrays) + my $columnMax = $columnCount+$multiColSpan-1; + + # groupingWidth contains the total width of column sizes grouped + # underneath the \multicolumn{} statement + my $groupingWidth = 0; + my $maxGroupingWidth = 0; + foreach (@formattedBody){ + $groupingWidth = 0; + + # loop through the columns covered by the multicolumn statement + foreach my $j ($columnCount..$columnMax){ + if( defined @{${$_}{columnSizes}}[$j] + and + @{${$_}{columnSizes}}[$j] >= 0 + and + ${$_}{format} + ){ + $groupingWidth += (defined $maximumColumnWidth[$j] ? $maximumColumnWidth[$j] : 0); + } else { + $groupingWidth = 0; + } + } + + # update the maximum grouping width + $maxGroupingWidth = $groupingWidth if($groupingWidth > $maxGroupingWidth); + + # the cells that receive multicolumn grouping need extra padding; in particular + # the *last* cell of the multicol group receives the padding, hence the + # use of $columnMax below + if(defined @{${$_}{columnSizes}}[$columnMax] and ($columnWidth > ($groupingWidth+3*($multiColSpan-1)) ) and @{${$_}{columnSizes}}[$columnMax] >= 0){ + @{${$_}{multiColPadding}}[$columnMax] = $columnWidth-$groupingWidth-3*($multiColSpan-1); + + # also need to account for maximum column width *including* other multicolumn statements + if($maximumColumnWidthMC[$columnCount]>$columnWidth){ + @{${$_}{multiColPadding}}[$columnMax] += ($maximumColumnWidthMC[$columnCount]-$columnWidth); + } + } + } + # update it to account for the ampersands and 1 space either side of ampersands (total of 3) + $maxGroupingWidth += ($multiColSpan-1)*3; + + # store the maxGroupingWidth for use in the next loop + @{${$_}{maxGroupingWidth}}[$columnCount] = $maxGroupingWidth; + + # update the columnCount to account for the multiColSpan + $columnCount += $multiColSpan - 1; + } + + # increase the column count + $columnCount++; + } + } + } + } - # log file info - $self->logger("Formatting string is: $fmtstring",'heading') if $is_t_switch_active; + # the maximum row width will be used in aligning (or not) the \\ + my $maximumRowWidth = 0; - # finally, reformat the body + # now that the multicolumn widths have been accounted for, loop through the body foreach(@formattedBody){ if(${$_}{format} and ${$_}{row} !~ m/^\h*$/){ + # set a columnCount, which will vary depending on multiColumnGrouping settings or not my $columnCount=0; my $tmpRow = q(); - foreach my $column (split(/(?<!\\)&/,${$_}{row})){ - # grab the column width + + # loop through the columns + foreach my $column (@{${$_}{columns}}){ + # calculate the width of the current column my $gcs = Unicode::GCString->new($column); my $columnWidth = $gcs->columns(); - # reset the padding + # reset the column padding my $padding = q(); - if($columnWidth < $columnSizes[$columnCount]){ - $padding = " " x ($columnSizes[$columnCount] - $columnWidth); + + # check for multiColumnGrouping + if(${$_}{multiColumnGrouping} and $column =~ m/\\multicolumn\{(\d+)\}/ and $1>1){ + my $multiColSpan = $1; + + # groupingWidth contains the total width of column sizes grouped + # underneath the \multicolumn{} statement + my $maxGroupingWidth = ${${$_}{maxGroupingWidth}}[$columnCount]; + + # set the padding; we need + # maximum( $maxGroupingWidth, $maximumColumnWidthMC[$columnCount] ) + # rather than load another module to give the 'max' function, I use the ternary operator + my $maxValueToUse = 0; + if(defined $maximumColumnWidthMC[$columnCount]){ + $maxValueToUse = ($maxGroupingWidth>$maximumColumnWidthMC[$columnCount]?$maxGroupingWidth:$maximumColumnWidthMC[$columnCount]); + } else { + $maxValueToUse = $maxGroupingWidth; + } + + # calculate the padding + $padding = " " x ( $maxValueToUse >= $columnWidth ? $maxValueToUse - $columnWidth : 0 ); + + # update the columnCount to account for the multiColSpan + $columnCount += $multiColSpan - 1; + } else { + # compare the *current* column width with the *maximum* column width + $padding = " " x (defined $maximumColumnWidth[$columnCount] and $maximumColumnWidth[$columnCount] >= $columnWidth ? $maximumColumnWidth[$columnCount] - $columnWidth : 0); } - $tmpRow .= $column.$padding." & "; + + # either way, the row is formed of "COLUMN + PADDING" + $tmpRow .= $column.$padding.(defined @{${$_}{multiColPadding}}[$columnCount] ? " " x @{${$_}{multiColPadding}}[$columnCount]: q())." & "; $columnCount++; } # remove the final & - $tmpRow =~ s/\s&\s$/ /; + $tmpRow =~ s/\h&\h*$/ /; + $tmpRow =~ s/\h*$/ /; # replace the row with the formatted row ${$_}{row} = $tmpRow; - # format the row, and put the trailing \\ and trailing comments back into the row - ${$_}{row} .= (${$_}{endPiece} ? ${$_}{endPiece} :q() ).(${$_}{trailingComment}? ${$_}{trailingComment} : q() ); + # update the maximum row width + my $gcs = Unicode::GCString->new($tmpRow); + ${$_}{rowWidth} = $gcs->columns(); + $maximumRowWidth = ${$_}{rowWidth} if(${$_}{rowWidth} > $maximumRowWidth); + } + } - # possibly remove space ahead of \\ - ${$_}{row} =~ s/\h*\\\\/\\\\/ if(!${$self}{alignDoubleBackSlash}); + # final loop through to get \\ aligned + foreach (@formattedBody){ + # reset the padding + my $padding = q(); - # possibly insert spaces infront of \\ - if(defined ${$self}{spacesBeforeDoubleBackSlash} and ${$self}{spacesBeforeDoubleBackSlash}>=0 and !${$self}{alignDoubleBackSlash}){ - my $horizontalSpaceToInsert = " "x (${$self}{spacesBeforeDoubleBackSlash}); - ${$_}{row} =~ s/\h*\\\\/$horizontalSpaceToInsert\\\\/; + # possibly adjust the padding + if(${$_}{format} and ${$_}{row} !~ m/^\h*$/){ + # remove trailing horizontal space if ${$self}{alignDoubleBackSlash} is set to 0 + ${$_}{row} =~ s/\h*$// if (!${$self}{alignDoubleBackSlash}); + + # format spacing infront of \\ + if(defined ${$self}{spacesBeforeDoubleBackSlash} and ${$self}{spacesBeforeDoubleBackSlash}<0 and !${$self}{alignDoubleBackSlash}){ + # zero spaces (possibly resulting in un-aligned \\) + $padding = q(); + } elsif(defined ${$self}{spacesBeforeDoubleBackSlash} and ${$self}{spacesBeforeDoubleBackSlash}>=0 and !${$self}{alignDoubleBackSlash}){ + # specified number of spaces (possibly resulting in un-aligned \\) + $padding = " " x (${$self}{spacesBeforeDoubleBackSlash}); + } else { + # aligned \\ + $padding = " " x ($maximumRowWidth - ${$_}{rowWidth}); } } - # if we have an empty row, it's possible that it originally had an end piece (e.g \\) and/or trailing comments - if(${$_}{row} =~ m/^\h*$/){ - ${$_}{row} .= (${$_}{endPiece} ? ${$_}{endPiece} :q() ).(${$_}{trailingComment}? ${$_}{trailingComment} : q() ); - } + # format the row, and put the trailing \\ and trailing comments back into the row + ${$_}{row} .= $padding.(${$_}{endPiece} ? ${$_}{endPiece} :q() ).(${$_}{trailingComment}? ${$_}{trailingComment} : q() ); } # to the log file diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm index 1a9b9c1f9f8..e4b5f12c54d 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm @@ -14,7 +14,6 @@ package LatexIndent::GetYamlSettings; # Chris Hughes, 2017 # # For all communication, please visit: https://github.com/cmhughes/latexindent.pl -use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/; use strict; use warnings; use LatexIndent::Switches qw/%switches $is_m_switch_active $is_t_switch_active $is_tt_switch_active/; @@ -241,6 +240,8 @@ sub get_indentation_settings_for_this_object{ ${${previouslyFoundSettings}{$storageName}}{lookForAlignDelims} = ${$self}{lookForAlignDelims} if(defined ${$self}{lookForAlignDelims}); ${${previouslyFoundSettings}{$storageName}}{alignDoubleBackSlash} = ${$self}{alignDoubleBackSlash} if(defined ${$self}{alignDoubleBackSlash}); ${${previouslyFoundSettings}{$storageName}}{spacesBeforeDoubleBackSlash} = ${$self}{spacesBeforeDoubleBackSlash} if(defined ${$self}{spacesBeforeDoubleBackSlash}); + ${${previouslyFoundSettings}{$storageName}}{multiColumnGrouping} = ${$self}{multiColumnGrouping} if(defined ${$self}{multiColumnGrouping}); + ${${previouslyFoundSettings}{$storageName}}{alignRowsWithoutMaxDelims} = ${$self}{alignRowsWithoutMaxDelims} if(defined ${$self}{alignRowsWithoutMaxDelims}); # some objects, e.g ifElseFi, can have extra assignments, e.g ElseStartsOnOwnLine # these need to be stored as well! @@ -280,10 +281,14 @@ sub alignment_at_ampersand_settings{ ${$self}{lookForAlignDelims} = (defined ${${$masterSettings{lookForAlignDelims}}{$name}}{delims} ) ? ${${$masterSettings{lookForAlignDelims}}{$name}}{delims} : 1; ${$self}{alignDoubleBackSlash} = (defined ${${$masterSettings{lookForAlignDelims}}{$name}}{alignDoubleBackSlash} ) ? ${${$masterSettings{lookForAlignDelims}}{$name}}{alignDoubleBackSlash} : 1; ${$self}{spacesBeforeDoubleBackSlash} = (defined ${${$masterSettings{lookForAlignDelims}}{$name}}{spacesBeforeDoubleBackSlash} ) ? ${${$masterSettings{lookForAlignDelims}}{$name}}{spacesBeforeDoubleBackSlash} : -1; + ${$self}{multiColumnGrouping} = (defined ${${$masterSettings{lookForAlignDelims}}{$name}}{multiColumnGrouping} ) ? ${${$masterSettings{lookForAlignDelims}}{$name}}{multiColumnGrouping} : 0; + ${$self}{alignRowsWithoutMaxDelims} = (defined ${${$masterSettings{lookForAlignDelims}}{$name}}{alignRowsWithoutMaxDelims} ) ? ${${$masterSettings{lookForAlignDelims}}{$name}}{alignRowsWithoutMaxDelims} : 1; } else { ${$self}{lookForAlignDelims} = 1; ${$self}{alignDoubleBackSlash} = 1; ${$self}{spacesBeforeDoubleBackSlash} = -1; + ${$self}{multiColumnGrouping} = 0; + ${$self}{alignRowsWithoutMaxDelims} = 1; } return; } diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm index a98cebf05e2..04753f81a87 100755 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm @@ -36,7 +36,7 @@ our $ifElseFiRegExp = qr/ (\R*) ) # begin statement, e.g \ifnum, \ifodd ( - \\(?!if)|\R|\h|\#|!-! # up until a \\, linebreak # or !-!, which is + \\(?!if)|[0-9]|\R|\h|\#|!-! # up until a \\, linebreak # or !-!, which is ) # part of the tokens used for latexindent ( (?: diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm index eca7ae7aad5..336ec34c7ad 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm @@ -41,7 +41,7 @@ sub processSwitches{ my $self = shift; # details of the script to log file - $self->logger("$FindBin::Script version 3.1, a script to indent .tex files",'heading'); + $self->logger("$FindBin::Script version 3.2, a script to indent .tex files",'heading'); $self->logger("$FindBin::Script lives here: $FindBin::RealBin/"); # time the script is used @@ -50,7 +50,7 @@ sub processSwitches{ if(scalar(@ARGV) < 1 or $switches{showhelp}) { print <<ENDQUOTE -latexindent.pl version 3.1 +latexindent.pl version 3.2 usage: latexindent.pl [options] [file][.tex|.sty|.cls|.bib|...] -h, --help help (see the documentation for detailed instructions and examples) diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm index f7469504e10..d18281f4ee9 100755 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm @@ -35,7 +35,7 @@ sub construct_grouping_braces_brackets_regexp{ # store the regular expresssion for matching and replacing $grouping_braces_regexp = qr/ ( - \h|\R|\{|\[|\$|\) + \h|\R|\{|\[|\$|\)|\( ) ( [0-9a-zA-Z@\*><]+? # lowercase|uppercase letters, @, *, numbers, forward slash, dots diff --git a/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml b/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml index fbc5401c3e9..916efb46dd3 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.1, 2017-05-27 +# defaultSettings.yaml for latexindent.pl, version 3.2, 2017-06-19 # a script that aims to # beautify .tex, .sty, .cls files # @@ -140,6 +140,8 @@ lookForAlignDelims: delims: 1 alignDoubleBackSlash: 1 spacesBeforeDoubleBackSlash: 2 + multiColumnGrouping: 0 + alignRowsWithoutMaxDelims: 1 tabularx: delims: 1 longtable: 1 diff --git a/Master/texmf-dist/scripts/latexindent/latexindent.pl b/Master/texmf-dist/scripts/latexindent/latexindent.pl index b4474a14c49..107d4fab865 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.1, 2017-05-27 +# latexindent.pl, version 3.2, 2017-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 |