Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to say 10 cent dollar per kilowatt-hour of electricity. When I compile the following,

\documentclass{article}
\usepackage{siunitx}
\begin{document}
\SI[per-mode=symbol]{0.1}[\$]{\per\kWh}
\end{document}

I get the following result that is not correct.

enter image description here

The correct output must be as follows:

enter image description here

This is a bug or I forgot something to setup?

share|improve this question
2  
Did you try something like \SI[per-mode=symbol]{0.1}{\$\per\kWh}? –  Claudio Fiandrino May 15 '12 at 7:53
    
@ClaudioFiandrino: The output is not exactly the same as what I want to get. –  Please don't touch May 15 '12 at 8:01
    
But why do you want dollar-cent 10 per kilowatt-hour? The comment from @ClaudioFiandrino looks like the correct solution to me –  matth May 15 '12 at 8:21
    
@matth: Because I want to say not I want to write. :-) The usual format is currency sign followed by a number per unit. –  Please don't touch May 15 '12 at 8:22
    
Ok, but you are aware that the solution by @ClaudioFiandrino is the common way of writing it? en.wikipedia.org/wiki/Electricity_pricing –  matth May 15 '12 at 8:25

2 Answers 2

up vote 12 down vote accepted

The problem is that kWh is a combined unit of watt and hours with a kilo prefix. So if you wirte \kWh it expands to \kilo\watt\hour and the \per will be applied to the \watt part only.

Solution 1

Use the sticky-per option to get \per\hour to.

\documentclass{article}
\usepackage{siunitx}
\begin{document}
\SI[per-mode=symbol,sticky-per]{0.1}[\$]{\per\kWh}
\end{document}

with parens

Adding bracket-unit-denominator = false will suppress the parens.

\documentclass{article}
\usepackage{siunitx}
\begin{document}
\SI[%
    per-mode=symbol,sticky-per,
    bracket-unit-denominator=false,
]{0.1}[\$]{\per\kWh}
\end{document}

suppressed parens

Solution 2

Overwrite the definition of \kWh:

\documentclass{article}
\usepackage{siunitx}

\AtBeginDocument{\DeclareSIUnit{\kWh}{kWh}}

\begin{document}
\SI[per-mode=symbol]{0.1}[\$]{\per\kWh}
\end{document}

overwritten unit macro

Conclusion

Decide wether you think kWh is a combine unit or not. If you think it is, use Solution 1 if you see it as a single unit use solution 2.

share|improve this answer
    
I see. And can it be regarded as a bug? –  Please don't touch May 15 '12 at 8:58
    
@Forgiver: Hm … depends on you point of view. I you take kWh as a single unit it’s a bug, if you take it as a combined unit, it’s no bug … –  Tobi May 15 '12 at 9:00
2  
@Forgiver this is no bug! The documentation even has a short section about the \kWh unit (section 7.12 “Special considerations for the \kWh unit”). The space -- which is common between units -- is discussed there as well. –  cgnieder May 15 '12 at 9:05
3  
@Forgiver No, that's not unnecessary. I warn in the docs that the usual use of 'kWh' with no space is very questionable, as it hides the multiplication (kilowatts times hours). There is a specific note about combining \kWh with other items. –  Joseph Wright May 15 '12 at 9:06
6  
@Tobi I'd say this is the design behaviour. A 'prebuilt' unit such as \kWh is intended as a shortcut for \kilo\watt\hour to be used if you have a lot of them. It's not really the intention that combinations of 'combined' units can then be used to build up further complexity as it then makes the powers complex. For example, what would \kWh\squared mean? I strongly favour writing things out, as it's rarely a significant increase in input complexity. Of course, if there is demand I can think about extending the parser, perhaps with an option to affect the behaviour. –  Joseph Wright May 15 '12 at 9:09

Honestly, this idea came from Claudio Fiandrino's comment. I compiled his code and I noticed I got a correct output but with different position of currency sign.

A funny way to solve it, just append \null as follows:

\documentclass{article}
\usepackage{siunitx}
\begin{document}
\SI[per-mode=symbol]{0.1}[\$]{\null\per\kWh}
\end{document}

Because I am still interested in why this way works, I leave this post as is until someone can explain the reason. Of course this post is not regarded as the answer!

share|improve this answer
    
I understood that this answer deserves a -1 for not having a scientific basis. I will not accept it until there is a worse one. –  Please don't touch May 15 '12 at 8:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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