I got a problem with formatting text in math mode. I made a commmand that moves the unit in the end of the equations all the way to the right. It looks like that


And this is how I intended to use it (just some random equation):

p(P)=S_{\text{i}}+10\cdot \log_{10}\left(\frac{P}{1\:\text{W}}\right)\,\unit[{dB}_{SPL}] 

And this is how it looks:

enter image description here

And now to the problem. As you can se the unit is italic but I would like to be normal (roman). I can do this if I type it manually every time I add a new unit but I would like it to automatic.

I have tried to use:


Here is some more info you might need to help me:


\sisetup{output-decimal-marker = {,}}
%THE newcommand which is causing problems!%

  • 2
    Hi and welcome, are you aware of package siunitx? You are loading it, why not use it here? Does something like \si{db_{SPL}} not work?
    – Johannes_B
    Oct 22, 2014 at 17:45
  • Thanks Jhannes - And yes it dose something with si units but I haven't used it and I dont know if you can make it automatically.Edit: no \si{} didnt work got a Undefined control sequence error.
    – Vinkel
    Oct 22, 2014 at 17:49
  • Welcome to TeX.SX! Please make your code into a complete, small document which is compilable (if possible). That makes it a lot easier for people to help: they can just copy-paste your code to reproduce the problem.
    – cfr
    Oct 22, 2014 at 17:56
  • in \unit[{dB}_{SPL}] the argument of \unit is just [ the other characters are just set in the surrounding math expression Oct 22, 2014 at 17:56
  • #3 I will try that next time :) #4 Thanks for the help its working now :)
    – Vinkel
    Oct 22, 2014 at 18:06

2 Answers 2


You're using the definition of \unit incorrectly.


specifies that \unit will take a single mandatory argument. If you don't provide an explicit brace (in the form of \unit{..}), then the first token will be taken as the argument:


So in the above, [ is taken as the argument and therefore the above is replaced with


which sets as expected. You should use


with the definition of \unit


Note though that \hfill doesn't make any sense in math mode and therefore the \unit will be set just to the right of where it's placed. I find that okay...

enter image description here



  p(P) = S_{\text{i}}+10\cdot \log_{10}\left(\frac{P}{1\:\text{W}}\right)\,\unit{dB_{SPL}}


Although the answer of Werner totally and correctly adresses the question of how to technically solve the problem, there is a big drawback: the use of units and brackets wished by the questioner is simply wrong.

Please note that [X] reads as the unit of X. So something like this would be correct: $[I] = \mathrm{A}$ or better $[I] = \si{\ampere}$. Read: "The unit of the current is Ampere".

So the physical quantity goes into the brackets, not the unit. The physical quantity itself is a product of the value and its unit .

So there would be two correct ways of showing your equation, please note also the use of siunitx for the "1 W" :

enter image description here



  p(P) = \left( S_{\text{i}}+10\cdot \log_{10}\!\left(\frac{P}{\SI{1}{\watt}}\right) \right) \si{\deci\bel}

  p(P)/\si{\deci\bel} = S_{\text{i}}+10\cdot \log_{10}\!\left(\frac{P}{\SI{1}{\watt}}\right)


Also the spacing in front of the \left( parentheses is not optimal, i added a negative math space \!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .