# nicematrix codeafter / tikz not working

consider my mwe:

\documentclass[10pt, a4paper]{article}

\usepackage{nicematrix}
\usepackage{tikz}

\begin{document}
$\begin{pNiceMatrix} 1 & 2 & 3 & 4 \\ 5 & 6 & 7 & 8 \\ 9 & 0 & 1 & 2 \\ \end{pNiceMatrix} % \begin{pNiceMatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \CodeAfter \tikz \draw (2-2) circle (2mm) ; \end{pNiceMatrix}$
\end{document}


This is exactly the example of the manual/documentation, but sadly it is not working. (Error:

! Undefined control sequence.
l.17         \CodeAfter


) I already tried compiling with pdflatex, lualatex and xelatex

Does anyone know why this isn't working?

(in the end I want it in a normal math environment, I just took inline mode, since this is one step closer to the original example)

EDIT: When outsourcing the tikz part, it works (but especially for macro/environment writing this is a bit inconvenient)

• The code works for me. Perhaps your packages are outdated. – Steven B. Segletes Jun 5 at 12:23
• If you go to the file where nicematrix is defined (here its /usr/share/texmf-dist/tex/latex/nicematrix/nicematrix.sty whats the indicated Version (in line 21)? (mine is 3.6) – atticus Jun 5 at 12:25
• My log file: Package: nicematrix 2020/05/27 v4.1, Package: tikz 2020/01/08 v3.1.5b (3.1.5b). LaTex version: This is pdfTeX, Version 3.14159265-2.6-1.40.21 (MiKTeX 2.9.7300 64-bit) – Steven B. Segletes Jun 5 at 12:35
• My guess is that it would be a package issue, not your LaTeX installation itself. – Steven B. Segletes Jun 5 at 13:28
• You can always check to see if the string CodeAfterappears in your version of nicematrix.sty – Steven B. Segletes Jun 5 at 13:33

You can't use \CodeAfter in version 3.6 of nicematrix. It has been introduced in version 3.15.

However, this keyword \CodeAfter is only an alternative syntax to specify what is called the code-after in the documentation of nicematrix. You can acheive your goal by using the key code-after (available since version 2.1).

\documentclass[10pt, a4paper]{article}
\usepackage{nicematrix}
\usepackage{tikz}
\begin{document}
$\begin{pNiceMatrix} 1 & 2 & 3 & 4 \\ 5 & 6 & 7 & 8 \\ 9 & 0 & 1 & 2 \\ \end{pNiceMatrix} % \begin{pNiceMatrix}[code-after = \tikz \draw (2-2) circle (2mm) ;] 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{pNiceMatrix}$
\end{document}


If you decide to update nicematrix to the most recent version (4.1), you will have to update also your whole TeX installation because that version uses features in very recent versions of expl3 (which is now a part of the LaTeX kernel).

• Ok, thanks, I think I'll have to wait for arch linux to update their latex package. – atticus Jun 5 at 14:31
• Yes, already tried to only update your package (didn't work as you said). Now I'm trying to collect my tikz code in a pgf key to insert it later on (for environment writing) but up to now it doesn't work (see tex.stackexchange.com/questions/547943/…). – atticus Jun 5 at 14:31