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 poweredاكتب LaTeX باستخدام الذكاء الاصطناعي

أفضل محرر LaTeX بالذكاء الاصطناعي، بديل Overleaf

يساعد Octree الباحثين من أكثر من 15 جامعة على كتابة أوراق البحث بشكل أسرع باستخدام الذكاء الاصطناعي

  • أنشئ رسوم TikZ جميلة باستخدام الذكاء الاصطناعي
  • ارفع صورة وحولها إلى LaTeX بسلاسة
  • احصل على مساعدة فورية في كتابة وتنسيق أوراق البحث