2

Latexindent fails to properly indent this code (it removes all indentation, when it should rather leave the indentation alone, or minimally modify it at least).

\ExplSyntaxOn
\newcommand*{\fixcref}{
    % Allow spaces in `cref` command.
    \cs_set_eq:Nc \bers_cref:nn { @cref }
    \cs_generate_variant:Nn \bers_cref:nn { nx }
    \cs_set_protected:cpn { @cref } ##1 ##2
        {
            \seq_set_split:Nnn \l_bers_cref_seq { , } { ##2 }
            \bers_cref:nx { ##1 } { \seq_use:Nn \l_bers_cref_seq { , } }
        }
    \seq_new:N \l_bers_cref_seq
}
\ExplSyntaxOff
Noldorin
  • 890
  • It seems the combination of ##1 ##2 and the single { on the next line creates the problem. With regular arguments (#1 #2) or something else on the next line (\a{ for example) the indentation is ok. Looks like a bug, maybe you can post an issue in the issue tracker. – Marijn Feb 03 '21 at 08:03
  • @Marijn Thanks. What would the work-around be for now, i.e., somehow telling latexindent to not bother formatting this block? – Noldorin Feb 03 '21 at 11:45
  • If you are willing to modify the code then you can add %\begin{noindent} and %\end{noindent} around the command, this will stop Latexindent from formatting it. – Marijn Feb 03 '21 at 12:54
  • @Marijn Thanks. I'll do that for the time being. – Noldorin Feb 03 '21 at 13:04
  • 1
    Resolved on issue tracker :) – cmhughes Feb 03 '21 at 14:28

1 Answers1

2

I ended up opening a GitHub issue for this, and @cmhughes, the author of latexindent, kindly got back to me promptly. He provided a fix for the time being, and also indicated that he would be incorporating this into the future default settings for latexindent.

For the time being, add this to your localSettings.yaml. It allows "escaped" arguments of the form ##1 between braces.

commandCodeBlocks:
    stringsAllowedBetweenArguments:
      - 
        amalgamate: 1
      - '\#\#\d' 
cmhughes
  • 100,947
Noldorin
  • 890
  • no need for the addition to localSettings.yaml as of V3.9 (https://github.com/cmhughes/latexindent.pl/releases/tag/V3.9) – cmhughes Jul 22 '21 at 06:23