[Tex/LaTex] In algorithm2e, how to force non-italic font in the condition block of While

algorithm2e

I have this snippet:

\documentclass[10pt]{article}

\usepackage{amsmath}
\usepackage[ruled,vlined,linesnumbered]{algorithm2e}

\begin{document}
  \begin{algorithm}
    \While{$|\text{OPEN}| > 0$}{
      $u = \textsc{ExtractMinimum}(\text{OPEN})$ \\
    }
    \caption{\textsc{$A*$}$(s, t, w, h)$}
  \end{algorithm}
\end{document}

which produces the following output:

enter image description here

My problem is that I cannot find a way to make LaTeX typeset on the first line "OPEN" instead of "OPEN"? Any advice?

Best Answer

The algorithm2e environment sets the first argument to \While using ArgSty, which is, by default, \emph. When you use \text in math mode, the font which was current when the formula started is used, italics, in this case.

\documentclass[10pt]{article}

\usepackage{amsmath}
\usepackage[ruled,vlined,linesnumbered]{algorithm2e}

\SetArgSty{textnormal}

\begin{document}
  \begin{algorithm}
    \While{$|\text{OPEN}| > 0$}{
      $u = \textsc{ExtractMinimum}(\text{OPEN})$ \\
    }
    \caption{\textsc{$A*$}$(s, t, w, h)$}
  \end{algorithm}
\end{document}

enter image description here

The style that by default is rendered in italics is FuncArgSty.