[Tex/LaTex] Absolute Value Symbols

math-modesymbols

What is the "best LaTeX practices" for writing absolute value symbols? Are there any packages which provide good methods?

Some options include |x| and \mid x \mid, but I'm not sure which is best…

Best Answer

I have been using the code below using \DeclarePairedDelimiter from the mathtools package.

Since I don't think I have a case where I don't want this to scale based on the parameter, I make use of Swap definition of starred and non-starred command so that the normal use will automatically scale, and the starred version won't:

enter image description here

If you want it the other way around comment out the code between \makeatother...\makeatletter.

\documentclass{article}
\usepackage{mathtools}

\DeclarePairedDelimiter\abs{\lvert}{\rvert}%
\DeclarePairedDelimiter\norm{\lVert}{\rVert}%

% Swap the definition of \abs* and \norm*, so that \abs
% and \norm resizes the size of the brackets, and the 
% starred version does not.
\makeatletter
\let\oldabs\abs
\def\abs{\@ifstar{\oldabs}{\oldabs*}}
%
\let\oldnorm\norm
\def\norm{\@ifstar{\oldnorm}{\oldnorm*}}
\makeatother

\newcommand*{\Value}{\frac{1}{2}x^2}%
\begin{document}
    \[\abs{\Value}  \quad \norm{\Value}  \qquad\text{non-starred}  \]
    \[\abs*{\Value} \quad \norm*{\Value} \qquad\text{starred}\qquad\]
\end{document}