[Tex/LaTex] Normal font in theorem when typesetting algorithms

algorithmstheorems

I'm using amsthm and clrscode to typeset algorithms. I'd like to have my algorithms numbered, so I do this:

\theoremstyle{plain}
\newtheorem{algorithm}[equation]{Algorithm}

\begin{algorithm}
The folowing algorithm does something. This text should stay in italics.

\begin{codebox}
\Procname{$\proc{Do-Something}(x,y)$}
\li \Return $0$ \Comment{here italics should be disabled}
\end{codebox}

\end{algorithm}

The plain theorem style has theorem name and number in bold, which I like, and the theorem statement in italic, which I also like. Unfortunately, in the case of an algorithm, the whole algorithm is typeset in italics and that looks very bad. So, for algorithms I'd like to turn off italics.

How do I do that? Is there any environment that I could use to temporarily disable italics only in codebox? If possible, I'd like to not create any new theorem style.

Best Answer

The macro \code@init is run at the beginning of a codebox environment. You can add \normalfont to it, which disables also the italic mode set before:

\makeatletter
\g@addto@macro\code@init\normalfont
\makeatother

\normalfont resp. \code@init works locally here, so after the codebox ended the italic shape will be restored.

algorithm example