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 컴퓨터 과학 →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.
최고의 AI LaTeX 편집기, Overleaf 대안
Octree는 15개 이상의 대학의 연구자들이 AI를 사용하여 논문을 더 빠르게 작성하도록 도움
- AI로 아름다운 TikZ 다이어그램 생성
- 이미지를 업로드하고 LaTeX로 원활하게 변환
- 논문 작성 및 서식에 대한 즉각적인 지원 받기