nsajko
This is my stripped down LaTeX code. There's lots of lines but there's also lots of comments and it *is* somewhat stripped down.

\RequirePackage[enable-debug]{expl3}

\ExplSyntaxOn
\debug_on:n {check-declarations, check-expressions, deprecation}
\ExplSyntaxOff

\documentclass{article}

\usepackage{pgfcore}
\usepgfmodule{shapes}
\usepackage{nicematrix}

\ExplSyntaxOn

% Average of two dimens.
\cs_new:Nn \nsajko_dim_average:nn {\dim_eval:n {(#1 + #2)/2}}

\msg_new:nnn {just-my-document} {unknown-value} {Unknown~value~given:~#1}

\dim_new:N \g__nsajko_coord_dim

% arg 1:
%   * a PGF point
%
% arg 2:
%   * the chosen dimension, either x or y
\cs_new_protected:Nn \nsajko_pgf_extract:nn {
\str_case:nnF
{#2}
{
{x} {\pgfextractx {\g__nsajko_coord_dim} {#1}}
{y} {\pgfextracty {\g__nsajko_coord_dim} {#1}}
}
{\msg_expandable_error:nnn {just-my-document} {unknown-value} {#2~in:~nsajko_pgf_extract:nn}}
\dim_use:N \g__nsajko_coord_dim
}

% Average of PGF points along either x or y axis.
%
% arg 1:
%   * PGF point
%
% arg 2:
%   * PGF point
%
% arg 3:
%   * the chosen dimension, either x or y
\cs_new_protected:Nn \nsajko_dim_average_points:nnn {\nsajko_dim_average:nn
{\nsajko_pgf_extract:nn {#1} {#3}}
{\nsajko_pgf_extract:nn {#2} {#3}}
}

% arg 1:
%   * x coordinate
%
% arg 2:
%   * y coordinate
%
% arg 3:
%   * the chosen dimension, either x or y
\cs_new:Nn \nsajko_extract_coord:nnn {
\str_case:nnF
{#3}
{
{x} {#1}
{y} {#2}
}
{
\msg_expandable_error:nnn {just-my-document} {unknown-value} {#3~in:~nsajko_extract_coord:nnn}
-1
}
}

% Implementation detail, use \nsajko_coord:nnnnn instead.
%
% arg 1:
%   * first node name
%
% arg 2:
%   * first node anchor
%
% arg 3:
%   * second node name
%
% arg 4:
%   * second node anchor
%
% arg 5:
%   * the chosen dimension, either x or y
\cs_new_protected:Nn \nsajko_coord_impl:nnnnn {\nsajko_dim_average_points:nnn
% inner
{\pgfpointanchor {#1} {#2}}

% outer
{\pgfpointanchor {#3} {#4}}

{#5}
}

% Implementation detail, use \nsajko_coord:nnnnn instead.
%
% arg 1:
%   * nicematrix environment name
%
% arg 2:
%   * offset
%
% arg 3:
%   * direction
%
% arg 4:
%   * the chosen dimension, either x or y
%
% arg 5:
%   * the x coordinate of the matrix element/table cell
%
% arg 6:
%   * the y coordinate of the matrix element/table cell
\cs_new_protected:Nn \nsajko_coord:nnnnnn {\nsajko_coord_impl:nnnnn
% inner
{#1 - #5 - #6}
{#3}

% outer
{#1 - \int_eval:n {\nsajko_extract_coord:nnn {#5} {#6} {#4} + #2}}
{center}

{#4}
}

\cs_new:Nn \nsajko_coord_helper_lohi_helper_offset:n {
\str_case:nnF
{#1}
{
{lo} {0}
{hi} {1}
}
{
\msg_expandable_error:nnn {just-my-document} {unknown-value} {#1~in:~nsajko_coord_helper_lohi_helper_offset:n}
-1
}
}

\cs_new:Nn \nsajko_coord_helper_lohi_helper_direction:n {
\str_case:nnF
{#1}
{
{lo} {north~west}
{hi} {south~east}
}
{
\msg_expandable_error:nnn {just-my-document} {unknown-value} {#1~in:~nsajko_coord_helper_lohi_helper_direction:n}
invalid~direction
}
}

% arg 1:
%   * nicematrix environment name
%
% arg 2:
%   * either lo or hi, as in "low" and "high"
%
% arg 3:
%   * the chosen dimension, either x or y
%
% arg 4:
%   * the x coordinate of the matrix element/table cell
%
% arg 5:
%   * the y coordinate of the matrix element/table cell
\cs_new_protected:Nn \nsajko_coord:nnnnn {\nsajko_coord:nnnnnn
{#1}
{\nsajko_coord_helper_lohi_helper_offset:n {#2}}
{\nsajko_coord_helper_lohi_helper_direction:n {#2}}
{#3}
{#4}
{#5}
}

% arg 1:
%   * nicematrix environment name
%
% arg 2:
%   * either lo or hi, as in "low" and "high", for x
%
% arg 3:
%   * either lo or hi, as in "low" and "high", for y
%
% arg 4:
%   * the x coordinate of the matrix element/table cell
%
% arg 5:
%   * the y coordinate of the matrix element/table cell
\cs_new_protected:Nn \nsajko_point:nnnnn {\pgfpoint
% x
{\nsajko_coord:nnnnn {#1} {#2} {x} {#4} {#5}}

% y
{\nsajko_coord:nnnnn {#1} {#3} {y} {#4} {#5}}
}

% arg 1:
%   * nicematrix environment name
%
% arg 2:
%   * the x coordinate of the matrix element/table cell
%
% arg 3:
%   * the y coordinate of the matrix element/table cell
\cs_new_protected:Nn \nsajko_cell_partial_box:nnn {
\pgfpathmoveto {\nsajko_point:nnnnn {#1} {lo} {hi} {#2} {#3}}

\pgfpathlineto {\nsajko_point:nnnnn {#1} {hi} {hi} {#2} {#3}}
\pgfpathlineto {\nsajko_point:nnnnn {#1} {hi} {lo} {#2} {#3}}

\pgfusepath {stroke}
}

\cs_new_protected:Nn \nsajko_cell_partial_box_drawn:n {
\pgfrememberpicturepositiononpagetrue

\begin {pgfpicture}
\pgfusepath {use~as~bounding~box}
\nsajko_cell_partial_box:nnn {#1} {1} {1}
\end {pgfpicture}
}

\NewDocumentCommand {\cellPartialBoxDrawn} {m} {
\nsajko_cell_partial_box_drawn:n {#1}
}

\ExplSyntaxOff

\begin{document}
\begin{NiceTabular}{cc}[
name = synthdivtab,
columns-width = auto,
code-after = \cellPartialBoxDrawn{synthdivtab}
]
$$-2$$ & $$-5$$
\end{NiceTabular}
\end{document}


Why do I get these weird error messages when trying to compile the above:

./r.tex:241: Use of \??? doesn't match its definition.
<argument> \???
! Package just-my-document Error: Unknown value given: \def  in: nsajko_p
l.241   \end{NiceTabular}


What is the meaning of \????

The end of the error message produced by my code seems to be cut off by the TeX engine for some reason, but nonetheless it seems like the function \\**nsajko_p**gf_extract:nn received \def for its second parameter, which should always be either x or y. \def is not a command I ever used directly, but it seems to be the TeX primitive for defining macros, so the thing that commands like \cs_new:Nn are probably based on. I don't see how could a function definition find its way into an argument, though.

Any ideas or tips?
Skillmon
# Regarding the \???

You're asking expl3 to print an error message expandably. There are limited ways to do so (unless you're opting for a LuaTeX-only solution, in LuaTeX one could actually get expandable error messages of arbitrary formatting, but that would defeat the purpose of same behaviour in all the major engines). The several solutions all work by throwing a low level error message of TeX in a way that allows to provide additional information via the TeX-mechanism to show the context in which the error was thrown, so we're always exploiting some engine behaviour to do something it wasn't really designed to do.

The way the kernel team decided to throw the error in an expandable manner was to use a macro (in this case \???) that has a specific argument structure (\??? is defined to expect a following ?), but expand it without that matching argument structure. This throws the low level TeX error Use of \??? doesn't match its definition. and the context that is displayed for that shows the real error message (! Package just-my-document Error: Unknown value given: \def  in: nsajko_p), but these context displays only support a limited number of characters and will therefore cut off your message if it gets too long.

There are other means to throw an expandable error (expkv uses another way that allows for a few more context characters, but unfortunately might fail in LuaTeX because you can configure LuaTeX to ignore the low level error that expkv exploits, which is why the team doesn't use that way).

But in the case of an unexpandable function (you define it protected) you don't have to use the expandable mechanism and can use \msg_error:nnn instead of \msg_expandable_error:nnn, and you'll not have the character limit and your error messages works as intended.

# Regarding how a \def ends up there

Let's just say your \nsajko_point:nnnnn ends up inside of \pgfmathparse and that does complicated and strange stuff leading to your macro not getting the arguments you're expecting.

You got two options:

1. Either make it fully expandable (good luck with that, things like \pgfextractx or \pgfpointanchor aren't expandable and you'd have to somehow rebuild them expandable...)

2. Change your implementation to instead of nest your \nsajko_point:nnnnn inside of \pgfmoveto and friends use them beforehand to extract the point and then use \pgfmoveto with the result of that extraction.

I'd go with the second route...

# Any ideas and tips:

To find out how a \def ends up in your function's argument you could either use the unravel package (I really like it, but it has its limits), or use the \tracing... macros built into TeX (search for help on the latter, you should find plenty information on the interwebs (e.g., [here is some](https://topanswers.xyz/tex?q=3372#a3545)); or shoot with nukes on a fly and use \tracingall -- **Warning:** \tracingall leads to much information in your log and really bloats it up, and could make the information you want to find hard to spot, I take no liability for any physical or mental harm caused by activating \tracingall on code using pgf/Ti*k*Z, beamer or any other complicated code!).

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.