Skip to main content
added 139 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

It seems the best way is to lead to the canonical form {{_, _}, {_, _}} every option on the first step, then handle their inter-dependencies separately. The following module returns complete horizontal and vertical margins {mHor, mVert} for "Input" style:

Module[{m, f, fm},
 {m, f, fm} = CurrentValue[EvaluationNotebook[], {StyleDefinitions, "Input", #}] & /@ {CellMargins, CellFrame, CellFrameMargins};
 (* canonicalization *)
 {m, f, fm} = Replace[{m, f, fm}, x : Except[{{_, _}, {_, _}}] :> {{x, x}, {x, x}}, {1}];
 (* replacing CellFrameMargins by zeros where the frame is off *)
 fm = ReplacePart[fm, Position[f, Except[True | _?(Positive[Abs[#]] &)], {2}, Heads -> False] -> 0];
 (* clearing up non-numeric values *)
 {m, f, fm} = Replace[{m, f, fm}, x_ /; Not@NumericQ[x] :> 0, {3}];
 Total /@ (m + f + fm)]
{76, 15}

Note that the above implementation is still incomplete because it doesn't take into account CellLabelMargins and CellFrameLabelMargins as well as "Widths" suboption of CellBracketOptions.

It seems the best way is to lead to the canonical form {{_, _}, {_, _}} every option on the first step, then handle their inter-dependencies separately. The following module returns complete horizontal and vertical margins {mHor, mVert} for "Input" style:

Module[{m, f, fm},
 {m, f, fm} = CurrentValue[EvaluationNotebook[], {StyleDefinitions, "Input", #}] & /@ {CellMargins, CellFrame, CellFrameMargins};
 (* canonicalization *)
 {m, f, fm} = Replace[{m, f, fm}, x : Except[{{_, _}, {_, _}}] :> {{x, x}, {x, x}}, {1}];
 (* replacing CellFrameMargins by zeros where the frame is off *)
 fm = ReplacePart[fm, Position[f, Except[True | _?(Positive[Abs[#]] &)], {2}, Heads -> False] -> 0];
 (* clearing up non-numeric values *)
 {m, f, fm} = Replace[{m, f, fm}, x_ /; Not@NumericQ[x] :> 0, {3}];
 Total /@ (m + f + fm)]
{76, 15}

Note that the above implementation is still incomplete because it doesn't take into account CellLabelMargins and CellFrameLabelMargins.

It seems the best way is to lead to the canonical form {{_, _}, {_, _}} every option on the first step, then handle their inter-dependencies separately. The following module returns complete horizontal and vertical margins {mHor, mVert} for "Input" style:

Module[{m, f, fm},
 {m, f, fm} = CurrentValue[EvaluationNotebook[], {StyleDefinitions, "Input", #}] & /@ {CellMargins, CellFrame, CellFrameMargins};
 (* canonicalization *)
 {m, f, fm} = Replace[{m, f, fm}, x : Except[{{_, _}, {_, _}}] :> {{x, x}, {x, x}}, {1}];
 (* replacing CellFrameMargins by zeros where the frame is off *)
 fm = ReplacePart[fm, Position[f, Except[True | _?(Positive[Abs[#]] &)], {2}, Heads -> False] -> 0];
 (* clearing up non-numeric values *)
 {m, f, fm} = Replace[{m, f, fm}, x_ /; Not@NumericQ[x] :> 0, {3}];
 Total /@ (m + f + fm)]
{76, 15}

Note that the above implementation is still incomplete because it doesn't take into account CellLabelMargins and CellFrameLabelMargins as well as "Widths" suboption of CellBracketOptions.

added 155 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

It seems the best way is to lead to the canonical form {{_, _}, {_, _}} every option on the first step, then handle their inter-dependencies separately. The following module returns complete horizontal and vertical margins {mHor, mVert} for "Input" style:

Module[{m, f, fm},
 {m, f, fm} = CurrentValue[EvaluationNotebook[], {StyleDefinitions, "Input", #}] & /@ {CellMargins, CellFrame, CellFrameMargins};
 (* canonicalization *)
 {m, f, fm} = Replace[{m, f, fm}, x : Except[{{_, _}, {_, _}}] :> {{x, x}, {x, x}}, {1}];
 (* replacing CellFrameMargins by zeros where the frame is off *)
 fm = ReplacePart[fm, Position[f, Except[True | _?(Positive[Abs[#]] &)], {2}, Heads -> False] -> 0];
 (* clearing up non-numeric values *)
 {m, f, fm} = Replace[{m, f, fm}, x_ /; Not@NumericQ[x] :> 0, {3}];
 Total /@ (m + f + fm)]
{76, 15}

Note that the above implementation is still incomplete because it doesn't take into account CellLabelMargins and CellFrameLabelMargins.

It seems the best way is to lead to the canonical form {{_, _}, {_, _}} every option on the first step, then handle their inter-dependencies separately. The following module returns complete horizontal and vertical margins {mHor, mVert} for "Input" style:

Module[{m, f, fm},
 {m, f, fm} = CurrentValue[EvaluationNotebook[], {StyleDefinitions, "Input", #}] & /@ {CellMargins, CellFrame, CellFrameMargins};
 (* canonicalization *)
 {m, f, fm} = Replace[{m, f, fm}, x : Except[{{_, _}, {_, _}}] :> {{x, x}, {x, x}}, {1}];
 (* replacing CellFrameMargins by zeros where the frame is off *)
 fm = ReplacePart[fm, Position[f, Except[True | _?(Positive[Abs[#]] &)], {2}, Heads -> False] -> 0];
 (* clearing up non-numeric values *)
 {m, f, fm} = Replace[{m, f, fm}, x_ /; Not@NumericQ[x] :> 0, {3}];
 Total /@ (m + f + fm)]
{76, 15}

It seems the best way is to lead to the canonical form {{_, _}, {_, _}} every option on the first step, then handle their inter-dependencies separately. The following module returns complete horizontal and vertical margins {mHor, mVert} for "Input" style:

Module[{m, f, fm},
 {m, f, fm} = CurrentValue[EvaluationNotebook[], {StyleDefinitions, "Input", #}] & /@ {CellMargins, CellFrame, CellFrameMargins};
 (* canonicalization *)
 {m, f, fm} = Replace[{m, f, fm}, x : Except[{{_, _}, {_, _}}] :> {{x, x}, {x, x}}, {1}];
 (* replacing CellFrameMargins by zeros where the frame is off *)
 fm = ReplacePart[fm, Position[f, Except[True | _?(Positive[Abs[#]] &)], {2}, Heads -> False] -> 0];
 (* clearing up non-numeric values *)
 {m, f, fm} = Replace[{m, f, fm}, x_ /; Not@NumericQ[x] :> 0, {3}];
 Total /@ (m + f + fm)]
{76, 15}

Note that the above implementation is still incomplete because it doesn't take into account CellLabelMargins and CellFrameLabelMargins.

Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

It seems the best way is to lead to the canonical form {{_, _}, {_, _}} every option on the first step, then handle their inter-dependencies separately. The following module returns complete horizontal and vertical margins {mHor, mVert} for "Input" style:

Module[{m, f, fm},
 {m, f, fm} = CurrentValue[EvaluationNotebook[], {StyleDefinitions, "Input", #}] & /@ {CellMargins, CellFrame, CellFrameMargins};
 (* canonicalization *)
 {m, f, fm} = Replace[{m, f, fm}, x : Except[{{_, _}, {_, _}}] :> {{x, x}, {x, x}}, {1}];
 (* replacing CellFrameMargins by zeros where the frame is off *)
 fm = ReplacePart[fm, Position[f, Except[True | _?(Positive[Abs[#]] &)], {2}, Heads -> False] -> 0];
 (* clearing up non-numeric values *)
 {m, f, fm} = Replace[{m, f, fm}, x_ /; Not@NumericQ[x] :> 0, {3}];
 Total /@ (m + f + fm)]
{76, 15}