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

latexindent feature that ignore table headings when using alignDoubleBackSlash and delims in lookForAlignDelims under tabular #182

Closed
yangmw opened this issue Jan 16, 2020 · 14 comments
Labels
align-at-ampersand-routine the align at ampersand; documented in lookForAlignDelims enhancement enhancement which might be to an existing feature or the development of a new feature feature-request user-centred feature request for an enhancement to an existing feature, or for a new feature implemented implemented tag means that either an enhancement or feature request has been implemented, or bugfix

Comments

@yangmw
Copy link

yangmw commented Jan 16, 2020

I encountered an issue, whenever my table headings becomes longer then the table items their Ampersand aligns with huge spaces in between my table items like this:

\begin{table}[htbp]
	\centering
	\caption{Add caption}
	\begin{tabular}{rrrrrrr}
		\toprule
		\multicolumn{1}{c}{Expiry} & Tenor & \multicolumn{1}{c}{$\Delta_{\text{call},10}$} & \multicolumn{1}{c}{$\Delta_{\text{call},25}$} & \multicolumn{1}{c}{$\Delta_{\text{call},50}$} & \multicolumn{1}{c}{$\Delta_{\text{call},75}$} & \multicolumn{1}{c}{$\Delta_{\text{call},90}$} \\
		\midrule
		                30-03-2016 &    1D &                                        -2E-14 &                                        -2E-14 &                                         3E-14 &                                        -8E-14 &                                        -7E-14 \\
		                05-04-2016 &    1W &                                        -4E-15 &                                        -1E-14 &                                         1E-14 &                                        -6E-15 &                                        -1E-14 \\
		                12-04-2016 &    2W &                                         3E-15 &                                         1E-14 &                                         1E-14 &                                        -3E-14 &                                        -2E-14 \\
		                27-04-2016 &    1M &                                        -2E-16 &                                        -2E-15 &                                        -1E-14 &                                        -7E-15 &                                        -2E-15 \\
		                27-05-2016 &    2M &                                         2E-15 &                                         7E-15 &                                         2E-15 &                                        -4E-15 &                                         4E-15 \\
		                28-06-2016 &    3M &                                        -4E-15 &                                         3E-16 &                                        -4E-15 &                                        -2E-15 &                                        -8E-15 \\
		                28-09-2016 &    6M &                                         1E-16 &                                         3E-16 &                                             0 &                                        -2E-15 &                                        -5E-15 \\
		                28-12-2016 &    9M &                                         1E-16 &                                         1E-15 &                                         2E-15 &                                         8E-15 &                                        -3E-15 \\
		                29-03-2017 &    1Y &                                         2E-16 &                                         2E-15 &                                         5E-15 &                                         1E-14 &                                         2E-14 \\
		                27-03-2018 &    2Y &                                         1E-15 &                                         7E-16 &                                        -2E-15 &                                         3E-16 &                                         5E-15 \\
		                27-03-2019 &    3Y &                                        -2E-16 &                                         1E-15 &                                        -6E-16 &                                        -2E-15 &                                        -4E-15 \\
		                27-03-2020 &    4Y &                                        -2E-16 &                                         1E-16 &                                         5E-16 &                                        -2E-16 &                                        -8E-15 \\
		                29-03-2021 &    5Y &                                         2E-16 &                                        -4E-16 &                                             0 &                                        -2E-15 &                                        -2E-15 \\
		\bottomrule
	\end{tabular}%
	\label{tab:addlabel}%
\end{table}%

The settings in the .yaml is:

lookForAlignDelims:
   tabular: 
      delims: 1
      alignDoubleBackSlash: 1
      spacesBeforeDoubleBackSlash: 1
      multiColumnGrouping: 0
      alignRowsWithoutMaxDelims: 0
      spacesBeforeAmpersand: 1
      spacesAfterAmpersand: 1
      justification: "right"

Is it possible for latexindent to ignore table headings? Then it would be very nice like this:

