I'm writing a pseudocode with algorithm
package.
Now algorithmicx
package produce a comment with the triangle on the right of the line which is referred (this is the default layout).
I need to change this layout in the classic //
or %
symbol, insert the command in the previous line to which is referred. Furthermore, I don't want to print the number of line (\State
) when is a comment.
My code is the following:
\documentclass{article}
\usepackage{algorithm,algpseudocode}
\renewcommand{\algorithmicforall}{\textbf{for each}}
\renewcommand{\Function}[2]{%
\csname ALG@cmd@\ALG@L @Function\endcsname{#1}{#2}%
\def\jayden@currentfunction{#1}%
}
\newcommand{\funclabel}[1]{%
\@bsphack
\protected@write\@auxout{}{%
\string\newlabel{#1}{{\jayden@currentfunction}{\thepage}}%
}%
\@esphack
}
%define my variables
\newcommand{\varu}{\emph{u}}
\newcommand{\vart}{\emph{t}}
\newcommand{\varT}{\emph{T}}
\newcommand{\varrt}{\emph{$r_{t}$}}
\newcommand{\varts}{\emph{ts}}
\newcommand{\varTripletta}{$u,\varrt, \varts$}
\newcommand{\varParamA}{\emph{ParamA}}
\newcommand{\varParamb}{\emph{ParamB}}
\newcommand{\varNameVariable}{nameVariable}
\begin{document}
In this section we define some variables \varTripletta that means that \varu is a user such that...
\begin{algorithm}
\caption{MyAlgorithm}
\label{algMyAlg}
\begin{algorithmic}[1]
\Procedure {MyAlgorithm} {$z, \varParamA, \varParamB$}
\State \textit{\varNameVariable} $\gets$ 0 \Comment {\emph{This comment is referred to this line}}
\State nameVariable $\gets $ 0
...
\EndProcedure
\end{algorithmic}
\end{algorithm}
An other question is to the \newcommand
. I define some varibales that I use in the document in order to use the same layout in the document.
For the variable \varNameVariable
, I need that in the pseudocode is in \textit{\varNameVariable}
. The problem it is printed in italic.
Can anyone help me?
Best Answer
The following implements
\LineComment[<indent>]{<line comment>}
which seems to provide what you're looking for:You can update
\commentsymbol
to suit your needs. It's original definition is/was\(\triangleright\)
.