0

Does there exist a multiline equation environment which automatically shows the changes from one line to the other?

I am thinking of an environment that would take inputs like

       E[d] & = \sum_{d=0}^{\infty} \frac{\lambda^d}{d!} d e^{-\lambda}\\
            & = \sum_{d=1}^{\infty} \frac{\lambda^d}{d!} d e^{-\lambda}\\
            & = \lambda \sum_{d=1}^{\infty} \frac{\lambda^{d-1}}{d!} d e^{-\lambda}\\
            & = \lambda \sum_{d=1}^{\infty} \frac{\lambda^{d-1}}{(d-1)!} e^{-\lambda}\\
            & = \lambda \sum_{d=0}^{\infty} \frac{\lambda^{d}}{(d)!} e^{-\lambda}\\
            & = \lambda\\

and output something like

enter image description here

Ideally, the math in the output should not be distorted as in the above example (e.g. the (d-1) in exponent should still have exponent size).

Edit : I am looking for an environment that would produce this kind of output automatically, without having to manually identify the changes and tag them with a certain color (which is what I did using colorbox to generate the example).

1 Answer 1

1

One possibility is use colorbox from package xcolor

\documentclass{article}
    \usepackage{mathtools}
    \usepackage[dvipsnames]{xcolor}
\newcommand{\shadow}[1]{\scriptsize\colorbox{orange!40}{$#1$}}
\newcommand{\shadowf}[1]{\footnotesize\colorbox{orange!40}{$#1$}}
\newcommand{\shadown}[1]{\colorbox{orange!40}{$#1$}}

\usepackage[active,displaymath,tightpage]{preview}
\setlength\PreviewBorder{5pt}%

    \begin{document}
\begin{align*}
       E[d] & = \sum_{d=0}^{\infty} \frac{\lambda^d}{d!} d e^{-\lambda}\\
            & = \sum_{d=\shadow{1}}^{\infty} \frac{\lambda^d}{d!} d e^{-\lambda}\\
            & = \lambda \sum_{d=1}^{\infty} \frac{\lambda^{\shadowf{d-1}}}{d!} d e^{-\lambda}\\
            & = \shadown{\lambda} \sum_{d=1}^{\infty} \frac{\lambda^{d-1}}{(\shadowf{d-1})!} e^{-\lambda}\\
            & = \lambda \sum_{\shadowf{d=0}}^{\infty} \frac{\lambda^{\shadowf{d}}}{(\shadown{d})!} e^{-\lambda}\\
            & = \lambda\\
\end{align*}
    \end{document}

enter image description here

3
  • Thanks, that's more or less what I did to generate the above example. Maybe I should have mentioned it. However, I am looking for an environment which would produce this kind of output automatically. I'll make it clearer in the question. Aug 2, 2015 at 19:34
  • Isn't there a \begin{equation} missing in your code? Aug 2, 2015 at 19:34
  • @MartinVanderLinden, huh, it is remmant from one other example and I forget to erase it. I will correct a code.
    – Zarko
    Aug 2, 2015 at 19:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .