10

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?

1
  • 1
    I'm confused. The picture you have shows OPEN, not OPEN.
    – Mark
    Apr 3, 2016 at 22:44

1 Answer 1

10
+50

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.

3
  • (1) It's not \SetProgSty but rather \SetProcSty. (2) \SetProcSty does not do what I want it to do. (3) There is no ArgSty, but rather \SetArgSty.
    – coderodde
    Apr 27, 2016 at 9:45
  • I don't know what happened, but I'm sure it was working. Now it should be fixed.
    – egreg
    Apr 27, 2016 at 10:08
  • I don't understand how, but it worked. algorithm2e is a weird package.
    – Tropilio
    Jan 30, 2022 at 14:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .