Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
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 _. –  Sean Allred Jul 30 at 18:33

2 Answers 2

up vote 5 down vote accepted

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

share|improve this answer

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

share|improve this answer
    
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! –  Phlox Midas Jul 30 at 20:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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