\begin{table}[htbp]
	\centering
	\caption{Add caption}
	\begin{tabular}{rrrrrrr}
	       \toprule
	       \multicolumn{1}{c}{Expiry} & Tenor & \multicolumn{1}{c}{$\Delta_{\text{call},10}$} & \multicolumn{1}{c}{$\Delta_{\text{call},25}$} & \multicolumn{1}{c}{$\Delta_{\text{call},50}$} & \multicolumn{1}{c}{$\Delta_{\text{call},75}$} & \multicolumn{1}{c}{$\Delta_{\text{call},90}$} \\
	       \midrule
	       30-03-2016 & 1D & -2E-14 & -3E-14 &  1E-14 & -8E-14 & -1E-14 \\
	       05-04-2016 & 1W & -0E-15 & -4E-14 &  2E-14 & -5E-15 & -5E-14 \\
	       12-04-2016 & 2W &  9E-15 &  5E-14 &  3E-14 & -3E-14 & -6E-14 \\
	       27-04-2016 & 1M & -8E-16 & -6E-15 & -4E-14 & -4E-15 & -7E-15 \\
	       27-05-2016 & 2M &  7E-15 &  7E-15 &  5E-15 & -4E-15 &  8E-15 \\
	       28-06-2016 & 3M & -6E-15 &  8E-16 & -6E-15 & -3E-15 & -1E-15 \\
	       28-09-2016 & 6M &  5E-16 &  9E-16 &      0 & -2E-15 & -2E-15 \\
	       28-12-2016 & 9M &  4E-16 &  2E-15 &  7E-15 &  8E-15 & -3E-15 \\
	       29-03-2017 & 1Y &  3E-16 &  1E-15 &  8E-15 &  2E-14 &  4E-14 \\
	       27-03-2018 & 2Y &  2E-15 &  4E-16 & -9E-15 &  3E-16 &  5E-15 \\
	       27-03-2019 & 3Y & -1E-16 &  5E-15 & -1E-16 & -2E-15 & -6E-15 \\
	       27-03-2020 & 4Y & -9E-16 &  6E-16 &  3E-16 & -2E-16 & -7E-15 \\
	       29-03-2021 & 5Y &  8E-16 & -7E-16 &      0 & -2E-15 & -9E-15 \\
	       \bottomrule
	\end{tabular}%
	\label{tab:addlabel}%
\end{table}%

Best wishes,

Yang.

@cmhughes cmhughes added align-at-ampersand-routine the align at ampersand; documented in lookForAlignDelims feature-request user-centred feature request for an enhancement to an existing feature, or for a new feature enhancement enhancement which might be to an existing feature or the development of a new feature labels Jan 16, 2020
@swaroopguggilam
Copy link

As per our discussion, posting my request which is similar to above one, here,

Firstly, thanks for this file, its really helpful.
Following is my problem:

\begin{alignat}{2}
    & asdfasdfadsaaaaaaaaaaadsaaaaaaaaaaaaaaaaaaaaaaasdfffffffffffffffffffff & & temp       \\
    &                                                                                     & & tempasdfasdf                                    \\
\end{alignat}

After I format it using latexindent.pl, all the & align, but I don't want that, because as one of my word is very long, its affecting the visibility of all the rows in my latex file.
Current Output:

\begin{alignat}{2}
    & asdfasdfadsaaaaaaaaaaadsaaaaaaaaaaaaaaaaaaaaaaasdfffffffffffffffffffff & & temp \\
    &                                                                        & & tempasdfasdf \\
\end{alignat}

Required Output:

\begin{alignat}{2}
    & asdfasdfadsaaaaaaaaaaadsaaaaaaaaaaaaaaaaaaaaaaasdfffffffffffffffffffff & & temp \\
    & & & tempasdfasdf \\
\end{alignat}

Is there an option to do this? (I want something similar to \ (alignDoubleBackSlash: 0))

This is kind of similar to above request, but would still highlight following differences:

  1. That one particularly focus on ignoring table headings, mine is in general ampersand signs
  2. Mine above is under equations (alignat) and not tables, but I believe same command can be used for different type of blocks across latex like your other features.
    Basically "Dont align at & routine or a variable to set this false" would be very helpful.
    Thank you.

@cmhughes
Copy link
Owner

cmhughes commented Mar 9, 2020

Here's my current thinking on how the YAML for this might look:

