# How to annotate matrix using tikz

so not really sure on how I can achieve this, I have tried to do it so far with tikznode and didn't get it to look like I wanted, granted not really sure of what I'm doing. This is the output I'm trying to get :

This is the basic code I'm using, without any annotation added to it :

\documentclass{article}
\usepackage{amsmath,mathrsfs}
\usepackage[usenames, dvipsnames,svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{intersections, decorations.pathreplacing,shapes,shapes.geometric,hobby,patterns,babel,matrix,calc}
\DeclareMathOperator{\Mat}{Mat}
\begin{document}
$L_{ij}(k) \rightarrow E_{ij}(k) = \begin{pmatrix} 1 & & & \\ & 1 & & \\ k & & \ddots & \\ & & & 1 \end{pmatrix}$
\end{document}


The new version of tikzmark is soon part of the standard TeX distribution. It contains a command \tikzmarknode, which can be used as follows:

\documentclass{article}
\usepackage{amsmath,mathrsfs}
\usepackage[usenames, dvipsnames,svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc}
\DeclareMathOperator{\Mat}{Mat}
\begin{document}
$L_{ij}(k) \rightarrow E_{ij}(k) = \begin{pmatrix} \tikzmarknode{l1}{1} & & & \\ & \tikzmarknode{l2}{1} & & \\ \tikzmarknode{k}{k} & & \ddots & \\ & & & \tikzmarknode{l3}{1} \end{pmatrix}$
\begin{tikzpicture}[overlay,remember picture]
\draw[<-] ($(l1.center)!0.5!(l2.center)$) to[out=45,in=180]
($(l1)+(2.5cm,0)$) node[right,anchor=north west,align=left,yshift=\baselineskip]{some long text\\
and more text};
\draw[<-,shorten <=3pt] (k.west) --++ (-0.4,0) node[left] {text};
\draw[<-,shorten <=3pt] (k.south) --++ (0,-0.8) node[below] {more text};
\end{tikzpicture}
\end{document}


Note that you may have to update your TeX distribution to run this (in case you do not yet have the newest version of the tikzmark library).