Message Boards Message Boards

0
|
10316 Views
|
8 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Quick and clean units using [esc][shortcut][esc]

Posted 8 years ago

Does someone have a list of "[ecs][xx..][ecs]" shortcuts?

I prefer to make unit inputs like this (for example the unit "Farads"):

c = 1F 

...by typing [esc][qf][esc]

Instead of this "confusing" expresion:

c = Quantity[1, "Farads"]

But i cannot find a list of all the "shortcuts" to the different units.

Otherwise i'm open to alternatives

POSTED BY: Benny Bomstærk
8 Replies

I sometimes hijack the InputForm for MessageName as a hacky shortcut for entering units:

MakeExpression[ RowBox[ { eStr_String, "::", units_String } ], StandardForm ] :=
  Replace[ ToExpression[ eStr, StandardForm, HoldComplete ],
           HoldComplete[ expr_ ] :> HoldComplete[ Quantity[ expr, units ] ]
  ];

enter image description here

I wouldn't recommend this for anything other than a throwaway session where you just want to quickly run some numbers, and definitely not for code that you intend to share with others. Overriding default system behavior can make things messy if you aren't careful.

POSTED BY: Richard Hennigan

Using the ESC key produces a named character, not a unit. You can see a full list of named characters and their keyboard shortcuts in the documentation under guide/ListingOfNamedCharacters.

The easiest way to write out quantities is to use natural language input. I often use "Ctrl + =".

Internally, all Quantities are written that way as "Quantity[number, unit]". This is the simplest possible representation of a Quantity and the most basic.

POSTED BY: Sean Clarke
POSTED BY: Sam Carrettie

Actually that Unit palette - brilliant by the way - was the one that made me discover the "esc" solution because it shows up when you mouse over the different units. But doing a lot of electrical engineering I do miss some units.

POSTED BY: Benny Bomstærk

Thanks for the answer. I do not agree that the "esc"-solution cannot make units. When I mouse over the F in the above example it says farads. And when i calculate with different units, the output unit is correct.

For writing units you just need do start the expression with "q" for quantity i think. e.g. [esc]qkv[ecs] for kV (kilovolts).

POSTED BY: Benny Bomstærk

Oh. I see now. The shortcuts you see are part of that package. They aren't part of a regular Mathematica installation. Without knowing that, I didn't understand your question. Without that package, I'm pretty sure you can't create quantities with the [esc] key.

POSTED BY: Sean Clarke

It makes sence. I'll try asking the guy that created the palette... Thanks again!

POSTED BY: Benny Bomstærk

I do not think you can type units like that. Why do you think you can? I tried [esc][qf][esc] and nothing happened.

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

Group Abstract Group Abstract