10

I'm writing some algorithms using the algorithmicx package.

I'm trying to create an if statement with an And boolean operator but using \And is causing an Undefined Control Sequence error

\usepackage{algorithm}
\usepackage{algpseudocode}

\If{$i < j+bandSize$ \And $j < i+bandSize$}
    \State $DTW_{i,j}\gets min(DTW_{i,j-1},DTW_{i-1,j},DTW_{i-1,j-1})+(f[i]-s[j])^2$
\EndIf

What's causing this?

cmhughes
  • 100,947
Chris
  • 201
  • I suggest use the answer by Werner if you use the algorithmic package: https://tex.stackexchange.com/a/519442/213 – Kevin Lee Dec 06 '19 at 07:14

2 Answers2

15

I did not find any \And in algpseudocode or algorithmicx, but you can easily add one:

\algnewcommand\And{\textbf{and}}
Boris
  • 38,129
  • 9
    Since \And is typically used as a parameterless macro almost like a binary relation in text, using \algnewcommand{\And}{\textbf{and}\xspace} seems a good idea (of course, including the xspace package). – Werner Apr 05 '12 at 20:36
  • Is it OK in pseudocode to use the logical and operator instead? – Chris Apr 06 '12 at 12:03
  • @Chris I think it depends on the pseudocode style you use. If you're not restricted, you can use it. – logo_writer Mar 03 '16 at 00:58
0

just use \&. It works completely fine.

\If{$i < j+bandSize$ \& $j < i+bandSize$} \State $DTW_{i,j}\gets min(DTW_{i,j-1},DTW_{i-1,j},DTW_{i-1,j-1})+(f[i]-s[j])^2$ \EndIf

Example from the question is modified for a clear explanation.

Komms
  • 11