Logarithms in LaTeX: \log, \ln and Bases

One command family with three names — log, ln and lg — plus the brace rule that decides whether the base is a single digit or an expression.

Logarithms are one command family with three names: \log, \ln, \lg. All three are upright operators with the spacing already correct; the base is a subscript and the argument is whatever follows — which is why brackets appear as soon as the argument is more than one token. The subscript rule is Sub & Sup again, and a change of base is an ordinary Fractions question.

Which one to use

Situation Write this Because
Base 2
\log_2 n
Subscript, single token, no braces needed.
Base 10
\log_{10} n
Braces required for two digits.
Natural log
\ln x
Its own operator; the base is implied.
Base e written out
\log_e x
Valid but unusual; prefer \ln.
Change of base
\frac{\log_b x}{\log_b a}
A fraction of two logarithms.
A power inside the log
\log(x^2)
Brackets once the argument is not a single token.

The commands

What Type this Renders as
Base as subscript Single-token base needs no braces, and the 2 sits below and right of the name.
\log_2 8
\log_2 8
Multi-character base Without braces you get log₁₀ followed by a stray x-shaped subscript artifact.
\log_{10} x
\log_{10} x
Natural log Its own command, not \log with an n attached.
\ln e = 1
\ln e = 1
Common log Some fields write \lg for base ten; LaTeX has no \lg, so define it or spell the base out.
\log_{10} 1000 = 3
\log_{10} 1000 = 3
Base as a definition The equivalence form that defines the logarithm, using the double-implication arrow.
\log_b x = y \iff b^{y} = x
\log_b x = y \iff b^{y} = x
Change of base Fractions inside a displayed line keep full height, which is what this identity needs.
\log_a b = \frac{\log_c b}{\log_c a}
\log_a b = \frac{\log_c b}{\log_c a}
Product rule Brackets around the argument when it is a compound expression.
\log(xy) = \log x + \log y
\log(xy) = \log x + \log y
Quotient rule A stacked fraction can follow the operator directly; no brackets required.
\ln\frac{a}{b} = \ln a - \ln b
\ln\frac{a}{b} = \ln a - \ln b
Power rule The exponent moves to the front, which is how these equations get solved.
\log(x^n) = n\log x
\log(x^n) = n\log x
Exponential pairing ln is the inverse of exp, so composed they cancel.
e^{\ln x} = x
e^{\ln x} = x

Worked examples

Solving a logarithmic equation

\log_2(x+1) = 3 \iff x+1 = 2^{3} \iff x = 7
\log_2(x+1) = 3 \iff x+1 = 2^{3} \iff x = 7

Chained equivalences on one displayed line; the argument keeps its parentheses throughout.

Sum of logs

\log_2 8 + \log_2 4 = \log_2 32 = 5
\log_2 8 + \log_2 4 = \log_2 32 = 5

Same base throughout, which is the precondition for merging them.

Square of a log versus log of a square

\log^2 x \neq \log x^2
\log^2 x \neq \log x^2

The left is (log x)², the right is log(x²). Position of the exponent carries the whole difference.

Order-of-magnitude statement

\log_{10}(6.02 \times 10^{23}) \approx 23.78
\log_{10}(6.02 \times 10^{23}) \approx 23.78

Scientific notation nests inside a log argument without extra syntax.

Common mistakes

  • \log_10 x when \log_{10} x was meant: only the 1 lands under the operator and the 0 escapes.
  • Writing ln or log without the backslash, which sets them as italic products of variables.
  • Omitting brackets on a compound argument: \log x + 1 is log(x) + 1, not log(x + 1).
  • Assuming \ln^2 x is self-explanatory. It is conventional but ambiguous next to \ln(x^2); spell out which you mean in prose.

Questions about this notation

What is the LaTeX command for natural log?
\ln. It takes the argument the same way \log does, so \ln 2 and \ln(x+1) are both valid, and there is no separate base subscript because the base is always e.
Does \log need brackets around its argument?
Only when the argument is more than one token. \log x, \log 2 and \log n work bare; \log(x+1) or \log\frac{x}{y} needs delimiting, otherwise the addition falls outside the function.
How do I write log base e minus one?
Carefully: \log_{e-1} x braces the whole base. Without braces the subscript stops at the e and the rest prints at normal height, which reads as an entirely different expression.
How do I write a logarithm whose base is an expression, or a squared logarithm?
The base is a subscript argument, so brace it whenever it is more than one token: \log_{a+b} x, \log_{10} x. A squared logarithm is \log^2 x, following the convention shared with trig functions, and it means (\log x)^2; write the parentheses out if your readers may take it as \log(x^2). \ln is built in and means base e.

Keep reading

Three ways into the same idea: the notation itself, the lesson that teaches it, and an article that applies it.