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

Feature Request: Support spreadtab block #535

Closed Hzbeta closed 3 months ago

Hzbeta commented 4 months ago

Spreadtab allows us to construct tables in a manner similar to a spreadsheet. The cells of a table have row and column indices and these can be used in formulas to generate values in other cells. Detailed instructions can be found here.

image

I hope latexindent.pl can support formatting of the table content in spreadtab block, just like normal tabular block!

For example, no yaml setting, original .tex code

\begin{spreadtab}{{tabular}{r*6c}} % or \spreadtab{{tabular}{r*6c}}
@Ages & 10 & 11 & 12 & 13 & 14 & 15\\
@Number & 5 & 8 & 20 & 55 & 9 & 3\\\hline
@Average&\multicolumn{6}{l}{:={sumprod(b1:g1;b2:g2)/sum(b2:g2)}}
\end{spreadtab} % or \endspreadtab

actual/given output

\begin{spreadtab}{{tabular}{r*6c}} % or \spreadtab{{tabular}{r*6c}}
    @Ages & 10 & 11 & 12 & 13 & 14 & 15\\
    @Number & 5 & 8 & 20 & 55 & 9 & 3\\\hline
    @Average&\multicolumn{6}{l}{:={sumprod(b1:g1;b2:g2)/sum(b2:g2)}}
\end{spreadtab} % or \endspreadtab 

desired or expected output

\begin{spreadtab}{{tabular}{r*6c}} % or \spreadtab{{tabular}{r*6c}}
    @Ages    & 10                                                      & 11 & 12 & 13 & 14 & 15 \\
    @Number  & 5                                                       & 8  & 20 & 55 & 9  & 3  \\\hline
    @Average & \multicolumn{6}{l}{:={sumprod(b1:g1;b2:g2)/sum(b2:g2)}}
\end{spreadtab} % or \endspreadtab 

anything else

Thanks for such a great LaTeX formatting tool! :)

cmhughes commented 4 months ago

Great, thanks, will do :)

cmhughes commented 4 months ago

If anyone wants to take this on, it should just be adding spreadtab to the lookForAlignDelims field. Should be a nice way to get started on contributing.

cmhughes commented 3 months ago

This is implemented as of https://github.com/cmhughes/latexindent.pl/commit/8e089c530e08235655e9d7ee67b9c3cdd7635851

It'll be part of the next release. Please leave this issue open until I've made the release, hopefully coming soon...

cmhughes commented 3 months ago

implemented and released at https://github.com/cmhughes/latexindent.pl/releases/tag/V3.24