TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

However I turn and twist it, for some reason I can't get the two lines I have commented out to work. It keeps giving me the error: "Undefined control sequence."

\caption{RIGHT-ROTATE algorithm}\label{right} 
\Procedure{Right-Rotate}{$T,y$}\Comment{right rotation of an binary search tree}
\State{$x = y.left$}
\If{$y.right \neq T.nil$}
\State{$y.right.p = x$}
\State{$x.p = y.p$}
\If{$y.p == T.nil$}
\State{$T.root = x$}
%\ElseIf{$y == y.p.right$}
%\State{$y.p.right = x$}
\Else \,{$y.p.left = x$}
share|improve this question

migrated from stackoverflow.com Feb 26 '12 at 15:30

This question came from our site for professional and enthusiast programmers.

up vote 9 down vote accepted

It’s \ElsIf, not \ElseIf (note the missing e).

Furthermore, algorithm pseudocode can (and should, for readability) be indented as usual in LaTeX:

\If{$y.p == T.nil$}
    \State{$T.root = x$}
\ElsIf{$y == y.p.right$}
    \State{$y.p.right = x$}
    \,{$y.p.left = x$}
share|improve this answer
How silly of me staring my self blind on that little thing, thanks for the answer. – kAlz Feb 25 '12 at 21:29

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.