Constant errors for missing symbols in equation environment

I realise this sounds like a daft question, but I have a lot of missing symbols coming up in my work, but they are there!

One such example is

$$\label{eq:rgbtohsb} \begin{center} Hue = \left\{\begin{array}{ccc} \frac{g - b}{max(r,g,b)- min(r,g,b)} & \quad \text{if } & max(r,g,b) = r\\ \frac{b-r}{max(r,g,b)- min(r,g,b)} & \quad \text{if } & max(r,g,b) = g \\ \frac{r-g}{max(r,g,b)- min(r,g,b)} & \quad \text{if } & max(r,g,b) = b \\ \end{array} Saturation = \left \{ \begin{array}{ccc} 0 & \text{if } & r = g = b\\ \frac{max(r,g,b)}{V} & \quad \text{ otherwise} \\ \end{array}  Value = max(r,g,b) Lightness = \frac{1}{2}(max(r,g,b) + min(r,g,b))  \end{center}$$


As you can see I do indeed have all of the $. Also I have the \begin{center} and \end{center} Another error, is that it says \begin{document} ended by Here is the header I am using \documentclass[a4paper,11pt,twoside]{article} \usepackage[left=2.5cm,right=2cm,top=2cm,bottom=2cm]{geometry} \usepackage{fancyhdr} \usepackage{mathtools} \usepackage[parfill]{parskip} \usepackage{program} \pagestyle{fancyplain} \fancyhf{} \rhead{\fancyplain{}{\today}} \cfoot{\fancyplain{}{\thepage}} \usepackage{graphicx} {\tiny }  I do have an \end{document} Thanks for your help! - You can't change in math-mode (started by to inline-math-mode ($) as far as I know. Also i don't think you can use center in an equation, but I didn't test it. – Juri Robl Aug 30 '12 at 13:14
The problem has nothing to do with TeXstudio. – Guido Aug 30 '12 at 13:40

There are four mistakes in your example.

• You don't need \begin/end{center} for displayed equations; they are centred by default.

• You don't need dollar signs inside an equation environment; you are in maths mode already.

• You can't have \left without a matching \right, though you can use \right. if you don't want the right delimiter.

• You can't have empty lines inside an equation environment.

A corrected version (with unnecessary material removed) is as follows. If you don't want the equations to be numbered, you can use equation* in place of equation, and you can abbreviate\begin{equation*} and \end{equation*} to $ and $. Finally, note that there are predefined commands \max and \min which produce better results than just typing 'max' and 'min'.

\documentclass[a4paper,11pt,twoside]{article}
\usepackage{mathtools}
\begin{document}
$$\label{eq:rgbtohsb} \text{Hue} = \left\{ \begin{array}{ccc} \frac{g - b}{max(r,g,b)- \min(r,g,b)} & \quad \text{if } & \max(r,g,b) = r\\ \frac{b-r}{max(r,g,b)- \min(r,g,b)} & \quad \text{if } & \max(r,g,b) = g \\ \frac{r-g}{max(r,g,b)- \min(r,g,b)} & \quad \text{if } & \max(r,g,b) = b \\ \end{array} \right.$$
%
$$\text{Saturation} = \left \{ \begin{array}{ccc} 0 & \text{if } & r = g = b\\ \frac{\max(r,g,b)}{V} & \quad \text{ otherwise} \\ \end{array} \right.$$
%
$$\text{Value} = \max(r,g,b)$$
%
$$\text{Lightness} = \frac{1}{2}(\max(r,g,b) + \min(r,g,b))$$
\end{document}


The amsmath package (which is automatically loaded when you load mathtools) provides lots of other environments for formatting mathematics, some of which (e.g. gather) may be better than equation, depending on the structure of your actual document. You might also find it useful to read the Not so Short Introduction to LaTeX.

-
 is unnumbered, equation is numbered. It could appear that the OP wished a single number for everything, in which case one could replace center with gathered. Last suggestion, perhaps use \max and \min? – Torbjørn T. Aug 30 '12 at 13:35
@Guido --- Indeed. I was thinking of equation*. – Ian Thompson Aug 30 '12 at 13:35
Sorry for nagging, but one more thing: I think one generally should not have several equations in sequence, but rather use a gather. – Torbjørn T. Aug 30 '12 at 13:41
@TorbjørnT. --- I wasn't sure exactly what result the OP wanted, so I just fixed the errors. However, I have added a link to the amsmath documentation. – Ian Thompson Aug 30 '12 at 13:55