# Undefined control sequence when adding math comment to \WHILE

I'm pretty new to (La)TeX so please forgive me if this question is stupid :)

I have an algorithm that is typeset with the algorithm and algorithmic packages.

Then I have this in the algorithm:

\WHILE[growingPhase returns $topK \eq \emptyset$ \OR $\sum_{u_i^-} > k^{th}score$]
{$\exists S_i$ such that $S_i \neq \emptyset$ \AND $growingPhase()$}


Which gives me an undefined control sequence error. The same line without the comment works fine:

\WHILE{$\exists S_i$ such that $S_i \neq \emptyset$ \AND $growingPhase()$}


Also another while works fine with comments:

\WHILE[latice.maxUpperBound is the largest upper bound among the objects in the latice when fullUpdate() or lightUpdate() was last called]
{$\exists S_i$ such that $S_i \neq \emptyset$ \AND $latice.maxUpperBound > k^{th}score$}


So I'm pretty sure it's not the comment, rather the math or the \OR in the comment that makes the trouble...

A minimum (non)working example is:

\documentclass[twoside,11pt,openright]{report}

\usepackage[utf8]{inputenc}
\usepackage[danish]{babel}
\usepackage{a4}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{epsfig}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[labeled]{multibib}
\usepackage{color}
\usepackage{datetime}
\usepackage{epstopdf}
\usepackage{subfig}
\usepackage{algorithm}
\usepackage{algorithmic}

\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\renewcommand{\algorithmicforall}{\textbf{for each}}
\renewcommand{\algorithmiccomment}[1]{\hfill// \textit{#1}}

\algsetup{linenosize=\tiny}
\captionsetup[algorithm]{font={scriptsize}}

\begin{document}

\begin{algorithm}
\begin{algorithmic}[1]
\WHILE[growingPhase returns $topK \eq \emptyset$ \OR $\sum_{u_i^-} > k^{th}score$]{$\exists S_i$ such that $S_i \neq \emptyset$ \AND $growingPhase()$}
\ENDWHILE
\end{algorithmic}
\end{algorithm}
\end{document}


(also the comment gives the same error when used in a \COMMENT{} macro.)

Your MWE is missing a \STATE command. Otherwise the only error is that \eq is not defined. You should just write =.

\documentclass{report}

\usepackage{subfig}
\usepackage{algorithm}
\usepackage{algorithmic}

\renewcommand{\algorithmiccomment}[1]{\hfill// \textit{#1}}

\algsetup{linenosize=\tiny}
\captionsetup[algorithm]{font={scriptsize}}

\begin{document}

\begin{algorithm}
\begin{algorithmic}[1]
\WHILE[growingPhase returns $\mathit{topK} = \emptyset$ \OR $\sum_{u_i^-} > k^{th}\mathit{score}$]
{$\exists S_i$ such that $S_i \neq \emptyset$ \AND $\mathit{growingPhase()}$}
\STATE something
\ENDWHILE
\end{algorithmic}
\end{algorithm}
\end{document}


Included is @egreg's suggestion to add the \mathit for the multi-letter identifies. As he also says, consider using k\text{-th} (or k\mbox{-th} without amsmath) instead of superscript.

• I'll remove my answer; would you add my comments to yours? Oct 24, 2012 at 16:23
• doh of course! The = instead of \eg solved it :) Also I simply forgot the \STATE in the example, in reality quite a lot of statements follow inside the \WHILE Oct 24, 2012 at 16:28
• @egreg OK, I've done that. Oct 24, 2012 at 16:31
• I think my multiletter identifiers actually work without \mathit - what is the difference? Also what is the difference between using amsmath (^{th}) instead of \text{-th} or \mbox{-th}? Oct 24, 2012 at 16:35
• @Casper Try to use the function name Difference() and after that try \mathit{Difference}(). You'll see a big difference. ;-) Oct 24, 2012 at 16:44