I observe the following in Wolfram Language:

Quantity[ 1, "Kilowatt hours" ] (* or "Kilowatts" * "Hours" *)

(* 1 h kW *)

That looks rather unconventional and in Wolfram Alpha it is done as kW h, for example: kW vs. kWh

How can this be achieved in Mathematica being compatible to the units framework?


Some more peculiarities.

Quantity[ 1, "Megawatt hours" ]
(* 1 h MW *)

(* but *)

Quantity[ 1, "USDollars" / "Megawatt hours" ]
(* Quantity: Unable to interpret unit specification *)

It is not the age of energy as of yet. ;-)

  • 1
    $\begingroup$ it seems to be baked into the display by frontend. Compare Quantity[1, "Hours"*"Kilowatts"] and Quantity[1, "Kilowatts"*"Hours"] they both give 1 h kW May be it uses some internal ordering based on letters or something like that? $\endgroup$
    – Nasser
    Mar 21, 2022 at 12:20
  • 2
    $\begingroup$ I do not think there is a way to change that. One can try to use $PrePrint to change the display, but it is tricky for this kind of output. Better learn to live with it :) You could submit request to WRI to change this and see what they say? $\endgroup$
    – Nasser
    Mar 21, 2022 at 12:23
  • 1
    $\begingroup$ Quantity[1, "USDollars"/("Kilowatts"*"Hours")] seems to solve your dollar issue. FYI, it seems to be sorting alphabetically by the unit name. $\endgroup$
    – Edmund
    Mar 21, 2022 at 12:35
  • 8
    $\begingroup$ @gwr It is a new kind of units :) $\endgroup$
    – Nasser
    Mar 21, 2022 at 12:46
  • 2
    $\begingroup$ If you are really desperate you could do Unprotect[RowBox]; RowBox[{"\"h\"", "\[ThinSpace]", "\"kW\""}] := RowBox[{"kWh"}]. But that is maybe not the right way to eat cookies. $\endgroup$ Mar 21, 2022 at 12:59

1 Answer 1

QuantityUnits`Private`getCompoundUnitBoxes@Quantity[_, "Hours" "Kilowatts"] := 
 RowBox[{"\"kW\"", "\[ThinSpace]", "\"h\""}]

QuantityUnits`Private`getCompoundUnitBoxes@Quantity[_, _/("Hours" "Kilowatts")] :=
 RowBox[{"\"per\"", "\"kW\"", "\[ThinSpace]", "\"h\""}]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.