Determinant of 3x3 matrix by cofactor expansion

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}

\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,baseline=(#1.base)] \node (#1) {#2};}

\begin{document}
\[
 \left[\begin{array}{*3{c}}
    \tikzmark{left_end}{0} & 2 & \tikzmark{right_end}{1}\\
    3 & -1 & 2 \\
    \tikzmark{down_left}{4} & 0 & \tikzmark{down}{1}
  \end{array}\right]
\]
\tikz[overlay,remember picture] {
\draw[red,thick,dashed] (left_end) circle (0.2cm);
    \draw[-,red,thick] (left_end) -- ++ (1.7,0) (right_end);
    \draw[-,red,thick] (left_end) -- ++ (0,-1.) (down_left);
}
\end{document}

enter image description here


This is more an extended comment on the answer by Sina Ahmadi. I will be happy to remove this if in that answer a few things get changed.

  1. \tikzmark is a phantastic command that is part of the tikzmark library. I would like to argue that creating a new command with this name is not a good practice.
  2. The nodes right_end and down_left are not used. The lines are drawn as determined by the two hard-coded distances - ++ (1.7,0) and - ++ (0,-1.).

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}
\[\begin{bmatrix}
    \tikzmarknode[circle,draw=red,inner sep=0.5pt,densely dashed]{A11}{0} & 2 & \tikzmarknode{A13}{1}\\
    3 & -1 & 2 \\
    \tikzmarknode{A31}{4} & 0 & 1
 \end{bmatrix} 
\]
\begin{tikzpicture}[overlay,remember picture] 
\draw[red] (A11.east) -- (A11.east-|A13.east)
(A11.south) -- (A11.south|-A31.south);
\end{tikzpicture}
\end{document}

enter image description here


A simple code with pstricks and mathtools:

\documentclass[svgnames]{article}
\usepackage{mathtools} 
\usepackage{pst-node, auto-pst-pdf}

\begin{document}

\begin{postscript}
\psset{{linecolor=DeepPink}, framesep=2pt, nodesepB=-8pt}
\[ \begin{bmatrix}
\mathclap{\circlenode[linestyle=dashed, dash=3.5pt 2.5pt]{A}{0}} & 2 & \rnode{C}{1} \\
3 & -1 & 2 \\
\rnode{B}{4} & 0 & 1 
\end{bmatrix} \]
\ncline{A}{B}
\ncline{A}{C}
\end{postscript}

\end{document} 

enter image description here

Ensure you have --enable-write18 in your LaTeX command/engine so that auto-pst-pdf works.