[Tex/LaTex] Typesetting explanations of algebra steps

alignmath-mode

I'm making a WordPress site explaining high school math, typesetting the math with the QuickLatex plugin. I mention that in case there are any compatibility issues, but so far it seems to work like any LaTeX program I've used.

I want to typeset explanations of the steps in algebra. For instance, sometimes an algebra book will explain to subtract 3x from each side of an equation via a diagram like this:

 3x + 8 - 2y = 6x
-3x           -3x
      8 - 2y = 3x

I am trying to use aligned mode, but it doesn't work all that well.

My first try uses one ampersand:

\begin{aligned} 
 3x + 8 - 2y &=  6x \\
-3x          &  -3x \\
      8 - 2y &= 3x
\end{aligned}

It looks like this:

LaTeX attempt one

As you can see, the -3x on the left side isn't lined up. So I decided to try another ampersand, here between the + and the 8:

\begin{aligned} 
 3x + & 8 -2y  &=  6x \\
-3x   &        &  -3x \\
      & 8 -2y  &=  3x
\end{aligned}

That looks like this:

LaTeX attempt 2

Better, but the 3x and the + and the 8 are jammed together.

I tried a number of other things, adding more ampersands, and the whole thing got more and more complicated, and more and more messed up. So I thought about using phantom symbols: typing more symbols than needed on each line, in a way so that the lines are aligned, and then hiding the symbols that shouldn't show.

\begin{aligned} 
 3x          +8-2y   &          =  6x \\
-3x \phantom{+8-2y}  & \phantom{=} -3x \\
              8-2y   &          =  3x
\end{aligned}

This seems better. Here it is:

LaTeX attempt three

But it's still a struggle: the results are often hard to predict. If there is a better way to go about this, let me know.

Also I may add some kind of annotation to the lines of equations, including the lines that don't have an equals sign, so it may be handy to use some method that allows for that nicely.

I also want to ask about adding annotation. I tried the answer mentioned below with the array package, and used one column of the array to enter annotation, like this:

\begin{system}
3x & + & 2x & = & 8 & \text{(original equation)} \\
   &   & 5x & = & 8 & \text{(after combining the 2x and 3x)}
\end{system}

But the problem is that there is not sufficient padding between the annotation text and the right-most term in some of the equations.

Best Answer

Remember that aligned makes pairs of right-left aligned columns.

This is a different possibility with array:

\documentclass{article}
\usepackage{amsmath,array}

\newenvironment{system}
 {\renewcommand{\arraystretch}{1.5}% like aligned does
  \begin{array}{
    @{}r@{}
    *{\value{MaxMatrixCols}}{
      >{{}}c<{{}}@{}
      >{\mathopen{}}r@{}
    }
  }%
 }{\end{array}}

\begin{document}

\[
\begin{system}
3x  & + & 8 & - & 2y & = & 6x \\
-3x &   &   &   &    &   & -3x \\
    &   & 8 & - & 2y & = & 3x
\end{system}
\]

\end{document}

enter image description here

With autoaligne, with some pulls to coerce it into good behavior:

\documentclass{article}
\usepackage{autoaligne}

\begin{document}

\[
\catcode` =9
\definirseparateurs{\\}{=||V}{+||-}
\begingroup\lccode`~=`V \lowercase{\endgroup\let~}\relax
\mathcode`V="8000
\autoaligne{
  3x  + 8 - 2y   =  6x\\%
\-3x             V \-3x\\%
      + 8 - 2y   = 3x
}
\]

\end{document}

enter image description here

Related Question