# Newline in equations

The code looks something like:

        $$If \ abs(dx) = abs(dy) \ then \\ step = abs(dx)\\ else \\ step = abs(dy)\\$$


I want the '\\' to behave as in normal way (newline) but it does not display a newline.

Thanks

-
I think the algorithms package might be better suited for your needs than simple mathmode. –  Martin Scharrer Mar 30 '11 at 14:21
Thanks. Let me try it. –  check123 Mar 30 '11 at 14:31
I use the lstlisting-package for advanced code listing. the documentation is quite helpful. –  kromuchi Mar 30 '11 at 14:34
Something else, the use of $$…$$ for equations is deprecated in LaTeX. Use $…$ instead. –  Konrad Rudolph Mar 30 '11 at 17:38
@Konrad, Thanks for that information. –  check123 Apr 4 '11 at 3:51

I agree with the comments above that algorithms, algorithmic or lstlisting packages are probably best for this kind of work, but in the case you want to only do something fairly simple, and you don't want to learn new package, you can use some of the amsmath environments, for example like this:

\documentclass{article}
\usepackage{amsmath}

\newcommand\If{\text{If }}
\newcommand\Then{\text{ then }}
\newcommand\Else{\text{else }}
\DeclareMathOperator\abs{abs}

\begin{document}
\begin{alignat*}{3}
&\If & \abs(dx) &= \abs(dy) && \Then \\
&& step &= \abs(dx) \\
&\Else \\
&& step &= \abs(dy)
\end{alignat*}
\end{document}


It will look like this:

-