2

I'm still pretty new to LaTeX and TeX. I came across this equation on GCD.

GCD equation

I wanted to note it down. So, I wrote the equation like this:

\begin{equation*}
 gcd(a,b)=
   \left\{\begin{array}{lr}
        a, & b=0\\
       gcd(b, a % b) , & b \neq 0
    \end{array}\right.
 \end{equation*}

But no matter how hard I try, I always get this:

enter image description here

Can anyone help?

Sean
  • 95

1 Answers1

4

As @Luis Turcio suggested, you can simply just put a \ in front of the % symbol. So you would use \% to typeset it.

All in all, the full equation would look like this:

\begin{equation*}
 gcd(a,b)=
   \left\{\begin{array}{lr}
        a, & b=0\\
       gcd(b, a \% b) , & b \neq 0
    \end{array}\right.
 \end{equation*}

But as @David Carlisle has said, you should "never set multi-letter symbols in math italic." So we would have to put \ in front of gcd. In addition, it's a good idea to use the cases environment (provided by the amsmath package} for the math expression at hand. And we would have this:

\begin{equation*}
\gcd(a,b)=
    \begin{cases}
        a,               & b=0 \\
        \gcd(b, a \% b), & b \neq 0
    \end{cases}
\end{equation*}
Mico
  • 506,678
Sean
  • 95