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

tabularray's cmidrule causes the conflict between "modifyLineBreaks" and "lookForAlignDelims" #426

Closed tatsy closed 1 year ago

tatsy commented 1 year ago

It seems that when I use \cmidrule command in tblr environment (of tabularray), the "lookForAlignDelims" does not work properly due to the conflict with "modifyLineBreaks".

I got the following output with the command:

latexindent main.tex -l -m -r

The versions of Perl and latexindent in my environment are:

Thank you in advance for your kind assistance.

original .tex code

\documentclass[10pt]{article}

\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}

\title{Hello}
\author{Hello}

\maketitle

\section{Table}

Hello world!
Hello world!

\begin{table}[t]
  \begin{tblr}{colspec={Q[c]Q[c]Q[c]Q[c]}}
    \toprule
    aaaaaa & bbbbb & ccc & dd \\
    \cmidrule[r]{1-1} \cmidrule{2-4}
    11 & 2 & 33 & 4 \\
    5 & 66 & 7 & 8 \\
    \bottomrule
  \end{tblr}
\end{table}

\end{document}

yaml settings

onlyOneBackup: 1
defaultIndent: "  "
removeTrailingWhiteSpace: 1

modifyLineBreaks:
  textWrapOptions:
    columns: 9999
    condenseMultipleBlankLinesInto: 1

lookForAlignDelims:
  tblr:
    delim: 1
    dontMeasure: largest

actual/given output

\documentclass[10pt]{article}

\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}

\title{Hello}
\author{Hello}

\maketitle

\section{Table}

Hello world! Hello world!

\begin{table}[t]
  \begin{tblr}{colspec={Q[c]Q[c]Q[c]Q[c]}}
    \toprule
    aaaaaa & bbbbb & ccc & dd \\
    \cmidrule[r]{1-1} \cmidrule{2-4}
    11 & 2 & 33 & 4          \\
    5  & 66 & 7  & 8          \\
    \bottomrule
  \end{tblr}
\end{table}

\end{document}

desired or expected output

\documentclass[10pt]{article}

\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}

\title{Hello}
\author{Hello}

\maketitle

\section{Table}

Hello world! Hello world!

\begin{table}[t]
  \begin{tblr}{colspec={Q[c]Q[c]Q[c]Q[c]}}
    \toprule
    aaaaaa & bbbbb & ccc & dd \\
    \cmidrule[r]{1-1} \cmidrule{2-4}
    11 & 2  & 33 & 4          \\
    5  & 66 & 7  & 8          \\
    \bottomrule
  \end{tblr}
\end{table}

\end{document}

anything else

When I remove \cmidrule from the above code, I could get the proper output as the following. Also, when I removed -m switch from my command, the table was formatted properly, though consecutive lines were not condensed into one.

\documentclass[10pt]{article}

\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}

\title{Hello}
\author{Hello}

\maketitle

\section{Table}

Hello world! Hello world!

\begin{table}[t]
  \begin{tblr}{colspec={Q[c]Q[c]Q[c]Q[c]}}
    \toprule
    aaaaaa & bbbbb & ccc & dd \\
    11 & 2  & 33 & 4          \\
    5  & 66 & 7  & 8          \\
    \bottomrule
  \end{tblr}
\end{table}

\end{document}
cmhughes commented 1 year ago

Thanks for this. I can confirm the behaviour. This is not intended.

I'll look into it and report back.

cmhughes commented 1 year ago

I think it's the combination of the dontMeasure and the -m switch.

tatsy commented 1 year ago

I agree with you that a bug is on the dontMeasure feature and think other features of lookForAlignDelims work fine as far as I checked. Thank you very much for your kind help.

cmhughes commented 1 year ago

Thanks again.

This is fixed and released as of https://github.com/cmhughes/latexindent.pl/releases/tag/V3.20.4. I'll get it uploaded to ctan next.

tatsy commented 1 year ago

@cmhughes Thank you very much for your kind help! I look forward to the new release.