I have been trying all day to set-up the commands necessary to represent the Haggis pseudocode format using the algorithmicx
package in Latex. I have managed to create the commands I need for the simple algorithm I am describing but I can't get the indentation to appear correctly.
In my main document I am defining the following new commands and my algorithm below it:
\documentclass{report}
\usepackage{algpseudocode}
\algnewcommand\algorithmicset{\textbf{SET}}
\algnewcommand\algorithmicto{\textbf{TO}}
\algnewcommand\SET[2]{\item\algorithmicset\ #1 \algorithmicto\ #2}
\algnewcommand\algorithmicreceive{\textbf{RECEIVE}}
\algnewcommand\algorithmicfromkeyboard{\textbf{FROM KEYBOARD}}
\algnewcommand\RECEIVE[1]{\item\algorithmicreceive\ #1 \algorithmicfromkeyboard}
\algnewcommand\algorithmicsend{\textbf{SEND}}
\algnewcommand\algorithmictodisplay{\textbf{TO DISPLAY}}
\algnewcommand\SEND[1]{\item\algorithmicsend\ #1 \algorithmictodisplay}
\algrenewcommand\algorithmicwhile{\textbf{WHILE}}
\algrenewcommand\algorithmicend{\textbf{END}}
\algrenewcommand\algorithmicdo{\textbf{DO}}
\algrenewcommand\algorithmicif{\textbf{IF}}
\algrenewcommand\algorithmicthen{\textbf{THEN}}
\begin{document}
\begin{algorithm}[H]
\caption{Hello world}
\begin{algorithmic}[1]
\SET{$number$}{$0$}
\While{$number \neq -1$}
\SEND{$"Please\ enter\ the\ next\ number\ (-1\ to\ end):\ "$}
\RECEIVE{$number$}
\If{$number \neq -1$}
\SET{$number$}{$total\ +\ number$}
\EndIf
\EndWhile
\SEND{$total$}
\end{algorithmic}
\end{algorithm}
\end{document}
When I create the PDF I get the following:
There is something wrong with the either the commands I have created or there is something else that I need to do that I am unaware of. I have searched for sometime without success and I would appreciate any assistance with this problem as I am tearing my hair out! No doubt it is something obvious I have overlooked.
\documentclass{...}
, the required\usepackage
's,\begin{document}
, and\end{document}
. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.