I am a real beginner in latex, and now I am struggling with using the algorithm package and algpseudocode to write some code.
What I did until now is:
\usepackage{algorithm}
\usepackage{algpseudocode}
\begin{algorithm}
\caption{My algorithm doing something....}
\begin{algorithmic}
\Function{findSomething}{$x, y$} \\
\(current\_value \gets 0\) \\
\(value\_found \gets false\)
\While{\(value\_found \neq true\)}
\If{......}
% DO something, doesn't matter \And % WHERE I TRIED THE And command
.......
\EndIf
\EndWhile \\
\Return \(x\)
\EndFunction
\end{algorithmic}
\end{algorithm}
Now I wanted to use commands like "and, or, to" but here they are not working, is this maybe another package than the once I loaded?
But still my second problem is, I found that i can define a command like:
\algnewcommand{\Or}{\textbf{or}}
But when I then use the \Or, nothing appears on the final pdf :S. Or when I try to define:
\algnewcommand{\And}{\textbf{and}}
Latex is telling me that the command already exists, but when I try to use it in my code (marked in the example) I get an error that the command is not available, :S
Best Answer
Defining
\And
and\Or
works as you proposed and as you can see in the following example. However, you should make use of\State
:A quote from the package documentation of algorithmicx (http://mirrors.ctan.org/macros/latex/contrib/algorithmicx/algorithmicx.pdf):
For logical and/or operators in pseudo-code I personally use
\land
or\lor
. Usually you should get around with the commands defined in algpseudocode.to
is usually not a command in pseudo-code imho but maybe used in the first line of a for loop. Again you can usealgnewcommand
to define ato
command. If you would like to typeset comments you might want to use\State \Comment And or to...
.