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

`CommaFinishesWithLineBreaks` in nested environments #520

Closed t-ober closed 5 months ago

t-ober commented 6 months ago

Hello everybody, I am absolutely clueless on how to get line breaks inside nested environments to work.

Most importantly I am tring to get th CommaFinishesWithLineBreaks command inside the nested axis environment to work. Bonus points for the line breaks and indentation of x tick label style.

Any help would be very very appreciated!

original .tex code

\begin{tikzpicture}[
    scale=1,node distance=1.5mm,
    ]
    \begin{axis}[
        width = 0.65\disswidth,height = 0.35\disswidth,
        x tick label style={/pgf/number format/fixed, /pgf/number format/precision=0},
    \end{axis}
\end{tikzpicture}

yaml settings

modifyLineBreaks:
    optionalArguments:
        CommaFinishesWithLineBreak: 1

actual/given output

\begin{tikzpicture}[
    scale=1,
    node distance=1.5mm,
    ]
    \begin{axis}[
        width = 0.65\disswidth,height = 0.35\disswidth,
        x tick label style={/pgf/number format/fixed, /pgf/number format/precision=0},
        ]
    \end{axis}
\end{tikzpicture}

desired or expected output

\begin{tikzpicture}[
    scale=1,
    node distance=1.5mm,
    ]
    \begin{axis}[
        width = 0.65\disswidth,
        height = 0.35\disswidth,
        x tick label style={
            /pgf/number format/fixed, 
            /pgf/number format/precision=0},
        ]
    \end{axis}
\end{tikzpicture}
cmhughes commented 6 months ago

Thanks for using the template :) I hope to get to this soon

t-ober commented 6 months ago

That would be great. Thanks!!

cmhughes commented 6 months ago

starting with (your code was missing a closing ])

\begin{tikzpicture}[
    scale=1,node distance=1.5mm,
    ]
    \begin{axis}[
        width = 0.65\disswidth,height = 0.35\disswidth,
    x tick label style={/pgf/number format/fixed, /pgf/number format/precision=0},]
    \end{axis}
\end{tikzpicture}

and using

defaultIndent: "   "

modifyLineBreaks:
    optionalArguments:
        CommaFinishesWithLineBreak: 1
    mandatoryArguments:
        CommaFinishesWithLineBreak: 1
        MandArgBodyStartsOnOwnLine: 1

gives

\begin{tikzpicture}[
      scale=1,
      node distance=1.5mm,
   ]
   \begin{axis}[
         width = 0.65\disswidth,
         height = 0.35\disswidth,
         x tick label style={
               /pgf/number format/fixed,
               /pgf/number format/precision=0},
      ]
   \end{axis}
\end{tikzpicture}
cmhughes commented 5 months ago

Let me know if you need anything else on this.