cmhughes / latexindent.pl

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.
GNU General Public License v3.0
894 stars 84 forks source link

Constructs like `{a}_{{b}}` prevent correct parsing of mandatory arguments #563

Open torik42 opened 2 months ago

torik42 commented 2 months ago

For some reason, mandatory arguments containing constructs like {a}_{{b}} or {a}^{{b}} are not recognized properly. Neither for indentation nor for line breaks. Unfortunately, this happens quite regularly in math material. (I also add a more realistic example, as for me the mechanism is not yet clear.)

Example for indentation

% 1-input.tex
\cmd{
    {a}_{{b}}
}

\cmd{
    {a}^{{b}}
}

\cmd{
    {a}_{b}
}

\cmd{
    \othercmd{a}_{b_{c}}
}

with

latexindent.pl 1-input.tex -o=1-output.tex

gives

% 1-output.tex
\cmd{
{a}_{{b}}
}

\cmd{
{a}^{{b}}
}

\cmd{
    {a}_{b}
}

\cmd{
\othercmd{a}_{b_{c}}
}

but I expect the first two commands to be indented as the third one which is there for comparison

% 1-expected.tex
\cmd{
    {a}_{{b}}
}

\cmd{
    {a}^{{b}}
}

\cmd{
    {a}_{b}
}

\cmd{
    \othercmd{a}_{b_{c}}
}

For some reason, without \othercmd, the last example is indented correctly. But one can put more additional commands and it still fails.

Example for modifylinebreaks

% 2-input.tex
\cmd{{a}^{{b}}}

\cmd{{a}^{b}}
# 2-config.yaml
modifyLineBreaks:
  mandatoryArguments:
    cmd:
      MandArgBodyStartsOnOwnLine: 1
      RCuBStartsOnOwnLine: 1

upon running

latexindent.pl -m 2-input.tex -l=2-config.yaml -o=2-output.tex 

produces

% 2-output.tex
\cmd{{a}^{{b}}}

\cmd{
    {a}^{b}
}

while I expect

% 2-expected.tex
\cmd{
    {a}^{{b}}
}

\cmd{
    {a}^{b}
}
cmhughes commented 1 month ago

Apologies for the delay I'm hoping to get to this soon