Use a symbol in a formula that's been defined over elsewhere

In my document preamble, I'm using:

\usepackage{fancyvrb}
\DefineShortVerb{\|}


It means I can indicate that things are to be rendered as code with |This_is_monospaced|, but now I'm trying to use vertical bars to represent magnitude in a formula, as such: $|V|$ (typeset with amsmath)

What I'm currently getting is a verbatim environment within my formula.

Is there a way of temporarily disabling the monospacing behaviour so my formula still renders normally?

-

You can load amsmath

\usepackage{amsmath}


and then use

$\lvert V\rvert$


Another option is to use \UndefineShortVerb:

\documentclass{article}
\usepackage{amsmath}
\usepackage{fancyvrb}
\DefineShortVerb{\|}

\begin{document}

$\lvert V\rvert$

\UndefineShortVerb{\|}
$|V|$
\DefineShortVerb{\|}

\end{document}


As Andrew Swann mentions in his comment, in general it is preferable to use \lvert...\rvert instead of just |...|.

-
Thanks for the fast reply! Spot on. –  Fabian Tamp Sep 13 '12 at 14:21
and I'm already using amsmath :) –  Fabian Tamp Sep 13 '12 at 14:21
In fact you should always use \lvert and \rvert for |V| to get correct spacing. –  Andrew Swann Sep 13 '12 at 14:25
@AndrewSwann Can you please provide an example showing a difference in spacing using |...| and \lvert...\rvert? (I've been trying to produce one but haven't found it) –  Gonzalo Medina Sep 13 '12 at 14:29
@GonzaloMedina Actually looking this up in the TeX book page 170, there are only two situations where \lvert which is class Open and | which is class Ord differ in spacing: when they are next to an Op, i.e. a large operator. So $$\bigoplus \lvert V \rvert$$ has less space than $$\bigoplus |V|$$, similarly when the first two terms are swapped. There are more cases when spacing for \rvert differs from that for |, including the situation where the V is replaced by a \left/\right pair. amsldoc explains that there are semantic reasons to prefer \lvert etc. –  Andrew Swann Sep 13 '12 at 15:31