3

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$.
7
  • Welcome to TeX.SX! The command \mid must appear in math mode and it produces errors in normal text modes.
    – egreg
    Feb 20 '15 at 14:54
  • And please learn not to use \\ in the text, ever!
    – daleif
    Feb 20 '15 at 14:55
  • @daleif Mind explaining why? I'm quite new to using latex.
    – rembrandt
    Feb 20 '15 at 15:01
  • @egreg is there a way I can do a vertical bar in text mode
    – rembrandt
    Feb 20 '15 at 15:02
  • 1
    First of, ``\\\` give an underfull hbox badness 10000. In general you should never have any need to insert manual line breaks. Of you do, then you are doing it wrong.
    – daleif
    Feb 20 '15 at 15:09
3

\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.)

2
  • PS I think the q0 in the next to last line should be $q_0$. Technically, even the 0 should be $0$. Feb 20 '15 at 15:19
  • @EthanBolker Yes, thank you for noticing that.
    – rembrandt
    Feb 20 '15 at 15:22

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.