1

I use the following packages:

\usepackage{algorithm}
\usepackage{algpseudocode}

to display pseudocode of some algorithms in my latex document. For conditionals I use the follow

\If{success = 0}
\State \Return{$\emptyset$}
\EndIf

Now, this renders the if and endif keywords in bold using the same typeface as the one used for all the other control structures. My question is the following: How can I render if not instead of if? So my code would read something like:

\IfNot{success}
\State \Return{$\emptyset$}
\EndIf
1

You can take all the details associated with \If (within algpseudocode.sty) and add your own \IfNot:

enter image description here

\documentclass{article}

\usepackage{algpseudocode}

\algnewcommand\algorithmicnot{\textbf{not}}
\algdef{SE}[IF]{IfNot}{EndIf}[1]{\algorithmicif\ \algorithmicnot\ #1\ \algorithmicthen}{\algorithmicend\ \algorithmicif}%

\begin{document}

\begin{algorithmic}
  \If{success = 0}
    \State \Return $\emptyset$
  \EndIf
  \IfNot{success}
    \State \Return $\emptyset$
  \EndIf
\end{algorithmic}

\end{document}
1
  • This did exactly what I was looking for, thanks! – gen Feb 24 at 2:44

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.