Logarithm in LaTeX (\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.
\documentclass{article}
\begin{document}
Logarithm: $\log$
\[ \log_2 n = \frac{\ln n}{\ln 2} \]
\end{document}Related symbols
All Computer Science →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.
Pinakamahusay na AI LaTeX Editor, Alternatibo sa Overleaf
Tinutulungan ng Octree ang mga researcher mula sa 15+ na unibersidad na sumulat ng research papers nang mas mabilis gamit ang AI
- Gumawa ng magagandang TikZ diagrams gamit ang AI
- Mag-upload ng larawan at i-convert ito sa LaTeX nang walang problema
- Makakuha ng instant na tulong sa pagsulat at pag-format ng research papers