Group Abstract Group Abstract

Message Boards Message Boards

1
|
12.3K Views
|
4 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Define InputAlias shortcuts for quickly entering nicely formatted units?

Attachments:
POSTED BY: Ian Williams
4 Replies

For your question regarding section 3, you can use an EventHandler so that the boxes are evaluated when a particular key is pressed. For example:

CurrentValue[ SelectedNotebook[ ], { InputAliases, "qty" } ] = ToBoxes @
  EventHandler[
      Defer @ Quantity @ SelectionPlaceholder[ ],
      {
          "RightArrowKeyDown" :>
            Module[ { box, input, new },

                box = EvaluationBox[ ];
                input = First @ NotebookRead @ box;

                new = Quiet @ Check[ ToExpression[ input,
                                                   StandardForm,
                                                   ToBoxes
                                     ],
                                     input
                              ];

                NotebookWrite[ box, new ]
            ]
      }
  ]

With this, you can use the input alias qty to generate a Quantity template, but pressing the right arrow key will automatically evaluate the quantity in place (see attached video).

Edit: DynamicModule wasn't necessary

Attachments:
POSTED BY: Richard Hennigan
Attachments:
POSTED BY: Ian Williams

Thanks David. I’ve sent you an email. I have a palette for units, but it’s a bit slow to use and want to establish whether it’s possible to achieve the same thing using just keyboard input. I’ve also figured out how to customise the QuantityPanel style to ditch the odd choice of a greyed out font colour for unitiized values. Look forward to seeing your UnitsHelper package.

All the best,

Ian

POSTED BY: Ian Williams
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard