Math Functions in LaTeX: log, ln, exp, argmax, floor, ceiling, absolute value and norm

Function names in mathematics are set upright, not in italics, and with a small space before their argument: log x, not log x. LaTeX gets this right only if you use the operator commands. This guide lists every predefined function, shows how to define your own (argmax, sgn, tr) with the right spacing and limits, and covers the delimiters that go with them: floor and ceiling, absolute value bars and norms, roots, fractions, function notation and piecewise definitions.

Why \log and Not log

In math mode every letter is a variable, so $log(x)$ is typeset as the product l·o·g in italics, with no spacing logic. \log is an operator: upright roman, and LaTeX inserts a thin space between it and what follows unless that is a parenthesis:

$log(x)$   $sin x$      % wrong: italic variables l, o, g
$\log(x)$  $\sin x$     % right: upright, correctly spaced
$\log_2 x$  $\log_{10} x$  $\ln x$  $\lg x$

The base of a logarithm is a subscript on the operator. \ln is the natural logarithm and \lg exists too; ISO 80000-2 defines lg as base 10 and lb as base 2, but there is no \lb command, so define it if you need it (see below). Powers go on the operator as well: \sin^2 x and \log^2 x are standard, though \log(x)^2 is clearer when there is any chance of confusion with \log x^2.

All Predefined Function Operators

All of these are built into LaTeX itself except the \var..., \injlim and \projlim variants, which need amsmath. Operators marked with limits take their subscript underneath in display math, like \lim_{x \to 0}:

GroupCommands
Trigonometric\sin \cos \tan \cot \sec \csc
Inverse trigonometric\arcsin \arccos \arctan (write \operatorname{arccot} for the others)
Hyperbolic\sinh \cosh \tanh \coth
Logarithms and exponential\log \ln \lg \exp
Limits (limits below)\lim \limsup \liminf; with amsmath also \varlimsup \varliminf \injlim \projlim \varinjlim \varprojlim
Extrema (limits below)\max \min \sup \inf
Algebra\det \dim \ker \deg \gcd \hom \arg \Pr (\det, \gcd and \Pr take limits below)
\[ \lim_{x \to 0} \frac{\sin x}{x} = 1, \qquad
   \max_{i} a_i, \qquad \gcd(a, b), \qquad \Pr(X \le x), \qquad \det A \]

Inline, the subscript of a limit-taking operator sits to the right (limx→0) so the line spacing stays even; add \limits after the operator if you insist on it underneath, or wrap the formula in \displaystyle.

Exponentials: e^x versus \exp

Both are correct; choose by the size of the argument. A short exponent reads best as a superscript, a long one as \exp so the reader does not have to squint at a tiny fraction:

\[ e^{x}, \qquad e^{-x^2/2\sigma^2}, \qquad
   \exp\left(-\frac{x^2}{2\sigma^2}\right) \]

ISO and many physics journals set the constant upright as \mathrm{e}; most mathematics journals leave it italic. Pick one and keep it consistent, ideally through a macro such as \newcommand{\e}{\mathrm{e}}.

Defining Your Own: argmax, sgn, tr and operatorname

argmax, argmin, sgn, tr, rank, Var, softmax and the like have no command. For a one-off use \operatorname{...}; for anything you use more than once, define it in the preamble with amsmath's \DeclareMathOperator. The starred form makes subscripts go underneath in display math, which is what argmax needs:

\usepackage{amsmath}
\DeclareMathOperator*{\argmax}{arg\,max}   % * = limits go below
\DeclareMathOperator*{\argmin}{arg\,min}
\DeclareMathOperator{\sgn}{sgn}
\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\rank}{rank}
\DeclareMathOperator{\lb}{lb}               % binary logarithm

\[ \hat\theta = \argmax_{\theta \in \Theta} \mathcal{L}(\theta), \qquad
   \operatorname*{arg\,max}_{x} f(x), \qquad
   \sgn(x), \quad \tr(A), \quad \operatorname{softmax}(z)_i \]

