6

So I'm not experienced with the algorithm packages in LaTeX. I'm assuming there must be a way to do

if condition1 and condition2 then...

but I can't find it. I've checked what I can find of the documentation. If I compile the below I get an error for undefined command at the \And. It looks like there is something in algorithm, using \AND, but that doesn't work here and I don't really understand what's going on.

\documentclass{article}
\usepackage[noend]{algpseudocode}
\usepackage[nothing]{algorithm}
\algrenewcommand{\algorithmicrequire}{\textbf{Input:}}
\algrenewcommand{\algorithmicensure}{\textbf{Output:}}

\begin{document}

\begin{figure}
\begin{algorithmic}
\If{$x> y$ \And $ x<z$}
\State{some code here}
\EndIf
\end{algorithmic}
\end{figure}
\end{document}

Is there a way to do what I'm after?

Joel
  • 2,429

2 Answers2

5

I could not find a \And command but we can make one:

\algnewcommand\And{\textbf{and}}

and add some space...

\documentclass{article}
\usepackage[noend]{algpseudocode}
\usepackage[nothing]{algorithm}
\algrenewcommand{\algorithmicrequire}{\textbf{Input:}}
\algrenewcommand{\algorithmicensure}{\textbf{Output:}}
\algnewcommand\And{\textbf{and} }

\begin{document}

\begin{figure}
\begin{algorithmic}
\If{$x> y$ \And  $ x<z$}
\State{some code here}
\EndIf
\end{algorithmic}
\end{figure}
\end{document}

Thanks: @Werner

JJoao
  • 683
1

I suggest use the answer by Werner if you use the algorithmic package. Link: Using the "algorithm" package - can't use \OR?

enter image description here

\documentclass{article}

\usepackage{algpseudocode}

\algnewcommand{\algorithmicand}{\textbf{ and }}
\algnewcommand{\algorithmicor}{\textbf{ or }}
\algnewcommand{\OR}{\algorithmicor}
\algnewcommand{\AND}{\algorithmicand}
\algnewcommand{\var}{\texttt}

\begin{document}

\begin{algorithmic}
  \Procedure{proc}{$v$}
    \State $\var{v.bool} \gets \var{v.bool} \OR \var{c.bool}$;
  \EndProcedure
\end{algorithmic}

\end{document}