Perl script to add indentation (leading horizontal space) to LaTeX files. It can modify line breaks before, during and after code blocks; it can perform text wrapping and paragraph line break removal. It can also perform string-based and regex-based substitutions/replacements. The script is customisable through its YAML interface.
GPL-3.0 License
Bot releases are visible (Hide)
Published by github-actions[bot] almost 3 years ago
This release implements an upgrade to the verbatim
blocks, and friends. Thank you to @XuehaiPan for this contribution.
See https://github.com/cmhughes/latexindent.pl/issues/288 for discussion and history.
noIndentBlock
, verbatimEnvironments
and verbatimCommands
can now be specified in the formverbatimEnvironments:
nameAsRegex:
name: '\w+code\*?'
lookForThis: 1
lookForThis
field is optional, and if not present, will assumed to be 1
(this is consistent with other settings in the script)nameAsRegex
but it could be named as anything, for example, it could be named mintedalias
verbatimEnvironments:
mintedalias:
name: '\w+code\*?'
lookForThis: 1
\begin{pythoncode}...\end{pythoncode}
then the above YAML settings is equivalent toverbatimEnvironments:
pythoncode: 1
noIndentBlock
users can specify begin
and end
(both) or only name
:
noIndentBlock:
beginend:
begin: regex_begin
end: regex_end
body: regex_body # optional
nameonly:
name: regex_name
body: regex_body # optional
# the above is equivalent to the follows when `regex_name` does not contain `'*'` and body is omitted
regex_name: 1
# the followings are ignored
none: # incomplete settings, ignored
lookForThis: 1
beginonly: # incomplete settings, ignored
begin: regex_begin
endonly: # incomplete settings, ignored
end: regex_end
namebeginend: # conflict settings, ignored
begin: regex_begin
end: regex_end
name: regex_name
namebegin: # conflict settings, ignored
begin: regex_begin
name: regex_name
nameend: # conflict settings, ignored
end: regex_end
name: regex_name
Published by github-actions[bot] about 3 years ago
This release implements two new features:
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
.
-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-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 differentlatexindent.pl
will exit with 1
if the indented text is differentLet'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
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}
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}
Published by github-actions[bot] about 3 years ago
textWrap
This release implements an upgrade to textWrap
: in particular, a new feature beforeFindingChildCodeBlocks
to be
used with perCodeBlockBasis
.
This was implemented in relation to the issues raised in issue 158
and issue 228. Demonstrations are given within these threads, and are documented.
This has been implemented to create and publish latexindent.exe
automatically. Hopefully
more automated actions will follow.
Published by cmhughes about 3 years ago
from https://github.com/cmhughes/latexindent.pl/issues/85 starting with
\matrix {
c01 & c02 \\
c_{11} & c12 \\
}
gives, by default
\matrix {
c01 & c02 \\
c_{11} & c12 \\
}
from https://github.com/cmhughes/latexindent.pl/issues/162 starting with
\begin{align}
A & =\begin{array}{cc}
BBB & CCC\\
E & F
\end{array}\\
Z & =\begin{array}{cc}
Y & X\\
W & V
\end{array}
\end{align}
gives, by default,
\begin{align}
A & =\begin{array}{cc}
BBB & CCC \\
E & F
\end{array} \\
Z & =\begin{array}{cc}
Y & X \\
W & V
\end{array}
\end{align}
from https://github.com/cmhughes/latexindent.pl/issues/212 starting with
\begin{equation}
\begin{aligned}
x =& x^2 \mqty[a_{11} & a_{12} \\ a_{21} & a_{22}] =& f(x) \\
y =& f(y) =& y^2 \\
z =& f(z) =& z^2
\end{aligned}
\end{equation}
gives, by default,
\begin{equation}
\begin{aligned}
x = & x^2 \mqty[a_{11} & a_{12} \\ a_{21} & a_{22}] =& f(x) \\
y = & f(y) = & y^2 \\
z = & f(z) = & z^2
\end{aligned}
\end{equation}
from https://github.com/cmhughes/latexindent.pl/issues/251 starting with
\begin{tabular}{ll}
Testing & Line 1 \\
Testing & Line 2 \\
Testing & Line 3 \verb|X| \\
Testing & Line 4 \\
\end{tabular}
gives, by default,
\begin{tabular}{ll}
Testing & Line 1 \\
Testing & Line 2 \\
Testing & Line 3 \verb|X| \\
Testing & Line 4 \\
\end{tabular}
Published by cmhughes over 3 years ago
starting with
some before text
\href{Handbook%20for%30Spoken%40document.pdf}{my document}
some after text
and using
modifyLineBreaks:
textWrapOptions:
columns: 80
huge: overflow
all: 1
perCodeBlockBasis: 1
removeParagraphLineBreaks:
all: 1
fineTuning:
trailingComments:
notPreceededBy: '(?:(?<!Handbook)(?<!for)(?<!Spoken))'
then the output is (using -m switch):
some before text \href{Handbook%20for%30Spoken%40document.pdf}{my document} some after text
starting with
some before text
this code
won't
be touched
by
latexindent.pl!
some after text
and using
noIndentBlock:
demo:
begin: 'some\hbefore'
body: '.*?'
end: 'some\hafter\htext'
lookForThis: 1
gives the output
some before text
this code
won't
be touched
by
latexindent.pl!
some after text
Note that lookForThis
is optional in the noIndentBlock
field; default is 1.
Starting with
\begin{equation}
\begin{aligned}
& a = b, \\
& c = d.
\end{aligned}
\end{equation}
\begin{equation}
\begin{aligned}
a & = b, \\
c & = d.
\end{aligned}
\end{equation}
and using
defaultIndent: ' '
noAdditionalIndent:
aligned: 1
lookForAlignDelims:
aligned:
spacesBeforeAmpersand:
default: 2
leadingBlankColumn: 0
then the result is
\begin{equation}
\begin{aligned}
& a = b, \\
& c = d.
\end{aligned}
\end{equation}
\begin{equation}
\begin{aligned}
a & = b, \\
c & = d.
\end{aligned}
\end{equation}
The fields default
and leadingBlankColumn
both take integer values that represent the spaces to be added before ampersands. They are both optional.
Published by cmhughes over 3 years ago
A minor release that updates log file creation https://github.com/cmhughes/latexindent.pl/issues/145; in particular, users can specify, for example,
latexindent.pl -g /dev/null myfile.tex
so that the log file will not be created. Prior to this release, latexindent.pl
would fail if the log file could not be created.
The other minor tweak to the logging procedure is that the FATAL
method has been created, for situations in which latexindent
is called to act on files that do not exist.
Published by cmhughes over 3 years ago
A minor release to include the bugfix for the noindent
block bug reported at #266
Published by cmhughes over 3 years ago
Minor updates to documentation, details at https://github.com/cmhughes/latexindent.pl/issues/255 and https://github.com/cmhughes/latexindent.pl/issues/259
Minor updates to fineTuning:
keyEqualsValuesBracesBrackets
, https://github.com/cmhughes/latexindent.pl/issues/257 which means that, by default, keyEqualsValuesBracesBrackets
no longer begin with braces.namedGroupingBracesBrackets
, https://github.com/cmhughes/latexindent.pl/issues/258 now starts with a lower-case 'n' in fineTuning
so as to be consistent with its appearance elsewhere in defaultSettings.yaml
. As this was my mistake, LatexIndent/NamedGroupingBracesBrackets.pm
will read from NamedGroupingBracesBrackets
(note the upper-case 'N') and a warning is given to the logfile. I plan to support both fineTuning:namedGroupingBracesBrackets
and fineTuning:NamedGroupingBracesBrackets
for V3.*, but if V4.0 is created, then only namedGroupingBracesBrackets
will be supported. I recommend users migrate to namedGroupingBracesBrackets
Published by cmhughes over 3 years ago
Latexindent/Logger.pm
for implementation.Small enhancements:
localSettings.yaml
, it will also look for (in order): latexindent.yaml, .localSettings.yaml and .latexindent.yaml. Note that you don't need to have all 4, and that for most uses, just 1 of these files should be enough. As previously, using -l=myfile.yaml
will only load myfile.yaml
and now using -l=myfile.yaml+
will assume that you want to load as many of the following that exist: myfile.yaml, localSettings.yaml, latexindent.yaml, .localSettings.yaml, .latexindent.yaml
bug fixes:
Published by cmhughes almost 4 years ago
This is a minor release that implements fixes for the following issues:
The documentation has been updated with appropriate examples, including details of how to produce alignment such as the following:
\begin{tikzpicture}
\path (A) edge node {0,1,L}(B)
edge node {1,1,R} (C)
(B) edge [loop above] node {1,1,L}(B)
edge node {0,1,L}(C)
(C) edge node {0,1,L}(D)
edge [bend left] node {1,0,R}(E)
(D) edge [loop below] node {1,1,R}(D)
edge node {0,1,R}(A)
(E) edge [bend left] node {1,0,R} (A);
\end{tikzpicture}
and a patch to the textWrap
routine, so that spaces are preserved (or not) according to the new field tabstop
x y
Settings
modifyLineBreaks:
textWrapOptions:
columns: 80
tabstop: 9
Pull request, for reference: https://github.com/cmhughes/latexindent.pl/pull/227
Published by cmhughes over 4 years ago
Bug fix addressing the issue at https://github.com/cmhughes/latexindent.pl/issues/207