I am just wondering if there is a way to reference the keyword data outside the algorithm in algorithm2e package. For example, given the example in algorithm2e, if I want to reference \KwData{this text} in my text outside the algorithm, how should I do it?
\begin{algorithm}[H]
\SetLine
\KwData{this text}
\KwResult{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{
read current\;
\eIf{understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
}
\caption{How to write algorithms}
\end{algorithm}
Best Answer
In the example you've given,
this text
is completely unformatted, and it's best to use it as-is in your text. However, components of analgorithm
are styled using various macros:\DataSty{<stuff>}
Used to set data (default is
\textsf
):\ArgSty{<stuff>}
Used to set arguments (to functions; default is
\textit
):\KwSty{<stuff>}
Used to prefix input parameters for an algorithm (default is
\textbf
):\FuncSty{<stuff>}
Formatting of a function name (default is
\texttt
):\CommentSty{<stuff>}
Formatting of comments (default is
\texttt
):\TitleSty{<stuff>}
Used to set the title of the algorithm via
\TitleOfAlgo
(default is regular text):...
I would use the appropriate style in the text as well, like in the following example:
The input
\matrixinput
is defined outside thealgorithm
environment in order to make it usable outside of that scope (without your text).