Skip to content

Commit

Permalink
small tweak to alignment within commands, and updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
cmhughes committed Mar 30, 2016
1 parent 64b2b2d commit 057e8f1
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 21 deletions.
Binary file modified documentation/latexindent.pdf
Binary file not shown.
87 changes: 79 additions & 8 deletions documentation/latexindent.tex
Original file line number Diff line number Diff line change
Expand Up @@ -686,10 +686,12 @@ \subsection{\lstinline!defaultSettings.yaml!}
providing this feature.

\item[\verbitem{lookForAlignDelims}] This is the first example of a field
in \lstinline!defaultSettings.yaml! that has more than one line; \cref{lst:aligndelims}
shows more details.
in \lstinline!defaultSettings.yaml! that has more than one line; \cref{lst:aligndelims:basic}
shows more details. In fact, the fields in \verbitem{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.

\begin{cmhlistings}[style=yaml]{\lstinline!lookForAlignDelims!}{lst:aligndelims}
\begin{cmhlistings}[style=yaml]{\lstinline!lookForAlignDelims! (basic)}{lst:aligndelims:basic}
lookForAlignDelims:
tabular: 1
tabularx: 1
Expand All @@ -711,18 +713,18 @@ \subsection{\lstinline!defaultSettings.yaml!}

The environments specified in this field will be operated on in a special way by \lstinline!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 \cref{lst:tabularbefore,lst:tabularafter}.
but in many cases it will produce results such as those in \cref{lst:tabularbefore:basic,lst:tabularafter:basic}.

\begin{minipage}{.5\textwidth}
\begin{cmhlistings}[style=demo,columns=fixed]{\lstinline!tabular! before}{lst:tabularbefore}
\begin{cmhlistings}[style=demo,columns=fixed]{\lstinline!tabular! before}{lst:tabularbefore:basic}
\begin{tabular}{cccc}
1& 2 &3 &4\\
5& &6 &\\
\end{tabular}
\end{cmhlistings}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\begin{cmhlistings}[style=demo,columns=fixed]{\lstinline!tabular! after}{lst:tabularafter}
\begin{cmhlistings}[style=demo,columns=fixed]{\lstinline!tabular! after (basic)}{lst:tabularafter:basic}
\begin{tabular}{cccc}
1 & 2 & 3 & 4 \\
5 & & 6 & \\
Expand All @@ -734,6 +736,74 @@ \subsection{\lstinline!defaultSettings.yaml!}
environments then you can either remove them from \lstinline!lookForAlignDelims! altogether, or set the relevant key to \lstinline!0!, for example \lstinline!tabular: 0!, or if you just want to ignore \emph{specific}
instances of the environment, you could wrap them in something from \lstinline!noIndentBlock! (see \cref{lst:noIndentBlock}).

If you wish to remove the alignment of the \lstinline!\\! within a delimiter-aligned block, then the
advanced form of \lstinline!lookForAlignDelims! shown in \cref{lst:aligndelims:advanced} is for you.
\begin{cmhlistings}[style=yaml]{\lstinline!lookForAlignDelims! (advanced)}{lst:aligndelims:advanced}
lookForAlignDelims:
tabular:
delims: 1
alignDoubleBackSlash: 0
spacesBeforeDoubleBackSlash: 0
tabularx:
delims: 1
longtable: 1
\end{cmhlistings}

Note that you can use a mixture of the basic and advanced form: in \cref{lst:aligndelims:advanced} \lstinline!tabular! and \lstinline!tabularx!
are advanced and \lstinline!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:
\begin{itemize}
\item \lstinline!delims!: switch equivalent to simply specifying, for example, \lstinline!tabular: 1! in
the basic version shown in \cref{lst:aligndelims:basic} (default: 1);
\item \lstinline!alignDoubleBackSlash!: switch to determine if \lstinline!\\! should be aligned (default: 1);
\item \lstinline!spacesBeforeDoubleBackSlash!: optionally, specifies the number of spaces to be inserted
before (non-aligned) \lstinline!\\!. In order to use this field, \lstinline!alignDoubleBackSlash! needs
to be set to 0 (default: 0).
\end{itemize}

With the settings shown in \cref{lst:aligndelims:advanced} we receive the before-and-after results shown in
\cref{lst:tabularbefore:advanced,lst:tabularafter:advanced}; note that the ampersands have been aligned, but
the \lstinline!\\! have not (compare the alignment of \lstinline!\\! in \cref{lst:tabularafter:basic,lst:tabularafter:advanced}).

\begin{minipage}{.5\textwidth}
\begin{cmhlistings}[style=demo,columns=fixed]{\lstinline!tabular! before }{lst:tabularbefore:advanced}
\begin{tabular}{cccc}
1& 2 &3 &4\\
5& &6 &\\
\end{tabular}
\end{cmhlistings}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\begin{cmhlistings}[style=demo,columns=fixed]{\lstinline!tabular! after (advanced)}{lst:tabularafter:advanced}
\begin{tabular}{cccc}
1 & 2 & 3 & 4\\
5 & & 6 &\\
\end{tabular}
\end{cmhlistings}
\end{minipage}

Using \lstinline!spacesBeforeDoubleBackSlash: 3! gives \cref{lst:tabularafter:spacing,lst:tabularafter:spacing},
note the spacing before the \lstinline!\\! in \cref{lst:tabularafter:spacing}.

\begin{minipage}{.5\textwidth}
\begin{cmhlistings}[style=demo,columns=fixed]{\lstinline!tabular! before}{lst:tabularbefore:spacing}
\begin{tabular}{cccc}
1& 2 &3 &4\\
5& &6 &\\
\end{tabular}
\end{cmhlistings}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\begin{cmhlistings}[style=demo,columns=fixed]{\lstinline!tabular! after (spacing)}{lst:tabularafter:spacing}
\begin{tabular}{cccc}
1 & 2 & 3 & 4 \\
5 & & 6 & \\
\end{tabular}
\end{cmhlistings}
\end{minipage}




If you have blocks of code that you wish to align at the \& character that
are \emph{not} wrapped in, for example, \lstinline!\begin{tabular}...\end{tabular}!, then you use the mark up
illustrated in \cref{lst:alignmentmarkup}. Note that the \lstinline!%*! must be next to
Expand Down Expand Up @@ -836,9 +906,10 @@ \subsection{\lstinline!defaultSettings.yaml!}
\item[\verbitem{indentAfterHeadings}] This field enables the user to specify
indentation rules that take effect after heading commands such as \lstinline!\part!, \lstinline!\chapter!,
\lstinline!\section!, \lstinline!\subsection*! etc. This field is slightly different from all
\lstinline!\section!, \lstinline!\subsection*! etc. This field is slightly different from most
of the fields that we have considered previously, because each element is
itself a field which has two elements: \lstinline!indent! and \lstinline!level!.
itself a field which has two elements: \lstinline!indent! and \lstinline!level!. (Similar
in structure to the advanced form of \lstinline!lookForAlignDelims! in \cref{lst:aligndelims:advanced}.)
\begin{cmhlistings}[style=yaml]{\lstinline!indentAfterHeadings!}{lst:indentAfterHeadings}
indentAfterHeadings:
part:
Expand Down
8 changes: 7 additions & 1 deletion latexindent.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,12 @@ sub begin_command_with_alignment{
# }

if( $_ =~ m/^\s*%\*\s*\\begin\{(.*?)\}/ and $lookForAlignDelims{$1}) {
$delimiters=1;
# increase the indentation
&increase_indent({name=>$1,
alignmentDelimiters=>1,
type=>"environment",
begin=>"\\begin{$1}",
end=>"\\end{$1}"});
# tracing mode
print $logfile "Line $lineCounter\t Delimiter environment started: $1 (see lookForAlignDelims)\n" if($tracingMode);
}
Expand Down Expand Up @@ -1077,6 +1082,7 @@ sub end_command_with_alignment{
# environments
if($delimiters) {
&print_aligned_block();
&decrease_indent($1);
} else {
# tracing mode
print $logfile "Line $lineCounter\t FYI: did you mean to start a delimiter block on a previous line? \n" if($tracingMode);
Expand Down
24 changes: 12 additions & 12 deletions success/alignmentoutsideEnvironments.tex
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
% arara: indent: {overwrite: true, trace: yes, silent: yes}

\matrix{%
% \begin{tabular}
& A_1 & A_2 & A_3 & A_4 & A_5 & A_6 & A_7 & A_8 & A_9 \\\hline
A_1 & 0 & & & & & & & & \\
A_2 & & 0 & & & & & & & \\
A_3 & & & 0 & & & & & & \\
A_4 & & & & 0 & & & & & \\
A_5 & & & & & 0 & & & & \\
A_6 & & & & & & 0 & & & \\
A_7 & & & & & & & 0 & & \\
A_8 & & & & & & & & 0 & \\
A_9 & & & & & & & & & 0 \\
%* \end{align}
%* \begin{tabular}
& A_1 & A_2 & A_3 & A_4 & A_5 & A_6 & A_7 & A_8 & A_9 \\\hline
A_1 & 0 & & & & & & & & \\
A_2 & & 0 & & & & & & & \\
A_3 & & & 0 & & & & & & \\
A_4 & & & & 0 & & & & & \\
A_5 & & & & & 0 & & & & \\
A_6 & & & & & & 0 & & & \\
A_7 & & & & & & & 0 & & \\
A_8 & & & & & & & & 0 & \\
A_9 & & & & & & & & & 0 \\
%* \end{tabular}
}
\begin{tabular}
& A_1 & A_2 & A_3 & A_4 & A_5 & A_6 & A_7 & A_8 & A_9 \\\hline
Expand Down

0 comments on commit 057e8f1

Please sign in to comment.