Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

Re: advanced keystroke remapping

  • To: mathgroup at smc.vnet.net
  • Subject: [mg25584] Re: [mg25531] advanced keystroke remapping
  • From: John Fultz <jfultz at wolfram.com>
  • Date: Mon, 9 Oct 2000 21:43:25 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

At 03:35 AM 10/7/2000 -0400, topquark at my-deja.com wrote:


>I'm looking for a way to filter the keystroke stream in a Mathematica
>notebook session and remap a pattern of keystrokes in real-time to
>another sequence as determined by a set of rules that allow roughly the
>flexibility of regular expressions.
>
>One of the reasons I'd like to do this is to customize the way
>mathematical expressions are entered in Mathematica.  I don't find
>always reaching for the Escape key very comfortable, and I would like
>to redefine how math mode is entered and exited and how mathematical
>expressions are navigated.
>
>The problem with standard key-remapping utilities is that they don't
>allow the user to define rules to remap a string that matches a pattern
>to a different string; they just swap keys and (re)define control-
>sequences.  The kind of program I'm looking for would have to buffer
>the keystroke input in order to see if a pattern is matched first
>before sending the substitution to the application.  If it sends each
>keystroke to the application as it is entered, it would be difficult
>to "get the string back" from the application in order to make the
>substitution without sending editing commands along with the
>replacement string.
>
>Preferably, a little piece of code written inside Mathematica would
>provide this level of customizability, but I'm willing to look at
>solutions that lie closer to the OS, in which case I'd be interested in
>suggestions that relate either to Windows or UNIX.
>
>Thanks.
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.

I believe you're asking two questions here.  The first question is, how do 
you make things like what you might type using the Escape key less 
tedious?  For example, how might you type "pi" and get \[Pi], or perhaps 
something even more sophisticated?

You can do this in Mathematica by using the InputAutoReplacements option in 
Mathematica 4.  Note what happens when you type into Mathematica something 
like the following...

a->b (type this into a typeset cell, notice that -> turns into an arrow)
TeX and LaTeX are fun. (type this into a Text cell, notice the substitution 
that happens to TeX and LaTeX).

These are accomplished by settings of the InputAutoReplacements option in 
the Default.nb stylesheet.  If you select an input cell, open the Option 
Inspector, set the scope to "selection", and look at the value for 
InputAutoReplacements, you'll see that, among other things, it includes the 
rule
         "->" -> "\[Rule]"

This is the first replacement I demonstrated above.  Note, however, that 
the replacement does not apply immediately when you type the '>', but only 
when you type the 'b'.  That's because the replacement only happens for 
things that can be lexically isolated as operators or symbols (in the case 
of mathematical input) or words (in the case of text), and so the 
replacement does not actually occur until Mathematica until it has 
determined whether you've finished typing the operator/symbol/word.  This 
allows you to create a replacement that triggers on "foo", but which does 
not happen when you type "foobar" because Mathematica detects that you 
didn't go onto the next word or symbol after typing the second o in "foo".

So, to add your own replacement, keep in mind that the replacement must be 
of a whole word, symbol, or operator, and choose what you want to do.  To 
use the example of typing in "pi" and getting \[Pi], set the Option 
Inspector's scope to global, then click the button next to the 
InputAutoReplacements option.  Click Add.

On the left side, type
         pi
On the right side, type
         "\[Pi]"

Now, do something like...
         Plot[Sin[x], {x, 0, 2pi}]

That should work in all mathematical cells.  If you want to make 
replacements which also take effect in Text cells, then you'll need to 
modify the InputAutoReplacements option of the Text style in the style sheet.

The second question it appears you're asking is, how do you change keyboard 
shortcuts?  There's no way at present to change them from within 
Mathematica, but there is a configuration files you can edit using a text 
editor.  In the Mathematica installation directory, open the following file 
in a text editor...
         SystemFiles\FrontEnd\TextResources\Windows\MenuSetup.tr (on Windows)
         SystemFiles/FrontEnd/TextResources/X/MenuSetup.tr (on Unix)

If you look at the MenuKey[] expressions, it should become quickly apparent 
how you can modify these to be whatever key you wish.  Note that Wolfram 
doesn't document or support changing this file, and makes no guarantees 
that the format of the file won't change in the future.  Also, note that 
it's entirely possible to come up with key combinations which won't work 
because they are reserved (for example, Alt+1 - Alt+9 are reserved for 
styles), or because a change you made causes a particular keystroke to show 
up multiple times.

I suggest making a backup of this file before you change it, or copy it 
into the directory name returned by Mathematica when you evaluate this 
expression:

ToFileName[{$PreferencesDirectory, "SystemFiles", "FrontEnd", "TextResources"}]

and modify the copy (Mathematica will prefer one in this location over the 
one in the installation directory):

There are similar key bindings for things which don't show up in the menus 
in a companion file called KeyEventTranslations.tr.  Incidentally, in both 
files, the "Command" modifier refers to the Mod1 key under X and the Alt 
key under Windows.



Sincerely,

John Fultz
jfultz at wolfram.com
User Interface Group
Wolfram Research, Inc.



  • Prev by Date: Re: Re: problem with nonlinearfit
  • Next by Date: Re: Re: problem with nonlinearfit
  • Previous by thread: advanced keystroke remapping
  • Next by thread: MultiLinear and Linear function