An equation with two splits / differing alignments

You can use standard amsmath tools:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{equation}
\begin{split}
x&=\begin{aligned}[t]
   5+3&-4 \\
      &-4+3+5
   \end{aligned} \\
 &=8-8+8 \\
 &=8
\end{split}
\end{equation}

\end{document}

enter image description here


I can use an \alignCenterstack here because the column alignment is rlrl. If it were other, I could always use a \tabularCenterstack.

\documentclass{article}
\usepackage{tabstackengine}
\TABstackMath
\begin{document}
\[
\TABbinary
\setstackaligngap{0pt}
\alignCenterstack{
 x=& 5 + 3 &-& 4\\
   &       &-& 4 + 3 + 5\\
   & 8 - 8 &+& 8\\
  =& 8     & &
}
\]
\end{document}

enter image description here

By default in tabstackengine, one can think of & tabs as being "replaced" with {}&, so that all cells have an empty group on the right. This helps spacing if relations and binary relations are placed at the right side of a cell and unary relations are placed at the left. In this case, however, I need the + and - to behave as binary in column 3, so \TABbinary instead "replaces" the & with {}&{}, so that all cell boundaries are padded with an empty group.

The \setstackaligngap{} sets the horizontal gap introduced after left-aligned columns of the align-stack, which here I want as 0pt.

The tabular stack equivalent is

\documentclass{article}
\usepackage{tabstackengine}
\TABstackMath
\begin{document}
\[
\TABbinary
\setstacktabulargap{0pt}
\tabularCenterstack{rll}{
 x=& 5 + 3 &- 4\\
   &       &- 4 + 3 + 5\\
   & 8 - 8 &+ 8\\
  =& 8     & 
}
\]
\end{document}