I am trying to create a macro to easily draw forks as this one:

enter image description here

I tried this:

 #1 \arrow[r, "#2"] & #3 \arrow[r,shift left, "#4"] 
 \arrow[r,shift right, "#5"'] & #6

But I get an error "Single ampersand used with wrong catcode."


You don't really want to use the center environment, but the main problem is the &:

  \begin{tikzcd}[ampersand replacement=\&]
  #1 \arrow[r, "#2"] \& #3 \arrow[r,shift left, "#4"] 
  \arrow[r,shift right, "#5"'] \& #6

The key ampersand replacement is necessary each time a TikZ matrix (such as a tikzcd diagram) is used in the argument to another command.

Use it in a display environment, say


Here's another suggestion for coping with both equalizer and coequalizer diagrams. Each item in the diagram is defined with a key-value approach (use different keys, if you like); a * tells to draw a coequalizer diagram. Like in most key-value approaches, the order of the keys is irrelevant.



\keys_define:nn { soap/forks }
  s .tl_set:N = \l__soap_fork_source_tl,
  t .tl_set:N = \l__soap_fork_target_tl,
  e .tl_set:N = \l__soap_fork_end_tl,
  u .tl_set:N = \l__soap_fork_up_tl,
  d .tl_set:N = \l__soap_fork_down_tl,
  c .tl_set:N = \l__soap_fork_center_tl,
  * .bool_set:N = \l__soap_fork_co_bool,
  * .default:n = true,

  \keys_set:nn { soap/forks } { #1 }
  \bool_if:NF \l__soap_fork_co_bool
   {% false, equalizer
    \arrow[r,"\l__soap_fork_center_tl"] \&
  \arrow[r,shift~right,"\l__soap_fork_down_tl",swap] \&
  \bool_if:NT \l__soap_fork_co_bool
   {% true, coequalizer
    \arrow[r,"\l__soap_fork_center_tl"] \&





enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.