gap-packages / typeset

Automatic typesetting framework for common GAP objects, with LaTeX generation.
http://gap-packages.github.io/typeset/
Other
3 stars 0 forks source link

[FEATURE] Generate LaTeX tables from "Browse" tables #26

Open kiryph opened 12 months ago

kiryph commented 12 months ago

Is your feature request related to a problem? Please describe. It would be convenient to be able to create a LaTeX version of simple generic tables which the GAP package browse can display:

An example can be a simple list of the calculated number of subgroups up to a certain index (LowIndexSubgroups). Let's consider the 17 wallpaper groups (crystallographic groups for dimension 2) which packages Cryst and CrystCat can handle.

gap> LoadPackage("CrystCat");

You can calculate the number of LowIndexSubgroups for each of the 17 wallpaper groups as following:

gap> List([1..17], no -> Length(LowIndexSubgroups(FpGroupSpaceGroupBBNWZ(SpaceGroupBBNWZ(2, no)), 3 * Size(PointGroup(SpaceGroupBBNWZ(2, no))))));

with the subgroup index set by a multiple $n$ (here 3) of the size of the point group of the plane group:

$|X{\mathcal{H} < \mathcal{G}}^n| = |\{ \mathcal{H} | \mathcal{H} < \mathcal{G} \wedge |\mathcal{G}:\mathcal{H}| \leq n \cdot |\mathcal{P}\mathcal{G}| \}|$

It takes a short while (21 seconds on my machine), so I simply add the final data:

gap> nr_subgroups := [ 8, 65, 42, 20, 22, 343, 128, 71, 157, 51, 279, 113, 14, 41, 33, 43, 176 ];

You can use the Hermann Mauguin Symbols to denote each of the seventeen groups in the table:

gap> CrystGroupsCatalogue[2].HermannMauguinSymbol;
[ "p1", "p2", "pm", "pg", "cm", "p2mm", "p2mg", "p2gg", "c2mm", "p4", "p4mm", "p4gm", "p3", "p3m1", "p31m", "p6",
  "p6mm" ]

You can show the results in a nicely formatted and labelled table in GAP with the package "browse":

gap> NCurses.BrowseDenseList(TransposedMat([nr_subgroups]), rec(labelsCol:=[["X_{\\cH < \\cG}^n"]], labelsRow:=TransposedMat([CrystGroupsCatalogue[2].HermannMauguinSymbol]), header := ["Number of Low Index Subgroups of Plane Groups", "\n"], footer := ["\n","$X_{\\cH < \\cG}^n = \\{\\cH | \\cH < \\cG \\wedge |\\cG:\\cH| \\leq n \\cdot |\\cP_\\cG| \\}$"]));

Screenshot 2023-11-15 at 09 32 54

Describe the solution you'd like It would be great if one could call Typeset instead of NCurses.BrowseDenseList to get conveniently a LaTeX table of the result for direct insertion into a LaTeX document.

Additional context

As a first step, adding support for NCurses.BrowseDenseList( list, arec ) with arec having following optional components:

- header
- footer
- convertEntry
- labelsRow
- labelsCol

would already be helpful.

I am aware that certain assumptions have to be made how the table will be formatted (e.g. if the LaTeX package booktabs should be used, ...).

ZachNewbery commented 8 months ago

@kiryph thanks for the suggestion. I'm not too familiar with Browse, would this feature be more of adding a method overload to handle any arguments that satisfy BrowseData.IsBrowseTable?

Or were you thinking of a more generic table-creating method that takes in a value table, with optional arguments for columns/rows and headers/footers etc.?

kiryph commented 8 months ago

@ZachNewbery Thanks for getting back to me:

[...] would this feature be more of adding a method overload to handle any arguments that satisfy BrowseData.IsBrowseTable? Or were you thinking of a more generic table-creating method that takes in a value table, with optional arguments for columns/rows and headers/footers etc.?

I would imagine the second one. Since I am not very familiar with Browse myself, but afaik it targets interactive browsing tables with paging, searching, sorting etc.

I was referring to Browse since it already defines/establishes how a table might be stored in GAP with labels for rows, columns and title. One could use this to export to LaTeX as well.

Other math software with export functionality to LaTeX tables for comparison:

  1. Sage: https://doc.sagemath.org/html/en/reference/misc/sage/misc/table.html
  2. Pandas (Python lib) data frame export which offers many options to style directly the exported LaTeX table. But this has grown over the years.
ZachNewbery commented 8 months ago

Ah that makes sense, thanks for clarifying. Do you think this would be restricted to rectangular tables, or are there cases where one may have uneven columns/rows?

Note to self when I find time to do this: here describes a filter that can be used to determine if we have homogenous lists. I imagine I will need an option like treatMatrixAsTable or treatListAsTable to allow fall-through to a more generic isTable overload of Typeset. Additionally, the specification of headers could be added either as options - unless it can be specified as an optional argument.