2

I have the following commuting diagram and I want to insert equation labels as (phantom) edge labels inside the diagram (the label here doesn't work, it's pseudocode):

\begin{tikzcd}
      A \arrow["h",dr] \arrow[dd,"j"'] \arrow["f",rr] & \arrow[d,phantom, "\label{eq:foo}" description] & B\arrow[dl, "g"] \\
      \arrow[r,phantom, "\label{eq:bar}" description]& C \\
      D\arrow[ru,"k"]
    \end{tikzcd}

And I want it to visually look like this:

enter image description here

Is there a way to do this? Basically I want to refer to different parts of the diagram commuting using different equation references.

2
  • Should these equation numbers follow the normal equation counter, i.e. the one of amsmath 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. Commented Sep 2, 2023 at 12:55
  • They are referencing parts of the commutative diagram, see tex.stackexchange.com/questions/480073/…. I was thinking of having them follow the normal equation counter but your idea of giving the CD a diagram would work as a workaround.
    – cxandru
    Commented Sep 2, 2023 at 12:59

1 Answer 1

3

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

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .