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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


share|improve this question
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
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:


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

   &\If & \abs(dx) &= \abs(dy) && \Then \\
   && step &= \abs(dx) \\
   &\Else \\
   && step &= \abs(dy)

It will look like this:

enter image description here

share|improve this answer

Your Answer


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.