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
884 stars 84 forks source link

Missing indent when path includes braces in tikz \graph #271

Closed zeertzjq closed 3 years ago

zeertzjq commented 3 years ago

Please provide the following when posting an issue:

original .tex code

\documentclass{article}
\begin{document}
\begin{tikzpicture}
  \graph {
    1 -> { 1, 2 };
  };
\end{tikzpicture}
\end{document}

yaml settings

3.9.3 default

actual/given output

\documentclass{article}
\begin{document}
\begin{tikzpicture}
    \graph {
    1 -> { 1, 2 };
    };
\end{tikzpicture}
\end{document}

desired or expected output

\documentclass{article}
\begin{document}
\begin{tikzpicture}
    \graph {
        1 -> { 1, 2 };
    };
\end{tikzpicture}
\end{document}

anything else

The problem doesn't occur if there are no braces in the path.

cmhughes commented 3 years ago

Hello, thanks for this. Can you take a look at https://latexindentpl.readthedocs.io/en/latest/sec-fine-tuning.html#lst-finetuning1-mod1 and see if that fixes it?

zeertzjq commented 3 years ago

I can't figure out what regex I have to set to arguments:between as literally everything can appear in \graph. I guess arguments:between is what can appear between { and }, but I'm not sure.

zeertzjq commented 3 years ago

Well, I guess PGF/TikZ is hard for latexindent to parse anyway as it is a different langauge. I'll add tikzpicture to verbatimEnvironments currently.

cmhughes commented 3 years ago

Try starting with https://latexindentpl.readthedocs.io/en/latest/sec-fine-tuning.html#lst-fine-tuning1

cmhughes commented 3 years ago

Any luck with this?

zeertzjq commented 3 years ago

The following configuration seems to work:

fineTuning:
  arguments:
    before: '(?:#\d\h*;?,?\/?)+|\<.*?\>|\-\-|\->|in'

The in makes indentation correct after \foreach ... in

cmhughes commented 3 years ago

Great, nicely done!