[Tex/LaTex] Ampersand symbol algorithm environment

algorithmsampersandsymbols

How to make a "normal" looking ampersand symbol within the algorithm environment?

I'm using \& but this results in a strange looking character as shown below:

enter image description here

Here is a minimal example how I use the ampersand

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[ruled,linesnumbered]{algorithm2e}

\begin{document}
    \begin{algorithm}[H]
      \If{$b$ \& $0x01$} {
        $p \leftarrow p \oplus a$\;  
      }
    \end{algorithm}
\end{document}

Best Answer

That's just how an italic ampersand looks in Computer Modern, the font you're using. If you don't like it, force it to be upright: \textup{\&}. Alternatively, you can use \textsl{\&} to get a slanted look, which is like the upright version, but skewed to look similar to italic text:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[ruled,linesnumbered]{algorithm2e}

\begin{document}
    \begin{algorithm}[H]
      \If{$b$ \textup\& $0x01$ or $b$ \textsl\& $0x80$} {
        $p \leftarrow p \oplus a$\;  
      }
    \end{algorithm}
\end{document}

output

Related Question