How could I produce such an image in code?

enter image description here

I'd also like to draw vector arrows by the end of the lines, in order to see the order of the calculations. I saw a TikZ solution on other answer that didn't work for me. Not only the code gave me an error, it's not fully what I want (I want it to look like a parentheses matrix, and I'd also like to have a convenient macro to produce it with just some few inputs). Here's this partial solution (given by Andrew here) I'm talking about:

Here is a quick hack using a matrix of math nodes and tikz:

enter image description here


       \matrix (M)[matrix of math nodes,row sep=1cm,column sep=16mm]{
        a & b & c & a & b\\ d & e & f & d & e\\ g & h & i & g & h\\&&[blue]adi&[red]-bfg&[blue]cdh\\

Also, that little product he put just below the lines showing the multiplication results are pretty awesome. Any way to implement it with what I've asked?


tikz-cd solution:



\tikzset{delim/.style={thick,shorten >=-1em,shorten <=-1em}}

a\arrow[xshift=-12pt,delim,dash]{ddd}\arrow[dash]{rd} & b\arrow[dash]{rd}                 & c\arrow[dash]{rd}\arrow[dash]{ld} & a\arrow[xshift=-30pt,delim,dash]{ddd}\arrow[dash]{ld} & b\arrow[dash]{ld} \\
d                                                     & e\arrow[dash]{rd}\arrow[dash]{ld} & f\arrow[dash]{rd}\arrow[dash]{ld} & d\arrow[dash]{rd}\arrow[dash]{ld}                     & e                 \\
g                                                     & h                                 & i\arrow[dash]{d}                  & g\arrow[dash]{d}                                      & h\arrow[dash]{d}  \\
\phantom{a}                                           &                                   & adi                               & -bfg                                                  & cdh


enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.