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.

I have the following LaTeX code (beginning from line 80):

\begin{definition}
$\hat{n}_{v}$ = \begin{cases}
$n_{v}$ & \text{ if } $v \in$ \text{connected component of size} $< \frac{2}{\epsilon}$
 \\
$\frac{2}{\epsilon}$ & \text{ otherwise }
\end{cases}

\end{definition}

However, when I want to compile this code, I get the following error:

./lect42.tex:80: Missing $ inserted.
<inserted text> 
                $
l.80 $\hat{n}_{v}$ = \begin{cases}

I looked at the code carefully, but there are no missing $'s. Why I get this error?

share|improve this question
    
The cases environment is defined only for math mode AFAIK, as part of the amsmath bundle. –  Count Zero Sep 8 '12 at 20:30
add comment

1 Answer 1

up vote 6 down vote accepted

You have lots of unnecessary dollar symbols, and one missing from the end.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\hat{n}_{v} = \begin{cases}
n_{v} & \text{ if } v \in \text{connected component of size} < \frac{2}{\epsilon}
 \\
\frac{2}{\epsilon} & \text{ otherwise }
\end{cases}
$
\end{document}

As this is quite a large expression, I would be inclined to use \[ and \] instead of the dollar signs, to create a displayed equation, rather than an in-text equation. You could also use \displaystyle to enlarge the fractions.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\hat{n}_{v} = \begin{cases}
n_{v} & \text{ if } v \in \text{connected component of size} < \displaystyle\frac{2}{\epsilon} \\
\displaystyle\frac{2}{\epsilon} & \text{ otherwise }
\end{cases}
\]
\end{document}
share|improve this answer
    
thanks, that worked like a charm! i thought i was being cautious by putting those $'s everywhere.. –  user39084 Sep 8 '12 at 20:44
1  
I'd use dfrac instead of \displaystyle\frac –  cmhughes Sep 8 '12 at 21:16
    
@cmhughes In that case it doesn't matter much, because the fractions are the last thing in the cell; but yes, in general \dfrac would be better. –  egreg Sep 17 '12 at 12:50
add 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.