4
$\begingroup$

I am using mathematica to write my physics homework, one thing that trouble me is that I need to enter lots of vectors. I usually type the name of the vector, "A" for example, and then hit "[Ctrl] 7" and "[Esc] vec [Esc]" to get a full vector representation. May I create a shortcut, like "[Alt] v" for example, to automatically finish this process?

$\endgroup$
9
$\begingroup$

It seem to me that for a task like writing homework, it would be complete overkill to try anything fancy or low-level. So I would suggest instead to go with something like this, which just applies in the current notebook and also just for the particular vector you use most commonly:

SetOptions[EvaluationNotebook[], 
 InputAutoReplacements -> {"aa" -> ToBoxes[
\!\(\*OverscriptBox[\(a\), \(\[RightVector]\)]\)]}]

Now if you type aa followed by a space, it will immediately change to $\vec{a}$.

Also be aware that you should use such constructs primarily for typesetting. Don't try using things like $\vec{a}$ in the same way you would use variables, unless you know what you're doing. See this tutorial and search for issues related to subscripted symbols. The same warnings apply to vectors.

Edit: general vectors

The above is the fastest method to input specific vectors. In practice, all you have to do is type the symbol you want to create, and paste it in the ToBoxes that wraps $\vec{a}$ in the above example. To add more individual characters, just add the analogous definitions, such as "bb" -> ToBoxes[...], to the list {...}.

To do something similar for arbitrary vectors, you will need more keystrokes. First enter

SetOptions[EvaluationNotebook[], 
  InputAutoReplacements -> 
  {"vv" -> OverscriptBox["\[NegativeMediumSpace]\[SelectionPlaceholder]", 
     "\[RightVector]"]}]

Now you can type vv followed by a space to get a placeholder into which you type the desired letter(s). Then you can press the arrow navigation keys or Ctrl-. repeatedly to get out of the placeholder when done.

The above use of InputAutoReplacements adds a space under the vector symbol, which I then have to undo by adding \[NegativeMediumSpace]. To avoid this, you could also do this:

SetOptions[EvaluationNotebook[], 
 InputAliases -> {"vv" -> 
    OverscriptBox["\[SelectionPlaceholder]", "\[RightVector]"]}]

With this method, you would have to type EscvvEsc to get the vector template, so it takes one additional keystroke. But it doesn't require me to add the \[NegativeMediumSpace] in the output.

|improve this answer|||||
$\endgroup$
  • $\begingroup$ How to generalize this method to any vectors? $\endgroup$ – username123 Mar 22 '15 at 12:34
  • $\begingroup$ Maybe the edited answer will help. $\endgroup$ – Jens Mar 22 '15 at 16:12
0
$\begingroup$

One possible solution is to use a global phrase replacement application like Phrase Express, which you can limit specific phrase 'shortcuts' to a specific application, like Mathematica. I store many shortcuts in Phrase Express for Mathematica, which helps speed up my input dramatically, and I don't need to worry about using packages or default notebooks to do the same thing.

Phrase Express is a closed source application, which offers a free version with limited functionality, and a paid version for more advanced functionality.

|improve this answer|||||
$\endgroup$
  • $\begingroup$ You might want to mention that PhraseExpress is a third-party, closed-source application which costs upwards of 50 USD. Looks like a nice tool though. $\endgroup$ – dionys Aug 27 '15 at 9:53
  • $\begingroup$ Thanks Dionys, I did add a comment, but want to note that they do offer a free limited version of their software which is actually pretty complete. You might want to check it out. $\endgroup$ – mitcheljh Aug 28 '15 at 11:19

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.