[Tex/LaTex] Latex question “Missing $ inserted

equations

I want to write this simple equation in latex

    2/|w|

In which |w| is the norm of w,,

I tried with

     \frac{2}{\|w\|}

And get error "Missing $ inserted"

then I use this

  \frac{2}{$\|w\|$}

And still get same error..

Does someone know how to solve this problem??

Best Answer

You'll need to include the whole thing in a math environment, as \frac is a math command.

\documentclass[]{article}

\usepackage[width=2in]{geometry}
\begin{document}

Inline: $ \frac{2}{\|w\|}$ \\[2em]

Display:
\[ \frac{2}{\|w\|} \]

Numbered Display:
\begin{equation} \frac{2}{\|w\|} \end{equation}

\end{document}

Result:

formulas

Related Question