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.

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

share|improve this question
5  
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
3  
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
add comment

1 Answer

up vote 8 down vote accepted

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:

enter image description here

share|improve this answer
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.