The \, inside arg\,max is a thin space; without it the two words run together. \DeclareMathOperator may only be used in the preamble, and it refuses to redefine an existing command, so if a class or package already provides \argmax you will see Command \argmax already defined; delete your definition or use \renewcommand with \operatorname*. Do not reach for \mathrm{argmax}: it gives upright letters but none of the operator spacing, and limits would be set as ordinary subscripts.

Floor and Ceiling

Floor and ceiling are not operators but pairs of delimiters, so they are written with the bracket commands \lfloor \rfloor and \lceil \rceil:

\[ \lfloor x \rfloor, \quad \lceil x \rceil, \quad
   \left\lfloor \frac{n}{2} \right\rfloor, \quad
   \lceil \log_2 n \rceil \]

\left and \right scale the brackets to the content; use them around fractions and leave them off around a single symbol. With mathtools you can wrap this into a command that handles both cases (next section).

Absolute Value: |x|, \lvert x \rvert and \left| x \right|

Typing |x| works for a quick formula, but the vertical bar is an ordinary symbol with no idea of whether it opens or closes, so the spacing is wrong next to operators: $|-x|$ has an uneven gap around the minus. amsmath provides \lvert and \rvert, which are real opening and closing delimiters:

\usepackage{amsmath}
\[ |x|, \qquad \lvert x \rvert, \qquad \lvert -x \rvert,
   \qquad \left\lvert \frac{a}{b} \right\rvert \]

The same three choices exist for every delimiter: plain for a single letter, \lvert ... \rvert for correct spacing, \left ... \right when the content is tall. \left| around a single letter is a common mistake: it adds space on both sides and is slightly too tall.

Norms: \lVert x \rVert and \|x\|

Double bars follow the same pattern. \| is a single ordinary symbol that prints two bars; \lVert and \rVert are the proper delimiters. The subscript naming the norm goes after the closing bar:

\usepackage{amsmath}   % \lVert and \rVert
\[ \|x\|, \qquad \lVert x \rVert_2, \qquad \lVert x \rVert_\infty,
   \qquad \lVert A \rVert_F, \qquad \left\lVert \frac{x}{\|x\|} \right\rVert \]

Never write ||x|| with two single bars: LaTeX sets a space between them and the result looks like four separate strokes.

mathtools: \DeclarePairedDelimiter for \abs, \norm, \floor and \ceil

mathtools (which loads amsmath) lets you define a delimiter pair as one command. The plain form gives fixed-size delimiters, the starred form inserts \left and \right, and an optional argument sets a manual size:

\usepackage{mathtools}
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}
\DeclarePairedDelimiter{\floor}{\lfloor}{\rfloor}
\DeclarePairedDelimiter{\ceil}{\lceil}{\rceil}

\[ \abs{x}, \quad \abs*{\frac{a}{b}}, \quad \abs[\Big]{\frac{a}{b}}, \quad
   \norm{x}_2, \quad \norm*{\frac{x}{\norm{x}}}, \quad
   \floor{\frac{n}{2}}, \quad \floor*{\frac{n}{2}}, \quad \ceil[\big]{\frac{n}{2}} \]

This is the recommended way to handle absolute values and norms in any document longer than a page: the notation is consistent, and if a journal wants different delimiters you change one line.

Roots and Fractions

\usepackage{amsmath}   % \dfrac, \tfrac and \binom
\[ \sqrt{x}, \quad \sqrt[3]{x}, \quad \sqrt[n]{x^2 + 1}, \quad
   \frac{a}{b}, \quad \dfrac{a}{b}, \quad \tfrac{a}{b}, \quad
   \binom{n}{k} = \frac{n!}{k!\,(n-k)!} \]

\sqrt[n]{...} takes the index as an optional argument. \frac adapts to its context, \dfrac forces display size and \tfrac forces text size; \binom, \dbinom and \tbinom do the same for binomial coefficients. Inline, prefer a/b or \tfrac for simple ratios so the line spacing is not pushed apart.

Function Notation: f\colon A \to B, \mapsto, composition and inverses

A function is declared with its domain and codomain using \colon rather than a bare colon (which is spaced as a relation, with too much room on the left) and \to; the rule is written with \mapsto:

