Skip to content

Instantly share code, notes, and snippets.

@rebcabin
Created June 17, 2012 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rebcabin/2943522 to your computer and use it in GitHub Desktop.
Save rebcabin/2943522 to your computer and use it in GitHub Desktop.
prints nice grid layout of rules in Mathematica
gridRules[rules_] /;
(ListQ[rules] &&
(Length @ rules > 0) &&
(And @@ (((Head @ # === Rule)||(Head @ # === RuleDelayed))& /@ rules))) :=
With[{
keys = #[[1]]& /@ rules,
heads = #[[0]]& /@ rules,
vals = gridRules[#[[2]]]& /@ rules},
Grid[MapThread[{
Style[#1, Bold],
Style[#3, Bold, Switch[#2, Rule, Blue, RuleDelayed, Red]]}&,
{keys, heads, vals}],
Frame -> All,
Alignment -> Left,
Background -> {{LightOrange, {LightYellow}}}]
];
gridRules[rules_List] := Column[
gridRules /@ rules,
Frame -> All,
Alignment -> Left,
Background -> LightGreen];
gridRules[any_] := InputForm @ any;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment