I have problems getting the Stylesheet settings for GridBoxOptions
/GridBoxItemSize
to be applied to Grid
expressions. Consider the following example:
(* Create a new Stylesheet with a GridTest style that sets the column widths of GridBox *)
SetOptions[
EvaluationNotebook[], StyleDefinitions -> Notebook[
{
Cell[
StyleData["GridTest"],
GridBoxOptions -> {
GridBoxItemSize -> {"Columns" -> {[email protected], {[email protected]}}}
}
]
}
]
]
(* Create a cell containing a Grid expression *)
CellPrint@Cell[BoxData@ToBoxes@Grid[{{"a", "b"}}], "GridTest"]
(* Manually create the GridBox *)
CellPrint@Cell[BoxData@GridBox@{{"a", "b"}}, "GridTest"]
As you can see, the setting from the Stylesheet is only applied to the case where the GridBox
is manually built. Inspecting the box structure of the automatically generated GridBox
reveals the problem:
ToBoxes@Grid[{{"a", "b"}}]
(* TagBox[
GridBox[
{{"\"a\"", "\"b\""}},
AutoDelete -> False,
GridBoxItemSize -> {"Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}
],
"Grid"
] *)
Apparently, ToBoxes
automatically adds a default for GridBoxItemSize
, which obviously overrides the Stylesheet default.
The question is now: How can I convert a Grid
expression into a box structure such that the Stylesheet options are not randomly overridden?
I've tried to specify things like ItemSize->{}
or ItemSize->Inherited
, but they do not work. There seems to be another issue that causes ToBoxes
to replace ItemSize->Inherited
with GridBoxItemSize->{}
, rather than GridBoxItemSize->Inherited
(which would behave properly).
The reason why I need this: I need to generate a cell containing a GridBox
from a Grid
expression with user defined option values and have it respect the stylesheet defaults. Since the mapping from Grid
options to GridBoxOptions
is not documented, I can't ask the user to provide the GridBox
options directly. Of course, I could manually perform the mapping or try to detect which options need to be deleted, this feels hacky and partly relies on undocumented behavior.