# \verb illegal in command argument in \begin{align*}

I am trying to generate a set of aligned equations that looks like,

(note: random and variable are supposed to be pseudo-code)

along with an error, that says,

\verb illegal in command argument

Does anyone know how to fix this problem?

Minimal working example:

\documentclass{book}
\usepackage[font=small,format=plain,labelfont={bf,up},labelsep=space{caption}
\usepackage{amsmath}
\usepackage{mathtools}

\begin{document}
\begin{align*}
\verb|random| &= \verb|variable|\\
& | \verb|random : variable|\\
& | \verb|<random> <variable>| \end{align*}
\end{document}

• verbatim and \verb not allowed ever in arguments. – Steven B. Segletes Sep 14 '18 at 17:20
• Use \texttt{random} – egreg Sep 14 '18 at 17:21
• @StevenB.Segletes I am not clear as to what arguments mean. Do you mean left hand side of "& =" ? – Aåkon Sep 14 '18 at 17:27
• In this case, I mean that align* does more than just set a few parameters and proceed...it has to digest the contents of the environment, in order to figure out how to align stuff. In the process of digesting the environment contents, it is digested with the wrong catcodes and, as a result, those contents cannot be used as verbatim. – Steven B. Segletes Sep 14 '18 at 17:38

You might use cprotect, but it's a waste of resources. As you can see, the second example typesets exactly the same as the first one.

\documentclass{article}
\usepackage{amsmath}
\usepackage{cprotect}

\newcommand{\ftexttt}[1]{\texttt{\frenchspacing#1}}

\begin{document}
\cprotEnv\begin{align*}
\verb|random| &= \verb|variable|\\
& \mid \verb|random : variable|\\
& \mid \verb|<random> <variable>|
\end{align*}

\begin{align*}
\ftexttt{random} &= \ftexttt{variable}\\
& \mid \ftexttt{random : variable}\\
& \mid \ftexttt{<random> <variable>}
\end{align*}
\end{document}