# Lines inside matrices [duplicate]

How could I produce such an image in code?

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:

Code

 \documentclass[border=5mm,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[auto]
\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\\
};
\draw[blue](M-1-1)--(M-2-2)--(M-3-3)--(M-4-3);
\draw[blue](M-1-2)--(M-2-3)--(M-3-4)--(M-4-4);
\draw[blue](M-1-3)--(M-2-4)--(M-3-5)--(M-4-5);
\end{tikzpicture}
\end{document}


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:

\documentclass[12pt,a4paper]{article}
\usepackage{tikz-cd}

\begin{document}

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

\begin{tikzcd}
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
\end{tikzcd}

\end{document}