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 Answer 1

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
    Commented Feb 24, 2021 at 2:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .