Debian Codegraph @

texmf-dist/tex/generic/tikz-cd/tikzlibrarycd.code.tex

raw
1 %% tikzlibrarycd.code.tex [2021/05/04 v1.0 Commutative diagrams with TikZ]
2 %% Copyright 2011, 2012, 2014, 2018, 2021 Augusto Stoffel
3 %
4 % This work may be distributed and/or modified under the
5 % conditions of the LaTeX Project Public License, either version 1.3
6 % of this license or (at your option) any later version.
7 % The latest version of this license is in
8 % http://www.latex-project.org/lppl.txt
9 % and version 1.3 or later is part of all distributions of LaTeX
10 % version 2005/12/01 or later.
11 %
12 % This work has the LPPL maintenance status `maintained'.
13 %
14 % The Current Maintainer of this work is Augusto Stoffel.
15 %
16 % This work consists of the files tikzlibrarycd.code.tex, tikz-cd.sty
17 % and tikz-cd-doc.tex.
18
19 \usetikzlibrary{matrix,quotes,arrows.meta}
20
21 \newif\iftikzcd@mathmode
22
23 \def\tikzcdset{\pgfqkeys{/tikz/commutative diagrams}}
24
25 \tikzcdset{
26 arrows/.code={\tikzcdset{every arrow/.append style={#1}}},
27 labels/.code={\tikzcdset{every label/.append style={#1}}},
28 cells/.code={\tikzcdset{every cell/.append style={#1}}},
29 diagrams/.code={\tikzcdset{every diagram/.append style={#1}}},
30 execute before arrows/.code={%
31 \expandafter\def%
32 \expandafter\tikzcd@before@paths@hook%
33 \expandafter{\tikzcd@before@paths@hook#1}},
34 to/.code={\tikzcd@setarrowend\tikzcd@ar@target{#1}},
35 from/.code={\tikzcd@setarrowend\tikzcd@ar@start{#1}},
36 shorten/.style={
37 /tikz/shorten <=#1,
38 /tikz/shorten >=#1},
39 description/.style={
40 /tikz/anchor=center,
41 /tikz/fill=\pgfkeysvalueof{/tikz/commutative diagrams/background color}},
42 marking/.style={
43 /tikz/font=,
44 /tikz/sloped,
45 /tikz/shape=asymmetrical rectangle,
46 /tikz/anchor=center},
47 phantom/.style={
48 /tikz/draw=none,
49 /tikz/commutative diagrams/labels={
50 /tikz/font=,
51 /tikz/anchor=center}},
52 crossing over/.style={
53 /tikz/preaction={
54 /tikz/draw=\pgfkeysvalueof{/tikz/commutative diagrams/background color},
55 /tikz/arrows=-,
56 /tikz/line width=\pgfkeysvalueof{/tikz/commutative diagrams/crossing over clearance}}},
57 cramped/.code={\tikzcdset{
58 every matrix/.append style={inner sep=+-0.3em},
59 every cell/.append style={inner sep=+0.3em}}},
60 row sep/.code={\tikzcd@sep{row}{#1}},
61 column sep/.code={\tikzcd@sep{column}{#1}},
62 sep/.code={\tikzcdset{row sep={#1},column sep={#1}}},
63 math mode/.is if=tikzcd@mathmode,
64 arrow style/.is choice}
65
66 \def\tikzcd@sep#1#2{%
67 \pgfkeysifdefined{/tikz/commutative diagrams/#1 sep/#2}%
68 {\pgfkeysgetvalue{/tikz/commutative diagrams/#1 sep/#2}\tikzcd@temp%
69 \pgfkeysalso{/tikz/#1 sep/.expand once=\tikzcd@temp}}%
70 {\pgfkeysalso{/tikz/#1 sep={#2}}}}
71
72 \def\tikzcd@setarrowend#1#2{%
73 \pgfutil@ifundefined{pgf@sh@ns@\tikzcdmatrixname-#2}%
74 {%
75 \c@pgf@counta=0%
76 \c@pgf@countb=0%
77 \let\tikzcd@temp=\tikzcd@parse%
78 \expandafter\tikzcd@temp#2\relax%
79 \ifx\tikzcd@temp\pgfutil@empty% true if it was a direction parameter
80 \advance\c@pgf@counta by\tikzcd@currentrow%
81 \advance\c@pgf@countb by\tikzcd@currentcolumn%
82 \edef#1{\tikzcdmatrixname-\the\c@pgf@counta-\the\c@pgf@countb}%
83 \else%
84 \def#1{#2}%
85 \fi%
86 }{%
87 \def#1{\tikzcdmatrixname-#2}%
88 }}
89
90 % The unknown key handler and direction argument parser
91 \tikzcdset{
92 .unknown/.code={%
93 \ifpgfkeysaddeddefaultpath%
94 \c@pgf@counta=0%
95 \c@pgf@countb=0%
96 \let\tikzcd@temp=\tikzcd@parse%
97 \expandafter\tikzcd@temp\pgfkeyscurrentname\relax%
98 \ifx\tikzcd@temp\pgfutil@empty% true if it was a direction parameter
99 \advance\c@pgf@counta by\tikzcd@currentrow%
100 \advance\c@pgf@countb by\tikzcd@currentcolumn%
101 \edef\tikzcd@ar@target{\tikzcdmatrixname-\the\c@pgf@counta-\the\c@pgf@countb}%
102 \else%
103 \pgfqkeys{/tikz}{\pgfkeyscurrentname={#1}}%
104 \fi%
105 \else%
106 \def\pgfutilnext{\pgfkeysvalueof{/handlers/.unknown/.@cmd}#1\pgfeov}\pgfutilnext%
107 \fi}}
108
109 \def\tikzcd@parse#1{% parser for arrow direction argument
110 \ifx#1r\advance\c@pgf@countb by1\else%
111 \ifx#1d\advance\c@pgf@counta by1\else%
112 \ifx#1l\advance\c@pgf@countb by-1\else%
113 \ifx#1u\advance\c@pgf@counta by-1\else%
114 \ifx#1\relax\let\tikzcd@temp\pgfutil@empty%
115 \else\let\tikzcd@temp\pgfutil@gobble@until@relax\fi\fi\fi\fi\fi%
116 \tikzcd@temp}
117
118 % The `tikzcd' environment
119 \def\tikzcd{%
120 \iffalse{\fi\ifnum0=`}\fi% standard trick to allow nesting of tabular-like environments (cf. the tabularx manual)
121 \pgfutil@ifnextchar&% if we get an & here, it will be returned with the wrong catcode to the input stream
122 {\expandafter\tikzcd@@\expandafter\pgfmatrixnextcell\pgfutil@gobble}%
123 {\tikzcd@@}}
124
125 \def\tikzcd@@{\pgfutil@ifnextchar[{\tikzcd@handle@shortcuts@next\tikzcd@}{\tikzcd@[]}}
126
127 \def\tikzcd@[#1]{%
128 \tikzpicture[/tikz/commutative diagrams/.cd,every diagram,#1]%
129 \ifx\arrow\tikzcd@arrow%
130 \pgfutil@packageerror{tikz-cd}{Diagrams cannot be nested}{}%
131 \fi%
132 \let\arrow\tikzcd@arrow%
133 \let\ar\tikzcd@arrow%
134 \def\rar{\tikzcd@xar{r}}%
135 \def\lar{\tikzcd@xar{l}}%
136 \def\dar{\tikzcd@xar{d}}%
137 \def\uar{\tikzcd@xar{u}}%
138 \def\urar{\tikzcd@xar{ur}}%
139 \def\ular{\tikzcd@xar{ul}}%
140 \def\drar{\tikzcd@xar{dr}}%
141 \def\dlar{\tikzcd@xar{dl}}%
142 \global\let\tikzcd@savedpaths\pgfutil@empty%
143 \matrix[%
144 /tikz/matrix of \iftikzcd@mathmode math \fi nodes,%
145 /tikz/every cell/.append code={\tikzcdset{every cell}},%
146 /tikz/commutative diagrams/.cd,every matrix]%
147 \bgroup}
148
149 \def\endtikzcd{%
150 \pgfmatrixendrow\egroup%
151 \pgfextra{\global\let\tikzcdmatrixname\tikzlastnode};%
152 \tikzcdset{\the\pgfmatrixcurrentrow-row diagram/.try}%
153 \begingroup%
154 \pgfkeys{% `quotes' library support
155 /handlers/first char syntax/the character "/.initial=\tikzcd@forward@quotes,%
156 /tikz/edge quotes mean={%
157 edge node={node [execute at begin node=\iftikzcd@mathmode$\fi,%$
158 execute at end node=\iftikzcd@mathmode$\fi,%$
159 /tikz/commutative diagrams/.cd,every label,##2]{##1}}}}%
160 \let\tikzcd@errmessage\errmessage% improve error messages
161 \def\errmessage##1{\tikzcd@errmessage{##1^^J...^^Jl.\tikzcd@lineno\space%
162 I think the culprit is a tikzcd arrow in cell \tikzcd@currentrow-\tikzcd@currentcolumn}}%
163 \tikzcd@before@paths@hook%
164 \tikzcd@savedpaths%
165 \endgroup%
166 \endtikzpicture%
167 \ifnum0=`{}\fi}
168
169 % The arrow commands
170 \def\tikzcd@arrow{%
171 \relax% this was added to avoid errors when a cell starts with \arrow, but it seems unnecessary now
172 \edef\tikzcd@temp{%
173 \noexpand\def\noexpand\tikzcd@currentcolumn{\the\pgfmatrixcurrentcolumn}%
174 \noexpand\def\noexpand\tikzcd@currentrow{\the\pgfmatrixcurrentrow}%
175 \noexpand\def\noexpand\tikzcd@lineno{\the\inputlineno}}%
176 \expandafter\pgfutil@g@addto@macro\expandafter\tikzcd@savedpaths\expandafter{\tikzcd@temp}%
177 \pgfutil@ifnextchar[{\tikzcd@handle@shortcuts@next\tikzcd@@arrow}{\tikzcd@ar@old[]}}
178
179 \def\tikzcd@@arrow[#1]{\pgfutil@ifnextchar\bgroup{\tikzcd@ar@old[#1]}{\tikzcd@ar@new[#1]}}
180
181 \def\tikzcd@ar@new[#1]{% new syntax
182 \pgfutil@g@addto@macro\tikzcd@savedpaths{%
183 \path[/tikz/commutative diagrams/.cd,every arrow,#1]%
184 (\tikzcd@ar@start\tikzcd@startanchor) to (\tikzcd@ar@target\tikzcd@endanchor); }}
185
186 \def\tikzcd@ar@old[#1]#2{% old syntax
187 \pgfutil@ifnextchar[%
188 {\tikzcd@handle@shortcuts@next\tikzcd@ar@getlabel{to={#2},#1}}%
189 {\pgfutil@ifnextchar\bgroup%
190 {\tikzcd@ar@getlabel{to={#2},#1}[]}%
191 {\tikzcd@ar@new[to={#2},#1]}}}
192
193 \def\tikzcd@ar@getlabel#1[#2]#3{%
194 \pgfutil@ifnextchar[%
195 {\tikzcd@handle@shortcuts@next\tikzcd@ar@getlabel{#1,"{#3}"{#2}}}%
196 {\pgfutil@ifnextchar\bgroup%
197 {\tikzcd@ar@getlabel{#1,"{#3}"{#2}}[]}%
198 {\tikzcd@ar@new[#1,"{#3}"{#2}]}}}
199
200 \def\tikzcd@xar#1{\relax\pgfutil@ifnextchar[{\tikzcd@handle@shortcuts@next\tikzcd@@xar{#1}}{\tikzcd@arrow[]{#1}}}
201 \def\tikzcd@@xar#1[#2]{\tikzcd@arrow[#2]{#1}}
202
203 \def\tikzcd@handle@shortcuts@next{% expand next macro using standard catcodes
204 \iftikz@handle@active@code%
205 \begingroup%
206 \tikz@switchoff@shorthands\expandafter%
207 \endgroup\expandafter%
208 \fi}
209
210 \def\tikzcd@ar@target{\tikzcdmatrixname-\tikzcd@currentrow-\tikzcd@currentcolumn}
211 \def\tikzcd@ar@start{\tikzcdmatrixname-\tikzcd@currentrow-\tikzcd@currentcolumn}
212
213 \def\tikzcd@forward@quotes#1{\tikzset{every to/.append style={#1}}}
214
215 \let\tikzcd@before@paths@hook\pgfutil@empty
216
217 % `start anchor', `end anchor', and `shift' keys
218 \def\tikzcd@setanchor#1[#2]#3\relax{%
219 \ifx\relax#2\relax\else%
220 \tikzcdset{@#1transform/.append style={#2},@shiftabletopath}%
221 \fi%
222 \ifx\relax#3\relax%
223 \pgfutil@namelet{tikzcd@#1anchor}{pgfutil@empty}%
224 \else%
225 \pgfutil@namedef{tikzcd@#1anchor}{.#3}%
226 \fi}
227
228 \tikzcdset{
229 @shiftabletopath/.style={
230 /tikz/execute at begin to={%
231 \begingroup%
232 \def\tikz@tonodes{coordinate[pos=0,commutative diagrams/@starttransform/.try](tikzcd@nodea) %
233 coordinate[pos=1,commutative diagrams/@endtransform/.try](tikzcd@nodeb)}%
234 \path (\tikztostart) \tikz@to@path;%
235 \endgroup%
236 \def\tikztostart{tikzcd@nodea}%
237 \def\tikztotarget{tikzcd@nodeb}%
238 \tikzset{insert path={(tikzcd@nodea)}}},
239 /tikz/commutative diagrams/@shiftabletopath/.code={}},
240 start anchor/.code={%
241 \pgfutil@ifnextchar[{\tikzcd@setanchor{start}}{\tikzcd@setanchor{start}[]}#1\relax},%]
242 end anchor/.code={%
243 \pgfutil@ifnextchar[{\tikzcd@setanchor{end}}{\tikzcd@setanchor{end}[]}#1\relax},%]
244 start anchor=,
245 end anchor=,
246 shift left/.style={
247 /tikz/commutative diagrams/@shiftabletopath,
248 /tikz/execute at begin to={%
249 \pgfpointnormalised{%
250 \pgfpointdiff{\pgfpointanchor{tikzcd@nodeb}{center}}{\pgfpointanchor{tikzcd@nodea}{center}}}%
251 \pgfgetlastxy{\tikzcd@x}{\tikzcd@y}%
252 \pgfmathparse{#1}%
253 \ifpgfmathunitsdeclared\else
254 \pgfmathparse{\pgfmathresult*\pgfkeysvalueof{/tikz/commutative diagrams/shift left/.@def}}
255 \fi
256 \coordinate (tikzcd@nodea) at ([shift={(\pgfmathresult*\tikzcd@y,-\pgfmathresult*\tikzcd@x)}]tikzcd@nodea);%
257 \coordinate (tikzcd@nodeb) at ([shift={(\pgfmathresult*\tikzcd@y,-\pgfmathresult*\tikzcd@x)}]tikzcd@nodeb);%
258 \tikzset{insert path={(tikzcd@nodea)}}}},
259 shift right/.style={
260 /tikz/commutative diagrams/shift left={-(#1)}},
261 transform nodes/.style={
262 /tikz/commutative diagrams/@shiftabletopath,
263 /tikz/commutative diagrams/@starttransform/.append style={#1},
264 /tikz/commutative diagrams/@endtransform/.append style={#1}},
265 shift/.style={
266 /tikz/shift={#1},% we need this for labels to receive a shift
267 /tikz/commutative diagrams/transform nodes={/tikz/shift={#1}}},
268 xshift/.style={
269 /tikz/xshift={#1},
270 /tikz/commutative diagrams/transform nodes={/tikz/xshift={#1}}},
271 yshift/.style={
272 /tikz/yshift={#1},
273 /tikz/commutative diagrams/transform nodes={/tikz/yshift={#1}}}}
274
275 % pgfmath functions to obtain math fontdimens
276 \pgfutil@ifluatex
277
278 \directlua{tex.enableprimitives('tikzcd@', {'Umathaxis', 'Umathfractionrule'})}
279
280 \pgfmathdeclarefunction{axis_height}{0}{%
281 \begingroup%
282 $\relax$% update fontdimens
283 \pgfmathreturn\the\tikzcd@Umathaxis\textstyle%
284 \endgroup}
285
286 \pgfmathdeclarefunction{rule_thickness}{0}{%
287 \begingroup%
288 $\relax$%
289 \pgfmathreturn\the\tikzcd@Umathfractionrule\textstyle%
290 \endgroup}
291
292 \else% if using (pdf)tex
293
294 \pgfmathdeclarefunction{axis_height}{0}{%
295 \begingroup%
296 $\relax$% update fontdimens
297 \pgfmathreturn\the\fontdimen22\textfont2%
298 \endgroup}
299
300 \pgfmathdeclarefunction{rule_thickness}{0}{%
301 \begingroup%
302 $\relax$%
303 \pgfmathreturn\the\fontdimen8\textfont3%
304 \endgroup}
305
306 \fi
307
308 % The shape used inside matrices
309 \pgfdeclareshape{asymmetrical rectangle} {
310 \inheritsavedanchors[from={rectangle}]
311 \inheritanchor[from={rectangle}]{base}
312 \inheritanchor[from={rectangle}]{north}
313 \inheritanchor[from={rectangle}]{south}
314 \inheritanchor[from={rectangle}]{base west}
315 \inheritanchor[from={rectangle}]{north west}
316 \inheritanchor[from={rectangle}]{south west}
317 \inheritanchor[from={rectangle}]{base east}
318 \inheritanchor[from={rectangle}]{north east}
319 \inheritanchor[from={rectangle}]{south east}
320 \inheritanchor[from={rectangle}]{mid}
321 \inheritanchor[from={rectangle}]{mid west}
322 \inheritanchor[from={rectangle}]{mid east}
323 \inheritbackgroundpath[from={rectangle}]
324 \anchor{center}{\pgf@anchor@rectangle@center\pgfmathsetlength\pgf@y%
325 {\pgfkeysvalueof{/tikz/commutative diagrams/center yshift}}}
326 \anchor{west}{\pgf@anchor@rectangle@west\pgfmathsetlength\pgf@y%
327 {\pgfkeysvalueof{/tikz/commutative diagrams/center yshift}}}
328 \anchor{east}{\pgf@anchor@rectangle@east\pgfmathsetlength\pgf@y%
329 {\pgfkeysvalueof{/tikz/commutative diagrams/center yshift}}}
330 \anchor{real center}{\pgf@anchor@rectangle@center}
331 \anchor{real west}{\pgf@anchor@rectangle@west}
332 \anchor{real east}{\pgf@anchor@rectangle@east}
333 \anchorborder{%
334 \pgfmathsetlength\pgfutil@tempdima%
335 {\pgfkeysvalueof{/tikz/commutative diagrams/center yshift}}%
336 \pgf@xb=\pgf@x% xb/yb is target
337 \pgf@yb=\pgf@y%
338 \southwest%
339 \pgf@xa=\pgf@x% xa/ya is se
340 \pgf@ya=\pgf@y%
341 \northeast%
342 \advance\pgf@x by-\pgf@xa%
343 \advance\pgf@y by-\pgf@ya%
344 \pgf@xc=.5\pgf@x% x/y is half width/height
345 \pgf@yc=.5\pgf@y%
346 \advance\pgf@xa by\pgf@xc% xa/ya becomes center
347 \advance\pgf@ya by\pgf@yc%
348 \ifdim\pgf@yb>0pt%
349 \northeast%
350 \pgf@yc=\pgf@y%
351 \advance\pgf@yc by-\pgfutil@tempdima%
352 \else%
353 \southwest%
354 \pgf@yc=-\pgf@y%
355 \advance\pgf@yc by\pgfutil@tempdima%
356 \fi
357 \edef\pgf@marshal{%
358 \noexpand\pgfpointborderrectangle
359 {\noexpand\pgfqpoint{\the\pgf@xb}{\the\pgf@yb}}
360 {\noexpand\pgfqpoint{\the\pgf@xc}{\the\pgf@yc}}%
361 }%
362 \pgf@process{\pgf@marshal}%
363 \advance\pgf@x by\pgf@xa%
364 \advance\pgf@y by\pgfutil@tempdima%
365 }%
366 }%
367
368 % Computer modern arrow tips
369 \pgfkeys{
370 cm to/.tip={Computer Modern Rightarrow[length=+0pt 6.2]},
371 cm bold to/.tip={cm to[scale=0.667]},
372 cm double to/.tip={cm to[sep=+0pt -2.6]cm to},
373 cm bar/.tip={Bar[width=+0pt 8.2 0.89,line cap=round]},
374 cm left hook/.tip={Hooks[width=+0pt 10.8,length=+0pt 3.6,harpoon,line cap=round]},
375 cm implies/.tip={Implies},
376 cm left to/.tip={cm to[left]},
377 cm right to/.tip={cm to[right]},
378 cm right hook/.tip={cm left hook[swap]},
379 cm to reversed/.tip={cm to[reversed]},
380 cm */.tip={Circle[length=+0pt 7.6]},
381 cm o/.tip={cm *[open]},
382 cm |/.tip={cm bar}}%|
383
384 % The `Glyph' meta arrow tip
385 \pgfqkeys{/pgf/arrow keys}{
386 glyph math command/.code={% if csname #1 is undefined, we want it to remain so
387 \pgfarrowsaddtooptions{\def\tikzcd@glyph{$\begingroup\expandafter\endgroup\csname #1\endcsname$}}},
388 glyph axis/.code={\pgfarrowsaddtooptions{\pgfmathsetlengthmacro\tikzcd@glyph@axis{#1}}},
389 glyph length/.code={\pgfarrowsaddtooptions{\pgfmathsetlengthmacro\tikzcd@glyph@len{#1}}},
390 glyph shorten/.code={\pgfarrowsaddtooptions{\pgfmathsetlengthmacro\tikzcd@glyph@shorten{#1}}}}
391
392 \pgfdeclarearrow{
393 name=Glyph,
394 cache=false,
395 bending mode=none,
396 parameters={\tikzcd@glyph@len,\tikzcd@glyph@shorten},
397 setup code={%
398 \pgfarrowssettipend{\tikzcd@glyph@len\advance\pgf@x by\tikzcd@glyph@shorten}},
399 defaults={
400 glyph axis=axis_height,
401 glyph length=+0.9ex,
402 glyph shorten=+-0.1ex},
403 drawing code={%
404 \pgfpathrectangle{\pgfpoint{+0pt}{+-1ex}}{\pgfpoint{+\tikzcd@glyph@len}{+2ex}}%
405 \pgfusepathqclip%
406 \pgftransformxshift{+\tikzcd@glyph@len}%
407 \pgftransformyshift{+-\tikzcd@glyph@axis}%
408 \pgftext[right,base]{\tikzcd@glyph}}}
409
410 % Arrow tip selection styles
411 \tikzcdset{
412 double line/.code={\tikzset{%
413 double equal sign distance,
414 double=\pgfkeysvalueof{/tikz/commutative diagrams/background color}}},
415 dashed/.style={/tikz/dash pattern={on 7\pgflinewidth off 4\pgflinewidth}},
416 tikzcd to/.tip={cm to},
417 tikzcd bar/.tip={cm bar},
418 tikzcd left hook/.tip={cm left hook},
419 tikzcd double to/.tip={cm double to},
420 tikzcd implies/.tip={Implies},
421 tikzcd right hook/.tip={tikzcd left hook[swap]},
422 tikzcd left to/.tip={tikzcd to[harpoon]},
423 tikzcd right to/.tip={tikzcd left to[swap]},
424 tikzcd to reversed/.tip={tikzcd to[reversed]},
425 tikzcd cap/.tip={},
426 tikzcd implies cap/.tip={},
427 tikzcd implies bar/.tip={tikzcd bar},
428 no tail/.code={\pgfsetarrowsstart{tikzcd cap}},
429 to head/.code={\pgfsetarrowsend{tikzcd to}},
430 maps to/.code={\pgfsetarrowsstart{tikzcd bar}},
431 hook/.code={\pgfsetarrowsstart{tikzcd right hook}},
432 hook'/.code={\pgfsetarrowsstart{tikzcd left hook}},
433 harpoon/.code={\pgfsetarrowsend{tikzcd left to}},
434 harpoon'/.code={\pgfsetarrowsend{tikzcd right to}},
435 two heads/.code={\pgfsetarrowsend{tikzcd double to}},
436 tail/.code={\pgfsetarrowsstart{tikzcd to reversed}},
437 rightarrow/.code={\pgfsetarrows{tikzcd cap-tikzcd to}},
438 Rightarrow/.code={\tikzcdset{double line}\pgfsetarrows{tikzcd implies cap-tikzcd implies}},
439 leftarrow/.code={\pgfsetarrows{tikzcd to-tikzcd cap}},
440 Leftarrow/.code={\tikzcdset{double line}\pgfsetarrows{tikzcd implies-tikzcd implies cap}},
441 leftrightarrow/.code={\pgfsetarrows{tikzcd to-tikzcd to}},
442 Leftrightarrow/.code={\tikzcdset{double line}\pgfsetarrows{tikzcd implies-tikzcd implies}},
443 mapsto/.code={\pgfsetarrows{tikzcd bar-tikzcd to}},
444 mapsfrom/.code={\pgfsetarrows{tikzcd to-tikzcd bar}},
445 Mapsto/.code={\tikzcdset{double line}\pgfsetarrows{tikzcd implies bar-tikzcd implies}},
446 Mapsfrom/.code={\tikzcdset{double line}\pgfsetarrows{tikzcd implies-tikzcd implies bar}},
447 hookrightarrow/.code={\pgfsetarrows{tikzcd right hook-tikzcd to}},
448 hookleftarrow/.code={\pgfsetarrows{tikzcd to-tikzcd left hook}},
449 rightharpoonup/.code={\pgfsetarrows{tikzcd cap-tikzcd left to}},
450 rightharpoondown/.code={\pgfsetarrows{tikzcd cap-tikzcd right to}},
451 leftharpoonup/.code={\pgfsetarrows{tikzcd right to-tikzcd cap}},
452 leftharpoondown/.code={\pgfsetarrows{tikzcd left to-tikzcd cap}},
453 rightarrowtail/.code={\pgfsetarrows{tikzcd to reversed-tikzcd to}},
454 leftarrowtail/.code={\pgfsetarrows{tikzcd to-tikzcd to reversed}},
455 twoheadrightarrow/.code={\pgfsetarrows{tikzcd cap-tikzcd double to}},
456 twoheadleftarrow/.code={\pgfsetarrows{tikzcd double to-tikzcd cap}},
457 no head/.code={\pgfsetarrowsend{tikzcd cap}},
458 dash/.code={\pgfsetarrows{tikzcd cap-tikzcd cap}},
459 dashrightarrow/.code={\tikzcdset{rightarrow,dashed}},
460 dashleftarrow/.code={\tikzcdset{leftarrow,dashed}},
461 equal/.code={\tikzcdset{double line}\pgfsetarrows{tikzcd implies cap-tikzcd implies cap}},
462 equals/.code={\tikzcdset{equal}},
463 rightsquigarrow/.code={\tikzcdset{rightarrow,squiggly}},
464 leftsquigarrow/.code={\tikzcdset{leftarrow,squiggly}},
465 leftrightsquigarrow/.code={\tikzcdset{leftrightarrow,squiggly}},
466 squiggly/.code={%
467 \pgfutil@ifundefined{tikz@[email protected]@loaded}%
468 {\pgfutil@packageerror{tikz-cd}{You need to say %
469 \string\usetikzlibrary{decorations.pathmorphing} to use squiggly arrows}{}}{}%
470 \pgfkeysalso{
471 /tikz/decorate,
472 /tikz/decoration={
473 zigzag,
474 segment length=9.25\pgflinewidth,
475 amplitude=1.9\pgflinewidth,
476 post=lineto, post length=6\pgflinewidth,
477 pre=lineto, pre length=6\pgflinewidth,
478 #1}}}}
479
480 % The `Latin Modern' arrow style
481 \pgfkeysdef{/tikz/commutative diagrams/arrow style/Latin Modern}{%
482 \tikzcdset{
483 tikzcd bar/.tip={Bar[width=+0pt 12 .992,line cap=round]},
484 tikzcd left hook/.tip={Hooks[width=+0pt 15,length=+0pt 4.2,arc=190,harpoon,line cap=round]}}}
485
486 % The `tikz' arrow style
487 \pgfkeysdef{/tikz/commutative diagrams/arrow style/tikz}{%
488 \tikzcdset{
489 tikzcd to/.tip={>},
490 tikzcd bar/.tip={Bar[width=+3pt 4 0.9]},
491 tikzcd left hook/.tip={Hooks[harpoon]},
492 tikzcd double to/.tip={tikzcd to[]tikzcd to}}}
493
494 % The `math font' arrow style
495 %
496 % If your font does not define the command \mapsfrom, do so by saying
497 % \def\mapsfrom{\pgfpicture\pgfsetbaseline{+0pt}\pgftransformxscale{-1}\pgftext[base]{$\mapsto$}\endpgfpicture}
498 %
499 % The method used to guess the correct value of `double distance'
500 % inside the `double line' style is not robust at all. If it fails,
501 % set
502 % \tikzcdset{double line/.append style={double distance=2*rule_thickness}}
503 % and find the correct value for `double distance' by trial and error
504 % (or measure the distance between the \Rightarrow stems in a font
505 % editor).
506 %
507 \pgfkeysdef{/tikz/commutative diagrams/arrow style/math font}{%
508 \tikzcdset{
509 tikzcd to/.tip={Glyph[glyph math command=rightarrow]},
510 tikzcd cap/.tip={Glyph[glyph math command=leftarrow]},
511 tikzcd to reversed/.tip={Glyph[glyph math command=leftarrowtail]},
512 tikzcd bar/.tip={Glyph[glyph math command=mapsfrom]},
513 tikzcd left hook/.tip={Glyph[glyph math command=hookleftarrow]},
514 tikzcd right hook/.tip={Glyph[glyph math command=hookleftarrow, swap]},
515 tikzcd implies/.tip={Glyph[glyph math command=Rightarrow, glyph length=1.2ex]},
516 tikzcd implies cap/.tip={Glyph[glyph math command=Leftarrow]},
517 tikzcd implies bar/.tip={Glyph[glyph math command=Mapsfrom]},
518 tikzcd double to/.tip={Glyph[glyph math command=twoheadrightarrow, glyph length=1.4ex]},
519 tikzcd left to/.tip={Glyph[glyph math command=rightharpoonup]},
520 tikzcd right to/.tip={Glyph[glyph math command=rightharpoonup,swap]},
521 double line/.append code={\tikzset{double distance={2*(height("$=$")-axis_height-rule_thickness)}}},
522 dashed/.code={\tikzset{dash pattern=on 0.8ex off 0.4ex, dash phase=0.8ex}},
523 squiggly/.default={pre length=1ex, post length=1ex}}}
524
525 % Default settings
526 \tikzcdset{
527 every arrow/.style={
528 /tikz/draw,
529 /tikz/line width=rule_thickness,
530 /tikz/commutative diagrams/rightarrow},
531 every label/.style={
532 /tikz/auto,
533 /tikz/font=\everymath\expandafter{\the\everymath\scriptstyle},
534 /tikz/inner sep=+0.5ex},
535 every cell/.style={
536 /tikz/shape={asymmetrical rectangle},
537 /tikz/inner xsep=+1ex,
538 /tikz/inner ysep=+0.85ex},
539 every matrix/.style={/tikz/inner sep=+0pt},
540 every diagram/.style={
541 /tikz/commutative diagrams/row sep=normal,
542 /tikz/commutative diagrams/column sep=normal,
543 /tikz/baseline=+0pt},
544 1-row diagram/.style={/tikz/baseline/.expanded=(\tikzcdmatrixname.base)},
545 math mode=true,
546 center yshift/.initial=axis_height,
547 row sep/huge/.initial=+3.6em,
548 row sep/large/.initial=+2.7em,
549 row sep/normal/.initial=+1.8em,
550 row sep/scriptsize/.initial=+1.35em,
551 row sep/small/.initial=+0.9em,
552 row sep/tiny/.initial=+0.45em,
553 column sep/huge/.initial=+4.8em,
554 column sep/large/.initial=+3.6em,
555 column sep/normal/.initial=+2.4em,
556 column sep/scriptsize/.initial=+1.8em,
557 column sep/small/.initial=+1.2em,
558 column sep/tiny/.initial=+0.6em,
559 crossing over clearance/.initial=+1.5ex,
560 shift left/.default=+0.56ex,
561 shift right/.default=1,
562 background color/.initial=white}
563
564 % ConTeXt-specific stuff
565 \pgfutil@IfUndefined{starttikzpicture}{}{%
566 \def\starttikzcd{\tikzcd}
567 \def\stoptikzcd{\endtikzcd}
568 \tikzcdset{
569 every matrix/.append code={%
570 \def\NC{\pgfmatrixnextcell}%
571 \def\NR{\pgfmatrixendrow}}}
572 }
573
574 \endinput