github cmhughes/latexindent.pl V3.12

latest releases: V4.0, V3.24.7, V3.24.6...
4 years ago

This release implements two new features:

  • check switch available, full details at issue 215
  • lines switch available, full details at issue 247

Additionally, mainDocument is now used as a preference instead of masterDocument for the textWrap routine, although masterDocument is still supported and will be for all V3.* of latexindent.pl.

check switch: interface

  1. new switch: -k or --check which checks if the indented text is different from the original; a 'poor man's diff' is given to the log file
  2. new switch: -kv or --checkv which does the same thing as the -k switch, but additionally outputs the 'poor man's diff' to the terminal.

For both switches, then the exit codes are as you detailed in the original post; explicitly:

  • latexindent.pl will exit with 0 if the indented text is not different
  • latexindent.pl will exit with 1 if the indented text is different

check switch: demonstration 1

Let's begin with the following file, say myfile.tex

here is a nested test
\begin{one}
	to be nested to be nested
	to be nested to be nested
	to be nested to be nested
	\begin{two}
		nested text nested tex nested tex
		nested text nested tex nested tex
		nested text nested tex nested tex
		nested text nested tex nested tex
	\end{two}
\end{one}
between nests
between nests
between nests
\begin{one}
	to be nested to be nested one   
	to be nested to be nested       two
	to be nested to be nested           three
\end{one}
here is a nested test
\begin{one}
	to be nested to be nested
	to be nested to be nested
	to be nested to be nested
	\begin{two}
		nested text nested tex nested tex
		nested text nested tex nested tex
		nested text nested tex nested tex
		nested text nested tex nested tex
	\end{two}
\end{one}
more
    of this
  again
        and again

If we run

latexindent.pl  --check myfile.tex -s -y "defaultIndent: '  '"
echo $?

Then, crucially, the exit code is 1

If we run

latexindent.pl  --checkv myfile.tex -s -y "defaultIndent: '  '"
echo $?

then the 'simple diff' is output as follows:

       @@ 3 -- 11 @@
       -	to be nested to be nested
       -	to be nested to be nested
       -	to be nested to be nested
       -	\begin{two}
       -		nested text nested tex nested tex
       -		nested text nested tex nested tex
       -		nested text nested tex nested tex
       -		nested text nested tex nested tex
       -	\end{two}
       +  to be nested to be nested
       +  to be nested to be nested
       +  to be nested to be nested
       +  \begin{two}
       +    nested text nested tex nested tex
       +    nested text nested tex nested tex
       +    nested text nested tex nested tex
       +    nested text nested tex nested tex
       +  \end{two}
       @@ 17 -- 19 @@
       -	to be nested to be nested one   
       -	to be nested to be nested       two
       -	to be nested to be nested           three
       +  to be nested to be nested one
       +  to be nested to be nested       two
       +  to be nested to be nested           three
       @@ 23 -- 31 @@
       -	to be nested to be nested
       -	to be nested to be nested
       -	to be nested to be nested
       -	\begin{two}
       -		nested text nested tex nested tex
       -		nested text nested tex nested tex
       -		nested text nested tex nested tex
       -		nested text nested tex nested tex
       -	\end{two}
       +  to be nested to be nested
       +  to be nested to be nested
       +  to be nested to be nested
       +  \begin{two}
       +    nested text nested tex nested tex
       +    nested text nested tex nested tex
       +    nested text nested tex nested tex
       +    nested text nested tex nested tex
       +  \end{two}
       @@ 34 -- 36 @@
       -    of this
       -  again
       -        and again
       +of this
       +again
       +and again

--lines switch available syntax

  • line range, as in - -lines 3-7
  • single line, as in --lines 5
  • multiple line ranges separated by commas, as in --lines 3-5,8-10
  • negated line ranges, as in --lines !3-5 which translates to --lines 1-2,6-N, where N is the number of lines in your file;

lines switch: demonstration 2

Starting with

here is a nested test
\begin{one}
		first block, second line
		first block, third line
		first block, fourth line
	\begin{two}
		second block, first line
		second block, second line
		second block, third line
		second block, fourth line
	\end{two}
\end{one}

and running

latexindent.pl --lines 3-5 myfile.tex

gives

here is a nested test
\begin{one}
first block, second line
first block, third line
first block, fourth line
	\begin{two}
		second block, first line
		second block, second line
		second block, third line
		second block, fourth line
	\end{two}
\end{one}

lines switch: demonstration 3

Running

latexindent.pl --lines 3-5,8-10 myfile.tex

gives

here is a nested test
\begin{one}
first block, second line
first block, third line
first block, fourth line
	\begin{two}
		second block, first line
second block, second line
second block, third line
second block, fourth line
	\end{two}
\end{one}

Don't miss a new latexindent.pl release

NewReleases is sending notifications on new releases.