# option 1 (nothing happens, default)
lookForAlignDelims:
    dontMeasure: 0

# option 2 (largest cell in each column is not counted for alignment)
lookForAlignDelims:
    dontMeasure: largest

# option 3 (user specifies specific strings to be ignored)
lookForAlignDelims:
    dontMeasure: 
        - \multicolumn{1}{c}{Expiry}
        - \multicolumn{1}{c}{$\Delta_{\text{call},10}$}

# option 4 (user specifies either a string or a regex to be ignored, either on a cell or row basis)
lookForAlignDelims:
    dontMeasure: 
    -
        this: \multicolumn{1}{c}{Expiry}
        applyTo: cell
    -
        regex: \\multicolumn\{\d\}\{.\}\{.*?\}
        applyTo: row

Please note: the above is not a commitment to this interface, but reflects my current thinking. Feel free to input :)

@yangmw
Copy link
Author

yangmw commented Mar 9, 2020

Hi, I like the last option 4 :)

@cmhughes
Copy link
Owner

cmhughes commented Mar 9, 2020

I'm hoping to allow all of the above options to be valid :)

@swaroopguggilam
Copy link

swaroopguggilam commented Mar 9, 2020

Thanks Chris for the update,
I like your idea.
I just have one question, does this solves the issue I mentioned? "About not aligning at &"? If yes, then what would be command/setting once you implement it?
To elaborate: I understand that option 2 will ignore only the largest, what if there are varying lengths data in the column.
Option 3 is specific strings.
I believe using regex in option 4, is the close resemblance to my need. How do I apply option 4 for entire set of equations in the "alignat"?

@cmhughes
Copy link
Owner

cmhughes commented Mar 9, 2020 via email

@yangmw
Copy link
Author

yangmw commented Mar 9, 2020

That would be even better! Thank you for doing this!
And when you are done, could you also update the latexindent.exe file in https://ctan.org/tex-archive/support/latexindent :)

cmhughes added a commit that referenced this issue Mar 10, 2020
…ent the 'largest' option (option 2 in the link) and then documentation
@cmhughes
Copy link
Owner

@yangmw @swaroopguggilam if you'd like to experiment, I've started a new branch as of f3e60ed

You'll see that option 1, 3 and 4 are now available. I need to work on option 2, next. So far, it looks optimistic.

You'll need to clone the https://github.com/cmhughes/latexindent.pl/tree/feature/dontMeasure branch, which is experimental at this time!

@yangmw
Copy link
Author

yangmw commented Mar 10, 2020

Excellent Chris! Thank you, I look forward to try it tomorrow.

@swaroopguggilam
Copy link

Thanks Chris, will try out this weekend and let you know.

@cmhughes
Copy link
Owner

All of the options detailed above are now implemented and documented in the develop branch, as of e6bb29c.

Feel free to test and let me know. For the moment, I'm going to label this as implemented.

@cmhughes cmhughes added the implemented implemented tag means that either an enhancement or feature request has been implemented, or bugfix label Mar 11, 2020
@cmhughes
Copy link
Owner

demonstration

starting with

\begin{tabular}{cccc}
  aaaaaa&bbbbb&ccc&dd\\
  11&2&33&4\\
  5&66&7&8
\end{tabular}

and the YAML

lookForAlignDelims:
   tabular: 
      dontMeasure: largest

gives

\begin{tabular}{cccc}
	aaaaaa & bbbbb & ccc & dd \\
	11 & 2  & 33 & 4          \\
	5  & 66 & 7  & 8
\end{tabular}

There are other options for the dontMeasure routine, all demonstrated within the documentation.

@cmhughes
Copy link
Owner

Implemented in Version 3.8, #190

@bf
Copy link

bf commented Mar 6, 2023

Same issue persists when using \thead instead of \multicolumn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
align-at-ampersand-routine the align at ampersand; documented in lookForAlignDelims enhancement enhancement which might be to an existing feature or the development of a new feature feature-request user-centred feature request for an enhancement to an existing feature, or for a new feature implemented implemented tag means that either an enhancement or feature request has been implemented, or bugfix
Projects
None yet
Development

No branches or pull requests

4 participants