# Incorrect sizing in nicematrix when using iRow and jCol counters as exponent

I am trying to be fancy/lazy in nicematrix (version 5.19 on Overleaf TeX Live 2020) by generating a matrix using the iRow and jCol counters.

Here is an example of what I try to achieve :

The previous result is done with the following code :

\begin{equation*}
\begin{bNiceMatrix}%
[
r,
first-row,
last-col,
code-for-first-row = \Block{}{\scriptstyle \color{blue} \arabic{jCol}},
code-for-last-col = \scriptstyle \color{red} \arabic{iRow}
]
& & & & \\
(-1)^{1+1+1}(1+1) & (-1)^{1+2+1}(1+2) & (-1)^{1+3+1}(1+3) & (-1)^{1+3+1}(1+4) & \\
(-1)^{2+1+1}(2+1) & (-1)^{2+2+1}(2+2) & (-1)^{2+3+1}(2+3) & (-1)^{2+3+1}(2+4) & \\
(-1)^{3+1+1}(3+1) & (-1)^{3+2+1}(3+2) & (-1)^{3+3+1}(3+3) & (-1)^{3+3+1}(3+4) & \\
(-1)^{4+1+1}(4+1) & (-1)^{4+2+1}(4+2) & (-1)^{4+3+1}(4+3) & (-1)^{4+3+1}(4+4) &
\end{bNiceMatrix}
\end{equation*}


However, instead of defining each term on its own, I try to use iRow and jCol :

\begin{equation*}
\begin{bNiceMatrix}%
[
r,
first-row,
last-col,
code-for-first-row = \Block{}{\scriptstyle \color{blue} \arabic{jCol}},
code-for-last-col = \Block{}{\scriptstyle \color{red} \arabic{iRow}}
]
& & & & \\
(-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
(-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
(-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
(-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) & \\
(-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
(-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
(-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
(-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) & \\
(-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
(-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
(-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
(-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) & \\
(-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
(-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
(-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
(-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) & \\
\end{bNiceMatrix}
\end{equation*}


Which lead to the following result :

There seems to be a sizing problem when using the counters, but the problem only seems to appear when using them as exponent, since removing it also bring back the delimiters to the right place :

\begin{equation*}
\begin{bNiceMatrix}%
[
r,
first-row,
last-col,
code-for-first-row = \Block{}{\scriptstyle \color{blue} \arabic{jCol}},
code-for-last-col = \Block{}{\scriptstyle \color{red} \arabic{iRow}}
]
& & & & \\
(\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
(\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
(\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
(\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) & \\
(\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
(\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
(\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
(\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) & \\
(\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
(\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
(\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
(\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) & \\
(\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
(\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
(\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
(\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) & \\
\end{bNiceMatrix}
\end{equation*}


Finally, nicematrix offers the AutoNiceMatrix commands, and when using them the sizing is correct :

\begin{equation*}
\bAutoNiceMatrix{4-4}{(-1)^{\arabic{iRow} + \arabic{jCol} + 1} (\arabic{iRow}+\arabic{jCol})}
\end{equation*}


For this usecase, the AutoNiceMatrix would be an option, but it is not always possible to define one general term for the matrix.

Has anyone encountered this problem and could help me "generate" my matrices instead of writing them by hand?

• I get the expected result with nicematrix 2021/07/23 v5.19. And also with TeX Live 2020 and nicematrix 2021/03/23 v5.13 Aug 6, 2021 at 14:54
• I think you should try to recompile after deletion of the aux file. In Overleaf: "View logs" (on the right of the PDF panel) and "Clear cache files" (red button). Sometimes, when modifying a document using nicematrix, the informations written on the aux files are out-of-date (because they were valid only for the previous version of the document). Aug 7, 2021 at 17:52
Deleting the aux file and recompiling, as suggested by F. Pantigny in a comment, indeed solved the problem.