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

the future of multirows in _tabularray_ package would let latexindent format the code incorrectly #543

Open Mikachu2333 opened 3 months ago

Mikachu2333 commented 3 months ago

When using the tabularray package to merge cells (multiple rows), latexindent always incorrectly recognizes multiple rows cells.

MWE (After formatted)

\documentclass{ctexrep}%Chinese report
\usepackage{tabularray}%tabular

\begin{document}
\begin{tblr}{
        cells={c,m},
        hlines,
        vlines,
    }
    AAAAAAA & BBBBBBB \\
    c       & {f      \\g} \\ %multirows
    d       & h       \\
    e       & {i      \\j}    %multirows
\end{tblr}
\end{document}

yaml settings

No changes have been made except defaultindent: 4spaces. Others have no impact on the results.

actual/given output

Success with no error pkZrYy8.jpg

desired or expected output

\documentclass{ctexrep}%Chinese report
\usepackage{tabularray}%tabular

\begin{document}
\begin{tblr}
    {
    cells={c,m},
    hlines,
    vlines,
    }
    AAAAAAA & BBBBBBB \\
    c       & {f      \\
          g}      \\
    d       & h       \\
    e       & {i      \\
              j}
\end{tblr}
\end{document}
cmhughes commented 3 months ago

The actual/given output should be tex code, not a screen shot.

Mikachu2333 commented 3 months ago

The actual/given output should be tex code, not a screen shot.

The MWE is also what latexindent output show.

cmhughes commented 3 months ago

latexindent gives text output, not images

On Fri, 10 May 2024, 12:51 Mikachu2333, @.***> wrote:

The actual/given output should be tex code, not a screen shot.

The MWE is also what latexindent output show.

— Reply to this email directly, view it on GitHub https://github.com/cmhughes/latexindent.pl/issues/543#issuecomment-2104474255, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ7CYAOOPXGV57JBG6YVFDZBSYF5AVCNFSM6AAAAABHQOM2FOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBUGQ3TIMRVGU . You are receiving this because you commented.Message ID: @.***>

Mikachu2333 commented 3 months ago
[13:08:15.182][Format][TeX] Start formatting with latexindent.
[13:08:15.182][Format][TeX] Checking latexindent: which latexindent
[13:08:15.187][Format][TeX] Checking latexindent is ok: /usr/local/texlive/2024/bin/x86_64-linux/latexindent

[13:08:15.188][Format][TeX] Formatting LaTeX. The command is latexindent:["--cruft=%WS1%/","%WS1%/__latexindent_temp_main.tex","--modifylinebreaks","--GCString","--yaml=defaultIndent: '    '"].
[13:08:15.311][Format][TeX] Formatted %WS1%/main.tex

Latex output after latexindent formatted.

\documentclass{ctexrep}%Chinese report
\usepackage{tabularray}%tabular

\begin{document}
\begin{tblr}
    {
        cells={c,m},
        hlines,
        vlines,
    }
    AAAAAAA & BBBBBBB \\
    c       & {f      \\
    g}                \\
    d       & h       \\
    e       & {i
    \\j}
\end{tblr}
\end{document}
cmhughes commented 3 months ago

When I start with

\documentclass{ctexrep}%Chinese report
\usepackage{tabularray}%tabular

\begin{document}
\begin{tblr}{
        cells={c,m},
        hlines,
        vlines,
    }
    AAAAAAA & BBBBBBB \\
    c       & {f      \\g} \\ %multirows
    d       & h       \\
    e       & {i      \\j}    %multirows
\end{tblr}
\end{document}

and run

latexindent.pl myfile.tex

then I receive

\documentclass{ctexrep}%Chinese report
\usepackage{tabularray}%tabular

\begin{document}
\begin{tblr}{
        cells={c,m},
        hlines,
        vlines,
    }
    AAAAAAA & BBBBBBB \\
    c       & {f      \\g} \\ %multirows
    d       & h       \\
    e       & {i      \\j}    %multirows
\end{tblr}
\end{document}

which is what I would expect.

Mikachu2333 commented 3 months ago

I apologize for not understanding what you said and answering irrelevantly.

What i input

\documentclass{ctexrep}%Chinese report
\usepackage{tabularray}%tabular

\begin{document}
\begin{tblr}{
        cells={c,m},
        hlines,
        vlines,
    }
    AAAAAAA & BBBBBBB \\
    c       & {g\\h}  \\ %multirows (g&h)
    d       & i       \\
    {e\\f}  & j          %multirows (e&f)
\end{tblr}
\end{document}

Command I use

latexindent main.tex --modifylinebreaks --GCString --yaml=defaultIndent: '    '

Latexindent output

(Success without error or warning as yours)

\documentclass{ctexrep}%Chinese report
\usepackage{tabularray}%tabular

\begin{document}
\begin{tblr}
    {
        cells={c,m},
        hlines,
        vlines,
    }
    AAAAAAA & BBBBBBB \\
    c       & {g      \\h}  \\
    d       & i       \\
    {e                \\f}       & j
\end{tblr}
\end{document}

BUT What I want

(Same as what i input, want latexindent understand the multirow style cell and normal cell)

\documentclass{ctexrep}%Chinese report
\usepackage{tabularray}%tabular

