Absolute Value Symbols

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}

Note if you just use | you get mathord spacing, which is different from the spacing you'd get from paired mathopen/mathclose delimiters or from \left/\right even if \left/\right doesn't stretch the symbol. Personally I prefer the left/right spacing from mathinner here (even if @egreg says I'm generally wrong:-)

\documentclass{amsart}

\begin{document}

$  \log|x||y|b $

$  \log\left|x\right|\left|y\right|b $

$  \log\mathopen|x\mathclose|\mathopen|y\mathclose|b $

\end{document}

enter image description here


One can also use commath package.

\documentclass{article}

\usepackage{commath}

\begin{document}
\[ \norm{a \vec{u}} = \abs{a} \, \norm{\vec{v}} \]
\end{document}

enter image description here