# Error in built output

This is difficult for me with all these $signs. Now, where is the problem in the following MWE? \documentclass{article}% \usepackage{amsmath}% \usepackage{amsfonts}% \usepackage{amssymb}% \usepackage{graphicx} \usepackage{comment} \begin{document} \varphi_{nk}(x,y) = \left\{ \begin{array}{c l} 1 &$x_{k}\succ_{n} y_{k}$\\ 1/2 &$x_{k} \sim_{n} y_{k}$\\ 0 &$x_{k}\prec_{n} y_{k}$\end{array} \right. So \textit{n} is \varphi_{n}(x,y)= \sum_{k}\varphi_{nk} \end{document}  Also a more general question related to Tex.sx. How can I copy the code to the question box, without having to press space bar 4 times for each line to indent it? As a follow up, in case I would like to insert the word 'if' in every case (piece) of the function above, how can I do so? Eg ...1/2 & if$x_{k}\succ_{n} y_{k}$ doesn't seem to work as the 'if' is conjoined. - Re "question box" (code sample): Highlight the code and click the "code" button (with "{}" on it). – lockstep Oct 1 '11 at 9:23 For questions about the site, please visit TeX - LaTeX Meta. – Stefan Kottwitz Oct 1 '11 at 9:23 add comment ## 2 Answers Don't use $ within an array environment, since the array environment is completely in math mode.

\documentclass{article}
\usepackage{amsmath}%
\usepackage{amsfonts}%
\usepackage{amssymb}%
\begin{document}
$\varphi_{nk}(x,y) = \left\{ \begin{array}{c l} 1 & x_{k}\succ_{n} y_{k}\\ 1/2 x_{k} \sim_{n} y_{k}\\ 0 & x_{k}\prec_{n} y_{k} \end{array} \right.$
So $n$ is $\varphi_{n}(x,y)= \sum_{k}\varphi_{nk}$.
\end{document}


• Use math expressions such as \varphi_{nk}(x,y) in math mode, either within text (inline) such as by $...$ or $$...$$ or in displayed mode, such as by $...$ in my example.

• Don't use empty lines before or after such displayed math formulas.

• Don't use \textit for simulating math mode.

Have a look at the Mathmode tag wiki for links to tutorials, useful packages and resources on this site.

-

You should read Math mode (H. Voß). With $...$ you always use the inline math.

You example can be modified with the cases-environment:

\documentclass{article}%

\usepackage{amsmath}%
\usepackage{amsfonts}%
\usepackage{amssymb}%
\usepackage{graphicx}
\usepackage{comment}

\begin{document}
$$\varphi_{nk}(x,y) = \left\{ \begin{array}{c l} 1 & x_{k}\succ_{n} y_{k}\\ 1/2 & x_{k} \sim_{n} y_{k}\\ 0 & x_{k}\prec_{n} y_{k} \end{array} \right.$$
So \textit{n} is$\varphi_{n}(x,y)= \sum_{k}\varphi_{nk}$

$$\varphi_{nk}(x,y) = \begin{cases} 1 & x_{k}\succ_{n} y_{k}\\ 1/2 & x_{k} \sim_{n} y_{k}\\ 0 & x_{k}\prec_{n} y_{k} \end{cases}$$
So \textit{n} is$\varphi_{n}(x,y)= \sum_{k}\varphi_{nk}$
\end{document}

-