1

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

enter image description here

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

However, instead I got this

enter image description here

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}
  • 2
    verbatim and \verb not allowed ever in arguments. – Steven B. Segletes Sep 14 '18 at 17:20
  • 2
    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 "& =" ? – Carlos - the Mongoose - Danger Sep 14 '18 at 17:27
  • 1
    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
1

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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.