\[ f\colon \mathbb{R} \to \mathbb{R}, \quad x \mapsto x^2, \qquad
   (g \circ f)(x) = g(f(x)), \qquad f^{-1}(y), \qquad
   f'(x), \; f''(x), \; f^{(n)}(x) \]

\mathbb needs amssymb. \circ is composition, and f^{-1} is the inverse (note that \sin^{-1} x means arcsin, which is why \arcsin is clearer). Derivatives use primes, and the differential is often set upright, \frac{\mathrm{d}y}{\mathrm{d}x}, with \partial for partial derivatives:

\[ \frac{\mathrm{d}}{\mathrm{d}x} \sin x = \cos x, \qquad
   \frac{\partial f}{\partial x}, \qquad
   \frac{\partial^2 f}{\partial x\, \partial y}, \qquad \nabla f \]

Piecewise Functions with cases

amsmath's cases environment sets the brace and aligns the conditions; separate the value and the condition with & and put the condition text in \text:

\[ |x| = \begin{cases}
     x  & \text{if } x \ge 0, \\
     -x & \text{if } x < 0.
   \end{cases} \]

Fractions inside cases are set in text style; use \dfrac there if they are hard to read, or mathtools' dcases environment, which does it for every line.

The physics Package: Convenient, with Caveats

The physics package offers ready-made \abs, \norm, \dv{f}{x}, \pdv{f}{x}, \grad, \curl and more, with automatic sizing by default:

\usepackage{physics}
\[ \abs{x}, \quad \norm{v}, \quad \dv{f}{x}, \quad \pdv[2]{f}{x}, \quad
   \grad f, \quad \div \vb{F}, \quad \curl \vb{F} \]

Three things to know before adopting it. It redefines \div, so the division sign ÷ is gone. It defines \abs and \norm itself, so combining it with the mathtools definitions above fails with Command \abs already defined; pick one. And its argument parsing is unusual (it looks ahead for parentheses), which produces surprising output in edge cases. The newer physics2 and derivative packages fix these problems and are the better choice for a new document.

Common Errors and Fixes

Symptom or messageCauseFix
Function name in italics, no space before the argumentlog x instead of \log xUse the operator command or \operatorname
Undefined control sequence \argmax (or \sgn, \tr, \abs, \norm)Not predefined\DeclareMathOperator / \DeclarePairedDelimiter in the preamble
Undefined control sequence \lvert / \dfrac / \textamsmath not loaded\usepackage{amsmath} (or mathtools)
Command \abs already definedphysics and a mathtools definition both define itRemove one; or name yours differently
Can be used only in preamble\DeclareMathOperator inside the documentMove it before \begin{document}; use \operatorname in the body
Missing \right. inserted / Extra \right\left and \right not paired in the same line or groupPair them; use \right. for an invisible closing delimiter
Subscript of argmax or lim sits to the right in display mathDefined without the star, or \mathrm used\DeclareMathOperator* or \operatorname*
Missing $ inserted around \frac or \sqrtMath command used in textWrap in $...$ or \[...\]
Bars around a single letter look too wide\left| ... \right| on a small argumentUse \lvert ... \rvert or the unstarred paired delimiter

Complete Example

\documentclass{article}
\usepackage{amsmath, amssymb}
\usepackage{mathtools}
\DeclareMathOperator*{\argmax}{arg\,max}
\DeclareMathOperator{\sgn}{sgn}
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}
\DeclarePairedDelimiter{\floor}{\lfloor}{\rfloor}

\begin{document}
Let $f\colon \mathbb{R}^n \to \mathbb{R}$ be differentiable. The maximiser
\[
  x^\star = \argmax_{x \in \mathbb{R}^n} f(x)
  \quad\text{satisfies}\quad
  \norm{\nabla f(x^\star)}_2 = 0 .
\]
For $x \neq 0$ we have $\sgn(x) = x / \abs{x}$, and
\[
  \ln\bigl(\exp(x)\bigr) = x, \qquad
  \log_2 n \le \floor{\log_2 n} + 1, \qquad
  \lim_{x \to 0} \frac{\sin x}{x} = 1 .
\]
The sign function is piecewise:
\[
  \sgn(x) = \begin{cases}
    1  & \text{if } x > 0, \\
    0  & \text{if } x = 0, \\
    -1 & \text{if } x < 0.
  \end{cases}
\]
\end{document}

