Let's say we have a procedure in which we want to iterate over an object whose data type we want to specify by writing it in texttt
font.
I tried
\documentclass{article}
\usepackage{algorithm2e}
\usepackage{amsmath}
\begin{document}
\begin{procedure}
\For{$x\in\texttt{myArray}$}{
$\texttt{MyArray}\gets\texttt{MyArray}.\text{append}(x)$}
\caption{MyProcedure()}
\end{procedure}\DecMargin{1em}
\end{document}
However, \texttt{MyArray}
looks different in the for loop and in the body of the loop. How can we make it look like in the body of the loop both times? I already tried to put it outside of math mode, but it did not change.