Definir función en pseudocódigo

Definir función en pseudocódigo

¿Podrían ayudarme, por favor, cómo puedo escribir un fragmento de pseudocódigo con función en látex?

    \begin{algorithmic}
\STATE $\mathrm{maxWeight} \leftarrow \mathrm{value of e.weight where e has maximum value of weight from all elements}$
\STATE $\mathrm{minWeight} \leftarrow \mathrm{value of e.weight where e has minimum value of weight from all elements}$
\STATE $\mathrm{maxDrawValue} \leftarrow \mathrm{value of element maximum size in visualization}$
\STATE $\mathrm{minDrawValue} \leftarrow \mathrm{ value of element minimum size in visualization}$
\Function{CountDrawValue}{elementWeight}
  \IF maxWeight = minWeight
\RETURN $\frac{maxWeight + minWeight}{2}$
\EndFunction
\end{algorithmic}

me sale un mensaje de error

! Undefined control sequence.
l.631 \Function
               {CountDrawValue}{elementWeight}
? 

Respuesta1

Quizás estés buscando algo parecido a esto:

ingrese la descripción de la imagen aquí

\documentclass{article}
\usepackage{algpseudocode,amsmath}
\newcommand{\var}{\texttt}
\newcommand{\assign}{\leftarrow}
\newcommand{\multilinestate}[1]{%
  \parbox[t]{\linewidth}{\raggedright\hangindent=\algorithmicindent\hangafter=1
    \strut#1\strut}}
\begin{document}

\begin{algorithmic}
  \State \multilinestate{$\var{maxWeight} \assign{}$value of \var{e.weight} where~\var{e} has maximum value of weight from all elements}
  \State \multilinestate{$\var{minWeight} \assign{}$value of \var{e.weight} where~\var{e} has minimum value of weight from all elements}
  \State $\var{maxDrawValue} \assign{}$value of element maximum size in visualization
  \State $\var{minDrawValue} \assign{}$value of element minimum size in visualization
  \Function{CountDrawValue}{\var{elementWeight}}
    \If{$\var{maxWeight} = \var{minWeight}$}
      \State\Return $(\var{maxWeight} + \var{minWeight}) / 2$
    \EndIf
  \EndFunction
\end{algorithmic}

\end{document}

\Functiones suministrado poralgpseudocode, mientras que el uso de \STATEsólo está disponible a través algcompatiblede oalgorithmic. He convertido tu entrada en algo que es totalmente compatible con algpseudocode.

información relacionada