\begin{document}
\begin{tblr}{
        cells={c,m},
        hlines,
        vlines,
    }
    AAAAAAA & BBBBBBB \\
    c       & {g\\h}  \\ %multirows (g&h)
    d       & i       \\
    {e\\f}  & j          %multirows (e&f)
\end{tblr}
\end{document}
cmhughes commented 3 months ago

Thanks, that's clear.

I think we need a new feature to specify the double back slash regex within each lookForAlignDelims field.

Leave it with me, I hope to get to it soon, but time is pressured for me at the moment.

Mikachu2333 commented 3 months ago

Thanks for timely answer!

Please prioritize your own tasks. This issue is just a improvement, not an extremely harmful crash or bug, there's no need to rush to finish it.

Mikachu2333 commented 1 month ago

RE-Update:

Still unresolved when the last line contains multirows although the command below has been used
lookForAlignDelims:tblr:alignFinalDoubleBackSlash: 1


Original/After formatted

\begin{tblr}[
        long
    ]{
        vlines,
        hlines,
    }
    {A & Z} & B \\ %multirow
    C  & {D     \\E} %multirow
\end{tblr}

What I want

\begin{tblr}[
        long
    ]{
        vlines,
        hlines,
    }
    {A & Z} & B       \\ %multirow
    C       & {D \\E} %multirow
\end{tblr}

YAML

modifyLineBreaks:
  condenseMultipleBlankLinesInto: 2
  optionalArguments:
    tblr:
      OptArgBodyStartsOnOwnLine: 1 # -1,0,1,2,3,4

lookForAlignDelims:
  tblr:
    alignFinalDoubleBackSlash: 1
    #dontMeasure: largest
    multiColumnGrouping: 1

fineTuning:
  keyEqualsValuesBracesBrackets:
    name: |-
      (?x)
      [a-zA-Z@\*0-9_\/.:\#-]+
      (?:
        [a-zA-Z@\*0-9_\/.\h:\#-]
        \{
          [a-zA-Z@\*0-9_\/.\h:\#-,]+?
        \}
      )*?
defaultIndent: "    "
Mikachu2333 commented 1 week ago

RE-Re-update: Add some examples.

MWE (After formatted):

% !TeX encoding = UTF-8
% !TEX TS-program = lualatex
\documentclass[a4paper,12pt]{ctexrep}
\usepackage{hyperref}
\usepackage{tabularray}

\begin{document}
\begin{table}
    \centering
    \begin{tblr}[
        tall,
        note{$\dag$} = {Comment for tblr.},
        ]{
        hlines,vlines,
        cells={c,m},
        row{1,3} = {10ex},
                row{7} = {7ex},
            }
            {%
        \href{127.0.0.1}{row1 line1}     \\
        \href{127.0.0.1}{row1 line2}     \\
                \href{127.0.0.1}{row1 line3}%
        }                                \\
        {row2 line4}\TblrNote{$\dag$}    \\
        {%
        \href{127.0.0.1}{row3 line5 (1)}、% This is because the line is too long to edit so i use "%" to break it.
        \href{127.0.0.1}{row3 line5 (2)} \\
        \href{127.0.0.1}{%This is becasue the content of the cell is too long to be indented.
            row 3 line6 (1) longlong%
            longlonglonglonglong%
        }、%
        \href{127.0.0.1}{row3 line6 (2)} \\
        \href{127.0.0.1}{%
            row3 line7}%
        }                                \\
        {row4 line8}                     \\
        {%
        {%
                \href{127.0.0.1}{row5 line9}%
            }
        }                                \\
    \end{tblr}
\end{table}
\end{document}

Latexindent output info and Args I use:

log

[18:29:06.836][Format][TeX] Start formatting with latexindent.
[18:29:06.838][Format][TeX] Formatting LaTeX. The command is latexindent:["-c=%WS1%/","%WS1%/__latexindent_temp_main.tex","-m","--GCString"].
[18:29:06.942][Format][TeX] Formatted %WS1%/main.tex

args

All default except --GCString arg

What I want:

% !TeX encoding = UTF-8
% !TEX TS-program = lualatex
\documentclass[a4paper,12pt]{ctexrep}
\usepackage{hyperref}
\usepackage{tabularray}

\begin{document}
\begin{table}
    \centering
    \begin{tblr}[
            tall,
            note{$\dag$} = {Comment for tblr.},
        ]{
            hlines,vlines,
            cells={c,m},
            row{1,3} = {10ex},
            row{7} = {7ex},
        }
        {%
            \href{127.0.0.1}{row1 line1}     \\
            \href{127.0.0.1}{row1 line2}     \\
            \href{127.0.0.1}{row1 line3}%
        }                                \\
        {row2 line4}\TblrNote{$\dag$}    \\
        {%
            \href{127.0.0.1}{row3 line5 (1)}、% This is because the line is too long to edit so i use "%" to break it.
            \href{127.0.0.1}{row3 line5 (2)} \\
            \href{127.0.0.1}{%This is becasue the content of the cell is too long to be indented.
                row 3 line6 (1) longlong%
                longlonglonglonglong%
            }、%
            \href{127.0.0.1}{row3 line6 (2)} \\
            \href{127.0.0.1}{%
                row3 line7}%
        }                                \\
        {row4 line8}                     \\
        {%
            {%
                \href{127.0.0.1}{row5 line9}%
            }
        }                                \\
    \end{tblr}
\end{table}
\end{document}