Define InputAlias shortcuts for quickly entering nicely formatted units?

Posted 8 months ago
1224 Views
|
4 Replies
|
6 Total Likes
|
 Ref the attached notebook, I'd like to be able to define InputAlias shortcuts for quickly entering nicely formatted units. The desired format is shown at Section 3 in the attached notebook. My approach at present is to use the InputAlias values defined at Section 1. This produces input in the format shown at Section 2. I then evaluate the Quantity[] parts of these expressions in place (in the input cells) to produce nicely formatted units shown at Section 3.My question is whether there's a way to evaluate the Quantity[] function within the AddInputAlias automatically when the InputAlias is invoked so that the nicely formatted form of units are shown at Section 3 is displayed straight off without having to evaluate in place? This would save a lot of time.Thanks in anticipation,Ian Attachments:
4 Replies
Sort By:
Posted 8 months ago
 Ian, would you settle for having a palette to paste in the units in a Mathematica expression? Or being able to quickly generate a custom palette that has the units for a particular problem type?I have an application called UnitsHelper. It's a package, with an advanced and basic palette and a custom style sheet that displays the units in black instead of grey. (It just seems to me that it's important information and should be displayed as all important information. But you don't have to use the style sheet or could change it to your preference.) There are also quick links to Wolfram and NIST documentation. The advanced palette displays all units by group and then either alphabetically or by size. Physical constants are also on the palette. There is a facility for using reduced units such as geometric or atomic units and also a facility to deunitize an expression to use implied input and output units. Also facilities for general decibel units.If you're interested send me an email from my profile page and I'll send you a Dropbox link.
Posted 8 months ago
 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
 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: