Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined behavior when formatting vertically aligned multicolumn commands with different column spans #143

Closed
douglasrizzo opened this issue Oct 16, 2018 · 11 comments

Comments

@douglasrizzo
Copy link

@douglasrizzo douglasrizzo commented Oct 16, 2018

Hi there. I'd like some clarification regarding the behavior of the multiColumnGrouping: 1 option with a particular example I have. I have the following tabular environment, whose columns I have aligned by hand in a way that looks sensible to me:

\begin{tabular}{cc|c||c|c}
    \multicolumn{3}{c||}{\textbf{Exploração Fácil}}                      & \multicolumn{2}{c}{\textbf{Exploração Difícil}}         \\
    \multicolumn{2}{c|}{\emph{Ótimo humano}} & \emph{Abuso da pontuação} & \emph{Recompensas densas} & \emph{Recompensas esparsas} \\
    \hline
    Assault     & Asterix                    & Beam Rider                & Alien                     & Freeway                     \\
    Asteroids   & Atlantis                   & Kangaroo                  & Amidar                    & Gravitar                    \\
    Battle Zone & Berzerk                    & Krull                     & Bank Heist                & Montezuma's Revenge         \\
    Bowling     & Boxing                     & Kung Fu Master            & Frostbite                 & Pitfall                     \\
    Breakout    & Centipede                  & Road Runner               & H E R O                   & Private Eye                 \\
    Chopper Cmd & Crazy Climber              & Seaquest                  & Ms Pac Man                & Solaris                     \\
    Defender    & Demon Attack               & Up N Down                 & Q Bert                    & Venture                     \\
    \hline
\end{tabular}

However, when I use latexindent in this file, it aligns my columns like so:

\begin{tabular}{cc|c||c|c}
    \multicolumn{3}{c||}{\textbf{Exploração Fácil}}         & \multicolumn{2}{c}{\textbf{Exploração Difícil}}                                             \\
    \multicolumn{2}{c|}{\emph{Ótimo humano}}        & \emph{Abuso da pontuação}                 & \emph{Recompensas densas} & \emph{Recompensas esparsas} \\
    \hline
    Assault     & Asterix                    & Beam Rider                & Alien                     & Freeway                                            \\
    Asteroids   & Atlantis                   & Kangaroo                  & Amidar                    & Gravitar                                           \\
    Battle Zone & Berzerk                    & Krull                     & Bank Heist                & Montezuma's Revenge                                \\
    Bowling     & Boxing                     & Kung Fu Master            & Frostbite                 & Pitfall                                            \\
    Breakout    & Centipede                  & Road Runner               & H E R O                   & Private Eye                                        \\
    Chopper Cmd & Crazy Climber              & Seaquest                  & Ms Pac Man                & Solaris                                            \\
    Defender    & Demon Attack               & Up N Down                 & Q Bert                    & Venture                                            \\
    \hline
\end{tabular}

Personally, I believe the first example is the correct one, not the second. Maybe I could get an explanation as to why latexindent prefers the second indentation? I can't see to find the logic behind it. The only customization I did to my config file is the addition of the following:

lookForAlignDelims:
tabular: 
    multiColumnGrouping: 1
@cmhughes

This comment has been minimized.

Copy link
Owner

@cmhughes cmhughes commented Oct 16, 2018

Thanks for this. I hope to take a look at it soon. I'll report back ....

@douglasrizzo

This comment has been minimized.

Copy link
Author

@douglasrizzo douglasrizzo commented Oct 17, 2018

No rush @cmhughes, it doesn't break anything and everything else is formatted accordingly. I just found it weird so I thought it better to report.
Maybe the column delimiters I use, like | and ||, or the fact that I use \textbf or \emph inside \multicolumn is what's confusing latexindent?

@cmhughes

This comment has been minimized.

Copy link
Owner

@cmhughes cmhughes commented Oct 20, 2018

Thanks for this. I agree that your first input would be desired.

I believe that it's the appearance of two different multicolumn commands that have different 'spannings' (3 and 2) which confuses things. I don't think that the | or \texbf, \emph affect this.

I'll leave this open as it needs further attention, but I can't commit to investigating immediately. I'll report back at some point with updates.

@cmhughes

This comment has been minimized.

Copy link
Owner

@cmhughes cmhughes commented Nov 3, 2018

Thanks for this, I'm going to label it as a bug, as the current behaviour is clearly not desirable. I hope to be able to address this, but I'm not sure when that will be. Thanks again.

@cmhughes cmhughes added the bug label Nov 3, 2018
@douglasrizzo

This comment has been minimized.

Copy link
Author

@douglasrizzo douglasrizzo commented Nov 29, 2018

I now understand what you mean. When we have a column in our tabular environment which has intersecting multicolumn commands, each of which spans different numbers of columns, this behavior emerges.

I am uploading a file which has a few examples of tables that show this kind of behavior. Extension is txt because GitHub. I used the first example as a control, so it should work fine.

@douglasrizzo douglasrizzo changed the title Clarification regarding the behavior of multiColumnGrouping Undefined behavior when formatting vertically aligned multicolumn commands with different column spans Nov 29, 2018
@cmhughes

This comment has been minimized.

Copy link
Owner

@cmhughes cmhughes commented Dec 1, 2018

Thanks a lot, very helpful.

I hope to take a look at this soon . Everything is a bit delayed as I'm slammed at work, but is hope to be able to look at this by early 2019....

@cmhughes

This comment has been minimized.

Copy link
Owner

@cmhughes cmhughes commented Jul 16, 2019

Just to say: sorry for the delay in addressing this. It's very near (or at!) the top of my latexindent.pl priorities :)

@douglasrizzo

This comment has been minimized.

Copy link
Author

@douglasrizzo douglasrizzo commented Jul 19, 2019

Hey @cmhughes glad to know you didn't forget about my issue.

Just a heads-up. In one of my most recent documents, I had to add line breaks inside cells of the tabular environment. I ended up resorting to this method, which adds a nested tabular environment inside the cell we want to add line breaks to.

I saw that you labelled my issue as align-at-ampersand-routine so I thought I'd warn you that, sometimes, people use nested environments and if these environments make use of ampersands to align their content, then you may have to check whether each ampersand relates to the inner or outer environments. I don't think this is directly related to my issue, but maybe this is related to #162.

cmhughes added a commit that referenced this issue Mar 1, 2020
issue reported at #143

To do: see test-cases/alignment/douglasrizzo1.tex when run with multiColumnGrouping.yaml
and then return to the more complicated version in the original issue,
above. Then ensure all test-cases behave as expected
cmhughes added a commit that referenced this issue Mar 8, 2020
Next:
  - make sure that test cases behave as desired.
  - can the multicolumn loops be optimised?
@cmhughes

This comment has been minimized.

Copy link
Owner

@cmhughes cmhughes commented Mar 9, 2020

Thanks again for this. As of 8f7836a the develop branch contains an over-hauled version of the align-at-ampersand routine.

Starting with the file you gave

\begin{tabular}{cc|c||c|c}
    \multicolumn{3}{c||}{\textbf{Exploração Fácil}}         & \multicolumn{2}{c}{\textbf{Exploração Difícil}}                                             \\
    \multicolumn{2}{c|}{\emph{Ótimo humano}}        & \emph{Abuso da pontuação}                 & \emph{Recompensas densas} & \emph{Recompensas esparsas} \\
    \hline
    Assault     & Asterix                    & Beam Rider                & Alien                     & Freeway                                            \\
    Asteroids   & Atlantis                   & Kangaroo                  & Amidar                    & Gravitar                                           \\
    Battle Zone & Berzerk                    & Krull                     & Bank Heist                & Montezuma's Revenge                                \\
    Bowling     & Boxing                     & Kung Fu Master            & Frostbite                 & Pitfall                                            \\
    Breakout    & Centipede                  & Road Runner               & H E R O                   & Private Eye                                        \\
    Chopper Cmd & Crazy Climber              & Seaquest                  & Ms Pac Man                & Solaris                                            \\
    Defender    & Demon Attack               & Up N Down                 & Q Bert                    & Venture                                            \\
    \hline
\end{tabular}

and running

latexindent.pl myfile.tex -y="lookForAlignDelims:tabular:multiColumnGrouping:1"

then you receive

\begin{tabular}{cc|c||c|c}
	\multicolumn{3}{c||}{\textbf{Exploração Fácil}}                      & \multicolumn{2}{c}{\textbf{Exploração Difícil}}         \\
	\multicolumn{2}{c|}{\emph{Ótimo humano}} & \emph{Abuso da pontuação} & \emph{Recompensas densas} & \emph{Recompensas esparsas} \\
	\hline
	Assault     & Asterix                    & Beam Rider                & Alien                     & Freeway                     \\
	Asteroids   & Atlantis                   & Kangaroo                  & Amidar                    & Gravitar                    \\
	Battle Zone & Berzerk                    & Krull                     & Bank Heist                & Montezuma's Revenge         \\
	Bowling     & Boxing                     & Kung Fu Master            & Frostbite                 & Pitfall                     \\
	Breakout    & Centipede                  & Road Runner               & H E R O                   & Private Eye                 \\
	Chopper Cmd & Crazy Climber              & Seaquest                  & Ms Pac Man                & Solaris                     \\
	Defender    & Demon Attack               & Up N Down                 & Q Bert                    & Venture                     \\
	\hline
\end{tabular}

This will be part of the next release. Thanks again!

@cmhughes cmhughes added the implemented label Mar 9, 2020
@douglasrizzo

This comment has been minimized.

Copy link
Author

@douglasrizzo douglasrizzo commented Mar 9, 2020

That's great! I'll make sure to do some testing when I write my next TeX document. I imagine it was rather complicated to implement.

@cmhughes

This comment has been minimized.

Copy link
Owner

@cmhughes cmhughes commented Mar 21, 2020

Implemented in Version 3.8, #190

@cmhughes cmhughes closed this Mar 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.