The easiest solution would be where the tikzcd
is using an unnumbered display math environment, i.e. equation*
or \[ … \]
and we will just place nodes with the equation number in it.
This seems to be compatible with hyperref
but needs adjustments for cleveref
(and then we might be able to introduce a separate category for those references as well).
All those macros are amsmath
internals:
\@eqnwstrue
toggles the output of equation numbers inside math environments that don't have one for
\make@display@tag
which prints the actual equation number and
\ltx@label
is the original \label
macro before amsmath
added its own changes.
Code
\documentclass{article}
\usepackage{tikz, amsmath}
\usetikzlibrary{cd}
\makeatletter
\tikzcdset{
eq node/.style={
commutative diagrams/math mode=false, anchor=center},
eq/.style={
phantom,
/tikz/every to/.append style={
edge node={node[commutative diagrams/eq node]
{\@eqnswtrue\make@display@tag\ltx@label{#1}}}}}}
\makeatother
\begin{document}
\[
\begin{tikzcd}
A \arrow["h", dr] \arrow[dd,"j"'] \arrow["f",rr]
& \arrow[d, eq=eq:foo]
& B \arrow[dl, "g"] \\
\arrow[r, eq=eq:bar]
& C \\
D \arrow[ru,"k"]
\end{tikzcd}
\]
Equations \ref{eq:foo} and \eqref{eq:bar}.
\end{document}
Output
equation
counter, i.e. the one ofamsmath
or are those numbers independent and maybe just unique per CD? (You could give the CD a number and then have subequations numbers inside the diagram.) What are these number referencing? A node? An arrow? A label? In your mock up they seem just randomly placed near C.equation
counter but your idea of giving the CD a diagram would work as a workaround.