1

I wrote the following pseudocode and I want to know if it is ok.

enter image description here

the two variables

   local_atoms                        //atoms inside hlground

and

   global_hlinks                      //hyperlinks to be cut 

are going to receive some value as it shown in the algorithm. But someone says putting them as in line 2 and line 3 is not right. I said I give comments on the right of line 2 and line 3, so it should be clear enough.

So I checked some examples of using algorithm package for writing pseudocode and did not find examples written like mine. So I want to know what is the best way to write line 2 and line 3?

My question is related to using algorithm package, so I am asking it here.

4
  • Are you looking for an opinion about the logic/formatting of your code example? If yes, then I would rather ask the person for whom you make it for (e. g. your professor if this is applicable). Or do you have a technical question (how to achieve this and that) - is that's the case, then I do not understand the question. Commented Mar 12, 2017 at 12:30
  • @Dr.ManuelKuehner I am asking for the way to format the two lines. commenting them as shown is the right way or something else can be done in algorithm package?
    – alim
    Commented Mar 12, 2017 at 14:11
  • 1
    Again, I think this is more a question about opinion or convention. Or maybe I don't get it. The question is now one day old and didn't get any attention apart from comment. Maybe others also have problems understanding it. Commented Mar 12, 2017 at 14:41
  • @alim, to your question "is it ok this way", it can only be as OK, as the package, you are using, allows it. If you feel, it's too limited, look for alternatives, e.g. here: ctan.org/topic/pseudocode . // And, BTW, it's always easier for all of us, when you provide the code too, which produces your result.
    – MS-SPO
    Commented Dec 16, 2023 at 10:37

2 Answers 2

2

Rather set the those lines entirely in comments, since it doesn't form part of the algorithm statements.

enter image description here

\documentclass{article}

\usepackage{algorithm,algpseudocode}

\newcommand{\var}{\texttt}
\newcommand{\assign}{\gets}
\newcommand{\True}{\textsc{True}}
\newcommand{\False}{\textsc{False}}
\newcommand{\Parameter}[2]{\Statex $\triangleright$ \var{#1}: #2}

\begin{document}

\begin{algorithm}
  \begin{algorithmic}[1]
    \Function{Find\_hlground}{$G, L$}
      \Parameter{local\_atoms}{atoms inside hlground}
      \Parameter{global\_hlinks}{hyperlinks to be cut}
      \State $\var{result} \assign \True$
        \Comment{true if hlground exists}
      \If{\textproc{cycle\_exist\_dfs}($G, L$)}
        \If{!\textproc{purepath\_exist\_dfs}($G, L$)}
          \State $\var{global\_hlinks} \assign \textproc{mincut}(G, L)$
        \Else
          \State $\var{result} \assign \False$
        \EndIf
      \EndIf
      \If{\var{result}}
        \State $\var{local\_atom} \assign \textproc{get\_local\_atoms}(G, L, \var{global\_links})$
      \EndIf
      \Return \var{result}
    \EndFunction
  \end{algorithmic}
\end{algorithm}

\end{document}
1

You tagged the question with algorithmicx so I'll assume that's your package (rather than "algorithm package" without "-icx", which you mention in your question text).

As implied by @dr-manuel-kuehner and the otherwise lack of answers, the documentation for algorithmicx (which is here, click on the link that says "Package Documentation" to get a PDF) does not tell how to declare variables.

Therefore I use a generic statement (using the \State keyword) and whatever type of formatting seems to fit the journal or conference (or professor, etc.) I am writing for. In this example I also initialise the variable in the declaration.

\State \textbf{local} $local\_atoms \gets 27$ \Comment{Number of atoms in a hlground}

In statements I sometimes also use \textsc for small caps, etc.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .