Conditional equations with with one curly bracket in LaTex?

How would I code something like this I've got the code

\begin{equation}
L =
\begin{cases}
1 & \text{if $i = j$ and $deg_j \neq 0$} \\
stuff & \text{if $(i, j) \in E$} \\
0 & \text{otherwise}
\end{cases}
\end{equation}

but where stuff is I want to use -\frac{1}{\sqrt{deg_ideg_j}} and where L is I want the Laplacian symbol \mathcal{L}. Whenever I try to put them in I get an error message that says "Missing $inserted" and I'm not exactly sure what it means, or how to fix it. Any help would be greatly appreciated. • Welcome to TeX.SE. You don't need the$ in stuff. You are already in math mode at that time. The $are required if you have math within \text{} as then you are in text mode, not math mode. – Peter Grill Jan 18 '16 at 1:37 • Sorry, that was a typo. Even without the$ before it still comes up with the same error. I've just updated it. – BriKil Jan 18 '16 at 1:40
• I can't reproduce the error when I complete your code in the obvious way. Could you please provide a complete document i.e. add the document class and required preamble etc. so that when you copy-paste-compile the code, it gives the error you want help with? – cfr Jan 18 '16 at 2:02

This seems to work fine:

\documentclass{article}
\usepackage{amssymb,mathtools}
\begin{document}
\begin{equation}
\mathcal{L} =
\begin{cases}
1 & \text{if $i = j$ and $deg_j \neq 0$} \\
-\frac{1}{\sqrt{deg_i deg_j}} & \text{if $(i, j) \in E$} \\
0 & \text{otherwise}
\end{cases}
\end{equation}
\end{document} • This works great for cases, as opposed to the dcases*, mentioned above. Thank you for your help as well! – BriKil Jan 18 '16 at 2:50

I suggest you use a dcases* environment (provided by the mathtools package, a superset of the amsmath package) for the job at hand. This environment differs from the cases environment in two important ways: (i) the math part (before the & separator) will be typeset in display-style math, and (ii) there's no need to wrap the text-material (after the & symbol) in \text macros. \documentclass{article}
\usepackage{mathtools} % for "dcases*" environment
\begin{document}
$\widehat{L}(u,v) = \begin{dcases*} 1 & if u=v and d_v\ne 0 \\ -\frac{1}{\sqrt{d_u d_v}} & if (u,v)\in E \\ 0 & otherwise \end{dcases*}$
\end{document}
• Can you change your example to give the output the OP wants? Then I'll delete my answer. – cfr Jan 18 '16 at 2:19
• @cfr - In view of the fact that the OP has accepted your answer in the meantime, I'd rather not change the code above. :-) – Mico Jan 18 '16 at 2:47
• I can see my mistake now, I wasn't using the correct package. Only had amsmath. Thank you very much for your help – BriKil Jan 18 '16 at 2:47
• @BriKil - If you're going to use the cases environment, there's no need to load the mathtools environment. The mathtools environment is needed only if you want to use the dcases* environment. – Mico Jan 18 '16 at 2:49
• I upvoted yours. But yours is better, so I have an excuse. @BriKil I added \usepackage{amssymb,mathtools} automatically. It isn't required for the answer I posted to work. amsmath is enough. – cfr Jan 18 '16 at 2:52