# Writing math formula

Currently I'm having to write something like:

I'm writing "q" in the denominator as |\vec{q}| using the "pipe"; is it the proper way to do it?

-
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Jubobs Jun 29 at 16:48

One way to do it is the following.

Code

\documentclass{article}

\usepackage{mathtools}
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}

\begin{document}
$\frac{\vec{q} \cdot \vec{r}_j}{\abs{\vec{q}\,} \times \abs{\vec{r}_j}}$
\end{document}


Output

-
A \vec without subscripts immediately followed by a bar clashes with it, so probably \abs{\vec{q}\,} is better. –  egreg Mar 13 '13 at 11:27

As far as I'm into LaTeX this is correct. I would put your formular as

$=\frac{\vec{q}\cdot\vec{r}_j}{|\vec{q}|\times|\vec{r}_j|}$


So for getting the absolute value typing the pipe | is fine. But do not use the pipe for some expression like

{a \in A | a \notin B}


instead use \mid there.

-
You'll get wrong spacing by using |s instead of \lvert and \rvert. –  Svend Tveskæg Dec 16 '13 at 4:57