Emacs: Unit Converter for the Engineer

How many cubic centimeters in a liter? How many feet in a kilometer? What about gallons per minute and liters per second?

Every single engineer needs to convert units. What may change is how he does it.

  1. Find an online converter / ask Google;
  2. Use a desktop application, such as convert; https://frozenlock.files.wordpress.com/2012/08/wpid-convert.png
  3. Or do it on-the-fly with Emacs!

Now, you may ask:

“But why on earth would I ever consider Emacs to convert my units?”

Because Emacs has an amazing hidden gem inside it: Calc. Fear not, there is no need to learn yet another tool only to convert some units; I’ve package everything needed in a little .el file.

Once this is installed, you can ask Emacs, on-the-fly, to convert some units. Here is an example:

Old value and unit (type C-z for unit list) :

100oz RET

to unit (type C-z for unit list) : g


100oz converted to g = 2834.9523125 g

Pretty nice, isn’t it?

But this is far from it. What’s really handy is how you can input usual prefixes, such as k (kilo), m (milli), y (yocto)… without any special care.

Old value and unit (type C-z for unit list) :

kg RET

to unit (type C-z for unit list) :


kg converted to g = 1000 g


What if you need units not yet defined in Calc? Simply add your own!

Here are some units I’ve added to be more helpful in a HVAC context:

;;; Add some custom units often used in HVAC
(eval-after-load "calc-units"
     (setq math-additional-units
           '((gpm "gal / min" "Gallons per minute")
             (ls "l / s" "Liters per second")
             (cfm "ft^3 / min" "Cubic feet per minute"))
           math-units-table nil)))

Finally, to make sure you take Emacs and Calc seriously, here is the unit list (obtained with M-x calc-view-units-table):

Calculator Units Table:

(All definitions are exact unless marked with an asterisk (*).)

