6

I would like the if statement to have "current stage" in serif and "satisfies" as normal text. The following code produces both with italics:

\documentclass{article}
\usepackage{algorithm2e}
\begin{document}
\begin{algorithm}

\If{\textsf{current\_state} \textrm{satisfies} \textsf{goal}}
{
return \textsf{existing\_plan}
}
\end{algorithm}
\end{document}

Any ideas?

1
  • 1
    With both of the solutions below, I would strongly recommend abstracting these concepts into new commands, e.g. \Var{current-state} \Satisfies \Var{goal}. If you use xparse and a tiny bit of expl3, you can auto-replace - to _. Jul 30, 2014 at 18:33

2 Answers 2

8

The algorithm2e package uses \ArgSty to typeset the argument of \If. If you don't want italics, add

\SetArgSty{textup}

Complete example:

\documentclass{article}
\usepackage{algorithm2e}
\SetArgSty{textup}

\begin{document}

\begin{algorithm}
\If{\textsf{current\_state} satisfies \textsf{goal}}
{
return \textsf{existing\_plan}
}
\end{algorithm}

\end{document}

enter image description here

4

You can use \textup instead of \textrm as suggested by egreg. The code now reads like this:

\documentclass{article}
\usepackage{algorithm2e}
\begin{document}
\begin{algorithm}

\If{\textsf{current\_state} \textup{satisfies} \textsf{goal}}
{
return \textsf{existing\_plan}
}
\end{algorithm}
\end{document}

and the output as required:

enter image description here

1
  • I'm sorry I couldn't mark yours as the answer too because it's definitely correct. I went for the other because it was visually exactly the effect I was after. I gave an upvote as compensation. Thanks for your help! Jul 30, 2014 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.