[Tex/LaTex] Error: \item is invalid in math mode

math-mode

I would like to put a vertical bar in my regex expression but I keep getting an error when I put in \mid. Can you help?

\item \textbf{Give a regular expression for the language accepted by the automaton~$A$.} \\\\
(0 \mid 1)*01)0 \mid 1)*\\
 \item \textbf{Explain what makes the automaton~$A$ non-deterministic.}\\\\
 The reason automaton~$A$ is non-deterministic is because in the state q0 reading a 0 can either lead to $q_0$ or $q_1$.

Best Answer

\mid causes tex to switch into math mode, and it's still in math mode when it gets to the next \item, hence the unexpected error message.

instead of what you have, make the line with \mid an unnumbered math display:

\item \textbf{Give a regular expression for the language accepted by the automaton~$A$.}
\[ (0 \mid 1)*01)0 \mid 1)* \]
 \item \textbf{Explain what makes the automaton~$A$ non-deterministic.}

 The reason automaton~$A$ is non-deterministic is because in the state $q_0$ reading a $0$
 can lead to either $q_0$ or $q_1$.

using double backslashes, as already commented, is not a good practice. see When to use \par and when \\ for more information.

edit: based on a comment about what is math and what isn't, i've adjusted the original code; i've also applied my "editing pencil" to the position of "either" for clarity. (apologies for my presumption; see my user profile to understand why i'm fussy this way.)