1

I want to disable globally the italics style in the program names.

I have seen this post which is on a similar question, and which suggests to use \SetArgSty{upshape} to disable globally italics in if conditions of algorithm2e. I want to do the same, but for program names. On the algorithm2e manual, I have seen that there exists a similar \SetProgSty command, however it does not seem to solve my problem:

\documentclass{article}
\usepackage[vlined,boxed,linesnumbered]{algorithm2e}
\SetProgSty{upshape}
\SetKwProg{Operation}{operation}{ is}{}

\begin{document} \begin{algorithm}[ht] \Operation{add_one$(x)$}{\textsf{return} $x+1$} \end{algorithm} \end{document}

What I get:

wig

What I want:

wiw

I have tried all other \Set...Sty commands, and I have also tried relax and textnormal instead of upshape, but nothing seems to work.

How to do that please?

JamesT
  • 3,169
  • 1
    algorithm2e is a really good package but it is funny in the same breath, defines things itself without using other packages like caption etc, it is not the easiest package but does work when you know how to go through the source code, I highly recommend going through algorithm2e.sty contained on Overleaf, TeXlive or whichever you use as you get more confident with the code/styles etc. Hope my answer helps! – JamesT Apr 12 '23 at 13:39
  • You should type \Operation{$\mathrm{add\_one}(x)$}{\textsf{return} $x+1$} – egreg Apr 12 '23 at 13:45

1 Answers1

1
\documentclass{article}
\usepackage[vlined,boxed,linesnumbered]{algorithm2e}
\SetProgSty{upshape}
\SetKwProg{Operation}{operation}{ is}{}

\renewcommand{\ProgSty}[1]{\textnormal{#1}\unskip} % removed \emph{}

\begin{document}
\begin{algorithm}[ht]
    \Operation{add\_one$(x)$}{\textsf{return} $x+1$}
\end{algorithm}
\end{document}

enter image description here

JamesT
  • 3,169