Improved open and closed immersions in tikz-cd
A long time ago, I explained how to draw arrows for open and closed immersions in tikz-cd
. Back then I already mentioned that my solution is not completely satisfactory. Yun Hao took up the challenge, and significantly improved my implementation.
\usetikzlibrary{decorations.markings}
\makeatletter
\tikzcdset{
open/.code = {\tikzcdset{hook, circled};},
closed/.code = {\tikzcdset{hook, slashed};},
open'/.code = {\tikzcdset{hook', circled};},
closed'/.code = {\tikzcdset{hook', slashed};},
circled/.code = {\tikzcdset{markwith = {\draw (0,0) circle (.375ex);}};},
slashed/.code = {\tikzcdset{markwith = {\draw[-] (-.4ex,-.4ex) -- (.4ex,.4ex);}};},
markwith/.code ={
\pgfutil@ifundefined%
{tikz@library@decorations.markings@loaded}%
{\pgfutil@packageerror{tikz-cd}{You need to say %
\string\usetikzlibrary{decorations.markings} to use arrows with markings}{}}{}%
\pgfkeysalso{/tikz/postaction = {
/tikz/decorate,
/tikz/decoration={markings, mark = at position 0.5 with {#1}}}
}
},
}
\makeatother
His example produces the following result
Observe that the position of the circle will be perfect in each font, whereas my solution was greatly font-dependent on how good the result was.
Many thanks to him for letting sharing his code!