[Tex/LaTex] Put a circle around elements in a matrix environment

matricesnodestikz-pgf

So I'm trying to put circles around 6,8,10,18 in row 1-4 respectively, however this does give me an error warning saying "missing $ inserted"

\documentclass{article}
\usepackage{mathtools}
\setlength\parindent{0pt}
\usepackage{tikz}



\begin{document}

$   
\text{M}=\begin{pmatrix}
4 & \tikz\node[draw,circle]{6} & 4 & 5 \\ 
3 & 8 & 1 & 6 \\ 
2 & 9 & 2 & 10 \\ 
1 & 2 & 3 & 18
\end{pmatrix}
$ 

\end{document}

How can I correct this error, because positioning various $ around the command hasn't helped so far.

Best Answer

The tikz code must always be ended with a semicolon.

4 & \tikz\node[draw,circle]{6}; & 4 & 5 \\ 

matrice

\documentclass{article}
\usepackage{mathtools}
\setlength\parindent{0pt}
\usepackage{tikz}

\begin{document}

$   
\text{M}=
\begin{pmatrix}
4 & \tikz\node[draw,circle]{6}; & 4 & 5 \\ 
3 & 8 & 1 & 6 \\ 
2 & 9 & 2 & 10 \\ 
1 & 2 & 3 & 18
\end{pmatrix}
$ 
\end{document}