From c5939f8cfc7473e846f62a11ef36db2b94754ca9 Mon Sep 17 00:00:00 2001 From: Jonas Rauber Date: Sat, 10 Jan 2015 15:07:31 +0100 Subject: [PATCH] show unit symbols for common units --- src/SIUnits.jl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/SIUnits.jl b/src/SIUnits.jl index 652b9e0..19bdef9 100644 --- a/src/SIUnits.jl +++ b/src/SIUnits.jl @@ -376,6 +376,25 @@ module SIUnits tup(x)[idx+1:end] == ntuple(7-idx, (i)->0) ? "" : " " end function show{m,kg,s,A,K,mol,cd}(io::IO,x::SIUnit{m,kg,s,A,K,mol,cd}) + units = [ + (Joule, "J"), + (Coulomb, "C"), + (Volt, "V"), + (Farad, "F"), + (Newton, "N"), + (Ohm, "Ω"), + (Hertz, "Hz"), + (Siemens, "S"), + (Watt, "W"), + (Pascal, "Pa") + ] + for (unit, symbol) = units + if unit == x + print(io, symbol) + return + end + end + kg != 0 && print(io, "kg", (kg == 1 ? spacing(1,x) : superscript(kg))) m != 0 && print(io, "m", (m == 1 ? spacing(2,x) : superscript(m))) s != 0 && print(io, "s", (s == 1 ? spacing(3,x) : superscript(s)))