[Tex/LaTex] Problem with units in math mode

math-mode

I'm having problems with the following equation:

\[\frac{dT(t)}{dt} =-1^{\circ}F \text{per hour}\]

it displays:

enter image description here

How do I make "per hour" in normal text form rather than italicized?

Best Answer

Use the siunitx package to write correctly units. It works in both text and math modes.

Default is to use negative exponents instead of a fraction. You can force the use of a symbol by using the \SI command option per-mode=symbol. You can also set the behavior for all units with \sisetup.

Code

\documentclass{article}

\usepackage{mathtools}

\usepackage{siunitx}
\DeclareSIUnit{\fahrenheit}{\SIUnitSymbolDegree F}
%\sisetup{per-mode=symbol}


\begin{document}

    \[\frac{dT(t)}{dt} = \SI{-1}{\fahrenheit\per\hour}\]
    \[\frac{dT(t)}{dt} = \SI[per-mode=symbol]{-1}{\fahrenheit\per\hour}\]

\end{document}

Result

enter image description here

Out-of-the-scope advice

In well formatted maths, the d of derivative should be upright, not slanted. To do so:

\[\frac{\mathrm{d}T(t)}{\mathrm{d}t} = \SI[per-mode=symbol]{-1}{\fahrenheit\per\hour}\]

enter image description here

Enjoy!