Logarithm in LaTeX (\log)

log⁡\log
LaTeX command
\log
Package
No package needed: built into LaTeX
Mode
Math mode only

Where it is used

Typesets the logarithm function name in upright roman type with correct spacing before its argument.

\log is one of LaTeX's predefined function names, so it prints upright log and inserts a thin space before the argument, unlike typing log, which italicizes three variables. Add a base with a subscript, as in \log_2 n for binary logarithms; in algorithm analysis an unsubscripted \log usually means base 2, while in mathematics it often means the natural log, so state the convention. LaTeX also predefines \lg for base-2 logs and \ln for natural logs. When the argument is more than one symbol, add parentheses, for example \log(n+1), and use \left( \right) for tall arguments.

Minimal compilable example

Paste this into an empty .tex file and compile it with pdfLaTeX, XeLaTeX or LuaLaTeX.

log⁡2n=ln⁡nln⁡2\log_2 n = \frac{\ln n}{\ln 2}
\documentclass{article}
\begin{document}
Logarithm: $\log$

\[ \log_2 n = \frac{\ln n}{\ln 2} \]
\end{document}

Related symbols

All コンピュータサイエンス →

Frequently asked questions

How do I write Logarithm in LaTeX?
Type \log in math mode, for example $\log_2 n = \frac{\ln n}{\ln 2}$. It works in plain LaTeX without loading any package.
Which package do I need for \log?
None. \log is part of standard LaTeX, so it compiles with nothing in the preamble but the document class.
Can I use \log in text mode, or only in math mode?
Only in math mode. Outside $...$ LaTeX stops with "Missing $ inserted", so write $\log$ in running text.
Math poweredAIでLaTeXを書く

最高のAI LaTeXエディタ、Overleaf代替

Octreeは15以上の大学の研究者がAIを使って論文をより速く書くのを支援

  • AIで美しいTikZダイアグラムを生成
  • 画像をアップロードしてシームレスにLaTeXに変換
  • 論文の執筆とフォーマットに即座にサポートを取得