2

I am writing pseudocode using the algorithmicx package. I am using the \Comment function to explain definitions inside the algorithm, but I'm unsure what the proper way of explaining what the function parameters stand for. Is there some convention on how to do that?

For example, in the example below, assume $N$ is the number of available actions. I'd like to pass it as an argument to the function, and of course I could explain in the text that this is what $N$ stands for. But I would like to also have that information inside the algorithm environment somewhere, so somebody who looks just at that float would also be able to understand what the function does. Any suggestions?

\documentclass{article}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}

\begin{document}

\begin{algorithm}
\begin{algorithmic}[1]
  \Function{f}{$N$}
    \State $p\gets e_N$
    \Comment{the $N$-dimensional unit vector}
    \State more stuff
  \EndFunction
\end{algorithmic}
\end{algorithm}

\end{document}
  • 1
    You can use \Comment also after the \Function line. – egreg May 7 '18 at 21:26
  • 1
    Thanks @egreg. It's just that in my (actual) example, the function has multiple input arguments, so there isn't quite enough space there. I was thinking more of something like a list environment below the function header which would look "commented out" in some way... but maybe there's just no convention on how to do this, and I should simply make something up – mimuller May 8 '18 at 20:17
  • 1
    So, did you come up with something? I'm surprised that this apparently hasn't already been asked/ that there aren't any answers/upvotes/not many views – polynomial_donut Oct 16 '19 at 18:33
  • I just included a description in the caption. Not ideal, but it worked for me. – mimuller Oct 18 '19 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.