Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 7 down vote accepted

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}

enter image description here

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

share|improve this answer
    
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
1  
@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
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.