Unit    Type  Definition                  Description

 gpm      U   gal / min                   Gallons per minute
 ls       U   l / s                       Liters per second
 cfm      U   ft^3 / min                  Cubic feet per minute

 m            m                           Meter (base unit)
 in           2.54 cm                     Inch
 ft           12 in                       Foot
 yd           3 ft                        Yard
 mi           5280 ft                     Mile
 au           149597870691 m (*)          Astronomical Unit
 lyr          c yr                        Light Year
 pc           3.0856775854 10^16 m (*)    Parsec
 nmi          1852 m                      Nautical Mile
 fath         6 ft                        Fathom
 fur          660 ft                      Furlong
 mu           1 um                        Micron
 mil          (1/1000) in                 Mil
 point        (1/72) in                   Point (1/72 inch)
 Ang          10^-10 m                    Angstrom
 mfi          mi + ft + in                Miles + feet + inches
 texpt        (100/7227) in               Point (TeX conventions)
 texpc        12 texpt                    Pica
 texbp        point                       Big point (TeX conventions)
 texdd        (1238/1157) texpt           Didot point
 texcc        12 texdd                    Cicero
 texsp        (1/65536) texpt             Scaled TeX point

 hect         10000 m^2                   Hectare
 a            100 m^2                     Are
 acre         (1/640) mi^2                Acre
 b            10^-28 m^2                  Barn

 L            10^-3 m^3                   Liter
 l            L                           Liter
 gal          4 qt                        US Gallon
 qt           2 pt                        Quart
 pt           2 cup                       Pint
 cup          8 ozfl                      Cup
 ozfl         2 tbsp                      Fluid Ounce
 floz         2 tbsp                      Fluid Ounce
 tbsp         3 tsp                       Tablespoon
 tsp          4.92892159375 ml            Teaspoon
 vol          tsp+tbsp+ozfl+cup+pt+qt+gal Gallons + ... + teaspoons
 galC         galUK                       Canadian Gallon
 galUK        4.54609 L                   UK Gallon

 s            s                           Second (base unit)
 sec          s                           Second
 min          60 s                        Minute
 hr           60 min                      Hour
 day          24 hr                       Day
 wk           7 day                       Week
 hms          wk + day + hr + min + s     Hours, minutes, seconds
 yr           365.25 day                  Year (Julian)
 Hz           1 / s                       Hertz

 mph          mi / hr                     Miles per hour
 kph          km / hr                     Kilometers per hour
 knot         nmi / hr                    Knot
 c            299792458 m / s             Speed of light

 ga           9.80665 m / s^2             "g" acceleration

 g            g                           Gram (base unit)
 lb           16 oz                       Pound (mass)
 oz           28.349523125 g              Ounce (mass)
 ton          2000 lb                     Ton
 tpo          ton + lb + oz               Tons + pounds + ounces (mass)
 t            1000 kg                     Metric ton
 tonUK        1016.0469088 kg             UK ton
 lbt          12 ozt                      Troy pound
 ozt          31.10347680 g               Troy ounce
 ct           0.2 g                       Carat
 u            1.660538782 10^-27 kg (*)   Unified atomic mass

 N            m kg / s^2                  Newton
 dyn          10^-5 N                     Dyne
 gf           ga g                        Gram (force)
 lbf          ga lb                       Pound (force)
 kip          1000 lbf                    Kilopound (force)
 pdl          0.138254954376 N            Poundal

 J            N m                         Joule
 erg          10^-7 J                     Erg
 cal          4.1868 J                    International Table Calorie
 calth        4.184 J                     Thermochemical Calorie
 Cal          1000 cal                    Large Calorie
 Btu          1055.05585262 J             International Table Btu
 eV           ech V                       Electron volt
 ev           eV                          Electron volt
 therm        105506000 J                 EEC therm
 invcm        h c / cm                    Energy in inverse centimeters
 Kayser       invcm                       Kayser (inverse centimeter energy)
 men          100 / invcm                 Inverse energy in meters
 Hzen         h Hz                        Energy in Hertz
 Ken          k K                         Energy in Kelvins
 Wh           W hr                        Watt hour
 Ws           W s                         Watt second

 W            J / s                       Watt
 hp           550 ft lbf / s              Horsepower
 hpm          75 m kgf / s                Metric Horsepower

 K        K   K                           Degree Kelvin (base unit)
 dK       K   K                           Degree Kelvin
 degK     K   K                           Degree Kelvin
 dC       C   K                           Degree Celsius
 degC     C   K                           Degree Celsius
 dF       F   (5/9) K                     Degree Fahrenheit
 degF     F   (5/9) K                     Degree Fahrenheit

 Pa           N / m^2                     Pascal
 bar          10^5 Pa                     Bar
 atm          101325 Pa                   Standard atmosphere
 Torr         (1/760) atm                 Torr
 mHg          1000 Torr                   Meter of mercury
 inHg         25.4 mmHg                   Inch of mercury
 inH2O        2.490889 10^2 Pa (*)        Inch of water
 psi          lbf / in^2                  Pounds per square inch

 P            (1/10) Pa s                 Poise
 St           10^-4 m^2 / s               Stokes

 A            A                           Ampere (base unit)
 C            A s                         Coulomb
 Fdy          ech Nav                     Faraday
 e            ech                         Elementary charge
 ech          1.602176487 10^-19 C (*)    Elementary charge
 V            W / A                       Volt
 ohm          V / A                       Ohm
 mho          A / V                       Mho
 S            A / V                       Siemens
 F            C / V                       Farad
 H            Wb / A                      Henry
 T            Wb / m^2                    Tesla
 Gs           10^-4 T                     Gauss
 Wb           V s                         Weber

 cd           cd                          Candela (base unit)
 sb           10000 cd / m^2              Stilb
 lm           cd sr                       Lumen
 lx           lm / m^2                    Lux
 ph           10000 lx                    Phot
 fc           lm / ft^2                   Footcandle
 lam          10000 lm / m^2              Lambert
 flam         (1 / pi) cd / ft^2          Footlambert

 Bq           1 / s                       Becquerel
 Ci           37 10^9 Bq                  Curie
 Gy           J / kg                      Gray
 Sv           Gy                          Sievert
 R            258 10^-6 C / kg            Roentgen
 rd           (1/100) Gy                  Rad
 rem          rd                          Rem

 mol          mol                         Mole (base unit)

 rad          rad                         Radian (base unit)
 circ         2 pi rad                    Full circle
 rev          circ                        Full revolution
 deg          circ / 360                  Degree
 arcmin       deg / 60                    Arc minute
 arcsec       arcmin / 60                 Arc second
 grad         circ / 400                  Grade
 rpm          rev / min                   Revolutions per minute

 sr           sr                          Steradian (base unit)

 h            6.62606896 10^-34 J s (*)   Planck's constant
 hbar         h / 2 pi                    Planck's constant
 mu0          4 pi 10^-7 H / m            Permeability of vacuum
 eps0         1 / mu0 c^2                 Permittivity of vacuum
 G            6.67428 10^-11 m^3/(kg s^2) (*) Gravitational constant
 Nav          6.02214179 10^23 / mol (*)  Avogadro's constant
 me           9.10938215 10^-31 kg (*)    Electron rest mass
 mp           1.672621637 10^-27 kg (*)   Proton rest mass
 mn           1.674927211 10^-27 kg (*)   Neutron rest mass
 mmu          1.88353130 10^-28 kg (*)    Muon rest mass
 Ryd          10973731.568527 /m (*)      Rydberg's constant
 k            1.3806504 10^-23 J/K (*)    Boltzmann's constant
 alpha        7.2973525376 10^-3 (*)      Fine structure constant
 muB          927.400915 10^-26 J/T (*)   Bohr magneton
 muN          5.05078324 10^-27 J/T (*)   Nuclear magneton
 mue          -928.476377 10^-26 J/T (*)  Electron magnetic moment
 mup          1.410606662 10^-26 J/T (*)  Proton magnetic moment
 R0           8.314472 J/(mol K) (*)      Molar gas constant
 V0           22.710981 10^-3 m^3/mol (*) Standard volume of ideal gas

Unit Prefix Table:

 Y     10^24      Yotta
 Z     10^21      Zetta
 E     10^18      Exa
 P     10^15      Peta
 T     10^12      Tera
 G     10^9       Giga
 M     10^6       Mega
 k K   10^3       Kilo
 h H   10^2       Hecto
 D     10^1       Deka
 d     10^-1      Deci
 c     10^-2      Centi
 m     10^-3      Milli
 u     10^-6      Micro
 n     10^-9      Nano
 p     10^-12     Pico
 f     10^-15     Femto
 a     10^-18     Atto
 z     10^-21     zepto
 y     10^-24     yocto

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: