2
$\begingroup$

I would like to set up a system (or define a keyboard shortcut) so when you type the following

sum

I have the following print at the current selection.

NotebookWrite[
 InputNotebook[],
 ToBoxes[Unevaluated@Sum[Placeholder[ ], {t, 1, n}]],
 Placeholder]

This only works partially works b/c it removes focus.

x = Input[""]
$\endgroup$
  • $\begingroup$ Unless you want to do it in Mathematica for you own specific reasons (portability maybe), I would strongly recommend Autohotkey? The pain you have to go through for that simple task is not worth the effort in Mathematica. In Autohotkey, that task is a one-liner: ::sum::Sum[Placeholder[ ], `{t, 1, n`}]{Left 5} $\endgroup$ – Hector Sep 3 '14 at 6:21
  • $\begingroup$ What would be the easiest way to run a M Function? Or how might I Print a ToBoxes version? Autohotkey doesn't seem to $\endgroup$ – William Sep 3 '14 at 12:22
4
$\begingroup$

Try this:

    nb = CreateDocument[{}, 
   InputAliases -> {"sum" -> 
      "\!\(\*UnderoverscriptBox[\(\[Sum]\), \(\[Placeholder] = \
\[Placeholder]\), \(\[Placeholder]\)]\)\[Placeholder]"}];

After evaluation a new notebook opens. Type in this notebook: Esc+sum+Esc. Done. Have fun!

$\endgroup$
  • $\begingroup$ I have been reconsidering my original thought if it is really a good idea but you definitely deserve and up vote. $\endgroup$ – William Sep 8 '14 at 22:37
  • 1
    $\begingroup$ @Liam William The up-vote is no matter. The point is that there are lots of already existing hot keys. I use some of them and there are too many to memorize them all. You might want to check Menu/Help/DocumentationCenter/tutorial/EnteringTwoDimensionalInput. Otherwise if you open any panel, such as Menu/Palette/BasicMathAssistant or Menu/Palette/SpecialCharacters and hover the cursor over any button you will find the corresponding hot key below the palette. In particular, Esc+sum+Esc gives you the sum by itself without additional efforts. So it may be a good idea to check already existing keys $\endgroup$ – Alexei Boulbitch Sep 9 '14 at 8:04
  • $\begingroup$ This should work pretty well if I combine it with an Autohotkey scriptw $\endgroup$ – William Sep 9 '14 at 23:09
1
$\begingroup$

After thinking it through some more this is the best solution I have come up with so far is to run the following in Mathematica so you can paste code into Mathematica that has formatting

FrontEndExecute[
 FrontEnd`AddMenuCommands[
  "DuplicatePreviousOutput", {Delimiter, 
   MenuItem["Raw Paste Clipboard", FrontEnd`KernelExecute[

     NotebookWrite[InputNotebook[], 
      Catch[NotebookGet@ClipboardNotebook[] /. 
        Cell[r_, ___] :> Block[{}, Throw[r, tag] /; True];
       $Failed, tag], Placeholder]

     ], MenuKey["v", Modifiers -> {"Control", "Shift"}], 
    System`MenuEvaluator -> Automatic]}]]

Next you can create Autohotkey scripts like the following

*SC023:: 
  clipboard = 
  (
    \!\(
    \*SubsuperscriptBox[\(\[Sum]\), \(i = 
    1\), \(\[Placeholder]\)]\[Placeholder]\)
  )
  Send, ^+v
  return
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.