# Comment in algorithmic on a line beginning with if, and using uncover/visible

I am trying to modify this code, into the following one :

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[plain]{algorithm}
\usepackage{algorithmic}
\usepackage{array}
\usepackage{eqparbox}
\renewcommand\algorithmiccomment[1]{%
\eqparbox{COMMENT}{#1}%
}

\begin{document}
\begin{frame}
\begin{algorithm}[H]
\begin{algorithmic}[1]
\STATE $x := 1$ \visible<2->{\COMMENT{$x_1 \in [1;1]$}}
\WHILE[\visible<2->{\COMMENT{whatever}}]{{$x < 10000$}
\STATE $x := x+1$     \COMMENT{bla}
\ENDWHILE
\end{algorithmic}
\end{algorithm}
\end{frame}

\end{document}


I just want the comment of the if block to appear on a second and different slide. That's why I used \uncover, but this isn't accepted by pdflatex during compilation.

The error is ! Undefined control sequence. (I can paste the log if you prefer)

How can I change this ? Thanks in advance

EDIT : the best option might be using algorithmicx. Thus, comments of a \While have to be pushed in the end of the same line, and not something like \WHILE[]

• Welcome to TeX.SX! What's the precise error here? – user31729 Apr 25 '15 at 15:49
• Thanks ! I edited my answer. Do you want me to paste the whole log ? – waffle Apr 25 '15 at 16:02
• I think, you're getting into trouble with verbatim content of the algorithm environments – user31729 Apr 25 '15 at 16:11

Is this requested? I am unsure, but sometimes it's better to use the \only command.

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[plain]{algorithm}
\usepackage{algorithmic}
\usepackage{array}
\usepackage{eqparbox}
\renewcommand\algorithmiccomment[1]{%
\eqparbox{COMMENT}{#1}%
}

\begin{document}
\begin{frame}
\begin{algorithm}[H]
\begin{algorithmic}[1]
\only<1>{%
\STATE $x := 1$
\WHILE[]{$x < 10000$}
\STATE $x := x+1$     \COMMENT{bla}
\ENDWHILE
}%
\only<2->{%
\STATE $x := 1$ {\COMMENT{$x_1 \in [1;1]$}}
\WHILE[\COMMENT{whatever}]{$x < 10000$}
\STATE $x := x+1$     \COMMENT{bla}
\ENDWHILE
}%
\end{algorithmic}
\end{algorithm}
\end{frame}

\end{document}

• It is. But I hoped there was a way to modify only the comment within the while, and not copy/paste the whole code. – waffle Apr 25 '15 at 16:25
• I checked : using algorithmicx is far easier in this case... Thanks for the help ! – waffle Apr 25 '15 at 16:49