Quick Reference

FunctionLaTeX
Logarithm, base 2, natural\log x, \log_2 x, \ln x
Exponentiale^{x}, \exp(x)
Trigonometric and inverse\sin x, \cos x, \tan x, \arcsin x, \sinh x
Limit, max, min, sup, inf\lim_{x \to a}, \max_i, \sup_x
argmax / argmin\DeclareMathOperator*{\argmax}{arg\,max} then \argmax_x
Custom operator\operatorname{sgn} or \DeclareMathOperator{\sgn}{sgn}
Floor, ceiling\lfloor x \rfloor, \lceil x \rceil
Absolute value\lvert x \rvert; \abs{x} with \DeclarePairedDelimiter
Norm\lVert x \rVert_2, \|x\|; \norm{x}
Auto-sized delimiters\left\lvert ... \right\rvert, \abs*{...}
Roots\sqrt{x}, \sqrt[n]{x}
Fractions\frac, \dfrac, \tfrac, \binom
Function declarationf\colon A \to B, x \mapsto f(x)
Composition, inverseg \circ f, f^{-1}
Derivativesf'(x), \frac{\mathrm{d}y}{\mathrm{d}x}, \partial
Piecewise\begin{cases} ... \end{cases}

Frequently Asked Questions

How do I write log base 2 or log base 10 in LaTeX?

Put the base in a subscript on the operator: \log_2 x and \log_{10} x. Braces are needed when the base has more than one character. \ln x is the natural logarithm and \lg x is defined as well; ISO 80000-2 reserves lg for base 10 and lb for base 2, and \lb does not exist, so define it with \DeclareMathOperator{\lb}{lb} if you follow that convention.

Why does my function name come out in italics?

Because you typed log or sin as plain letters, which LaTeX treats as the product of the variables l, o and g. Use the operator commands \log, \sin, \exp and so on; they set the name upright and add the correct space before the argument. For a function that has no command, write \operatorname{name}, or define it once in the preamble with \DeclareMathOperator.

How do I write argmax with the argument underneath?

Load amsmath and define the operator with the starred form, \DeclareMathOperator*{\argmax}{arg\,max}. The star makes subscripts go below the operator in display math, like \lim and \max, so \argmax_{\theta} f(\theta) puts θ underneath. In inline math the subscript stays to the right unless you add \limits.

What is the difference between |x|, \lvert x \rvert and \left| x \right|?

A plain | is an ordinary symbol, so LaTeX does not know whether it opens or closes and spaces it badly next to minus signs and operators. \lvert and \rvert from amsmath are proper opening and closing delimiters with correct spacing. \left| ... \right| additionally scales the bars to the height of the content, which you want around fractions but not around a single letter, where it adds unwanted space. The cleanest option is a mathtools paired delimiter: \DeclarePairedDelimiter{\abs}{\lvert}{\rvert} gives \abs{x} for fixed bars and \abs*{...} for scaled ones.

How do I typeset a norm in LaTeX?

Use \lVert x \rVert, or \| x \| for a quick fixed-size version. Subscripts for the type of norm go after the closing delimiter, \lVert x \rVert_2, \lVert x \rVert_\infty, \lVert A \rVert_F. With mathtools, \DeclarePairedDelimiter{\norm}{\lVert}{\rVert} lets you write \norm{x}_2 and \norm*{...} for automatic sizing.

Should I use \frac or \dfrac?

\frac picks the style for you: full-size in display math and small in inline math. \dfrac forces the display size and \tfrac the small text size regardless of context. Use \dfrac sparingly in inline text, as it stretches the line spacing; it is most useful inside a matrix or a cases environment where \frac would be reduced.

Next Steps

Functions sorted? These guides cover the rest of math typesetting:

Free LaTeX Tools

Write math faster with AI

Octree's AI editor turns “argmax over theta of the likelihood” into correct LaTeX, defines the operators you need in the preamble, and compiles your document in seconds.

Try Octree Free →