0

I am currently writing an essay and I'd like to insert some kind of code. This is my first time trying such a thing so I'm very unexperienced. I found the packages algorithm, algorithmicx, algpseudocode on the internet and I think I understand what they're doing (found this). Nevertheless, I am not able to compile my document. It always says "algorithm.sty" not found when trying to compile. I think there is some error installing the package? What should I do?

\documentclass[arxiv,reqno,twoside,a4paper,12pt]{amsart}

\usepackage{algorithm, algpseudocode}

\begin{document}

\begin{algorithmic}[1]
    \STATE S := I
    \WHILE{$\frac{h}{k} \ne \Phi(S)$}
        \IF{$\frac{h}{k} < \Phi(S)$} $S = SL$
        \ELSE $S = SR$ \ENDIF
    \ENDWHILE
\end{algorithm}

\end{document}
  • if you have the storage capacity on your hard drive, install the complete TeX environment. otherwise see, if you can enable the option install missing packages on the fly – naphaneal Jun 17 '18 at 10:45

1 Answers1

1

You should install the algorithm package (how, it depends on what TeX distribution you're using).

Then you have to fix the code for using algpseudocode specific commands.

\documentclass[reqno,twoside,a4paper,12pt]{amsart}

\usepackage{algorithm, algpseudocode}

\begin{document}

\begin{algorithmic}[1]
\State S := I
\While{$\frac{h}{k} \ne \Phi(S)$}
  \If{$\frac{h}{k} < \Phi(S)$}
    \State $S = SL$
  \Else
    \State $S = SR$
  \EndIf
\EndWhile
\end{algorithmic}

\end{document}

enter image description here

egreg
  • 1,121,712
  • I tried to install algorithms manually but it doesn't work. Entering latex algorithms.ins into the command prompt gives me the error "can't write on latex.log" This is the page I got my ideas from. – Astrid Niehues Jun 17 '18 at 19:43