LatexNotes

Logarithms and exponentials in LaTeX

\log, \ln and \exp are LaTeX's upright operator commands for logarithms and the exponential function; \log takes an optional subscript for its base and \ln is the dedicated command for the natural logarithm.

LaTeX command

\log, \ln, \exp

Not the symbol you meant? Draw it to find the command →

Like the trig functions, \log, \ln and \exp print as upright roman text with correct spacing before their argument, rather than italicising each letter. \log is the general logarithm command; add a subscript for the base, \log_{2} x for log base 2, or leave it bare for an unspecified or base-10 context.

\ln is a separate command for the natural logarithm, used often enough in calculus to deserve its own shortcut; \ln x and \log_{e} x mean the same thing, but \ln is shorter and more common. \exp is useful when the exponent is large or complicated, \exp\left(\frac{-x^2}{2}\right) reads far more cleanly than e stacked with a tall superscript.

A common mistake is typing log or ln directly without a backslash, which italicises the letters just like the trig-function problem. Always use the command, and for a custom named function LaTeX doesn't provide, build one with \operatorname{name} instead.

Other forms

\log_{2} xa base subscript
e^{x}exponential

Examples

$\log_{10} 1000 = 3$

log base 10

$\ln(e^x) = x$

natural log undoes exp

$\log_2 8 = 3$

log base 2

$\exp(x) = e^x$

exp written as a named function

$\ln(ab) = \ln a + \ln b$

the product rule for logs

Tips and common mistakes

Working from handwritten notes?

LatexNotes turns a photo or PDF of handwritten mathematics into clean, compilable LaTeX - graphs and all. Free to try, no sign-up.

Convert your maths to LaTeX →

FAQ

What's the difference between \log and \ln?

\ln is always base e, the natural log; \log is the general command, its base is unspecified by default unless you add a subscript such as \log_{2} x.

How do I write log base 2 in LaTeX?

\log_{2} x, which renders the 2 as a small subscript right after log.

When should I use \exp instead of e^x?

Use \exp when the exponent is long or contains a fraction, for example \exp\left(-\frac{x^2}{2\sigma^2}\right) reads far better than e raised to that whole stacked power.

Why does my log look italic and wrong?

You typed log without a backslash, so LaTeX read it as three italic variables multiplied together. Use \log instead.

See also