MathGroup Archive 2013

[Date Index] [Thread Index] [Author Index]

Search the Archive

universal shortcut

Dear Group, 

despite my rather long experience with Mathematica I was never satisfied with
palettes or shortcuts ideas to input nice formated symbols in Mathematica. The
first is too slow, the second requires to remember a lot of
abbreviations.  From the other side Shift + K idea (universal completion
template) I found rather useful. So I would like to implement something
like universal "shortcut" (well, say for simple heads with fixed number
of arguments at least). Consider for example the following particular

 InputAliases -> 
   CurrentValue[System`$FrontEndSession, InputAliases],
   Thread[Rule[{"mvb"}, Blank[]]]]]

$GAPackageInputAliases = {};

$GAPackageInputAliases = 
  Join[$GAPackageInputAliases, {"mvb" -> 
            "Placeholder"]}, "GADown", 
          DisplayFunction -> (SubscriptBox["\[InvisibleSpace]", 
              RowBox[{##, "\[InvisibleSpace]"}]] &)], 
         "RunningAlgebra"}, "\[DoubleStruckE]", 
        DisplayFunction -> (RowBox[{StyleBox["\[DoubleStruckE]", 
              RGBColor[0, 0, 0]], "\[InvisibleSpace]", #}] &)]}] }];

  InputAliases -> 
     InputAliases], $GAPackageInputAliases]];

with the following definitions

MakeBoxes[GADown[in__], StandardForm] := 
 With[{pf = 
    Function @@ {SubscriptBox["\[InvisibleSpace]", 
       RowBox[Riffle[Slot /@ Range[Length[{in}]], 
  TemplateBox[MakeBoxes /@ {in}, "GADown", DisplayFunction -> pf, 
   SyntaxForm -> SubscriptBox, Tooltip -> ToString[GADown[in]]]]
MakeBoxes[\[DoubleStruckE][in__, ra_Cl], StandardForm] := 
 With[{pf = 
     Function @@ {RowBox[
        Join[{StyleBox["\[DoubleStruckE]", GAStyle[ra]], 
         Riffle[Slot /@ Range[Length[{in}]], "\[InvisibleSpace]"]]]}},
    TemplateBox[MakeBoxes /@ {in, ra}, "\[DoubleStruckE]", 
    DisplayFunction -> pf, SyntaxForm -> RowBox, Tooltip -> None]] /; 
  MemberQ[GAStyle[ra], _Rule]

SetAttributes[upgradeInputAlias, HoldRest];
upgradeInputAlias[aliasName_String, aliasReplacementRul__Rule] := 
 Module[{inpOpt, alposition}, 
    inpOpt = 
      InputAliases], (alposition = 
       Position[inpOpt, aliasName -> _][[1]]) -> (Extract[inpOpt, 
        alposition] /. {aliasReplacementRul})]]]

Options[DefineGeometricAlgebra] = {FontColor -> Automatic};
DefineGeometricAlgebra[{p_Integer, q_Integer, r_Integer: 0}, 
  opts___?OptionQ] := (
  RunningAlgebra = Cl[p, q, r];
    Cl[p, q, r]] = {FontColor -> 
      Switch[value = ((FontColor /. 
            FilterRules[{opts}, Options[StyleBox]]) /. 
          Options[DefineGeometricAlgebra]), _RGBColor, value, 
       Automatic, RGBColor[p, r, q], _, Black]]};
   RGBColor[__] -> (FontColor /. GAStyle[Cl[p, q, r]])];
  upgradeInputAlias["mvb", "RunningAlgebra" -> MakeBoxes[Cl[p, q, r]]];

Now if we define 

DefineGeometricAlgebra[{5, 3, 0}]

then input shortcut <esc>mvb<esc> seems work nice.

Suppose now that I don't want to remember what "mvb" means. Instead I
would like to start typing  container name i.e. \[DoubleStruckE] and
then pres some universal combination like Shift + ctrl + W or any other
not reserved, and this will look in defined input aliases (or You can
think any other idea) and insert Template box matching
\[DoubleStruckE] .

Can the idea of "universal shortcut" or "supershorcut" be implemented? 
The Mathematica expression completion description is rather sketchy.

Sincerely, Arturas Acus 

  • Prev by Date: Re: bug in Print
  • Next by Date: Re: Decision whether point lies within closed contour
  • Previous by thread: Re: Image color ratio
  • Next by thread: Maple procedures to Mathematica