-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtikzcdintertext.tex
51 lines (39 loc) · 1.96 KB
/
tikzcdintertext.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
\RequirePackage{tikz-cd}
\RequirePackage{etoolbox}
\usetikzlibrary{calc}
\edef\mytikzcdrestoreat{\catcode`@=\the\catcode`@\let\noexpand\mytikzcdrestoreat\noexpand\undefined}
\makeatletter
\newbox\mytikzcd@trialbox
\patchcmd\tikzcd@{#1]}{remember picture,#1]\let\intertext\mytikzcd@intertext}{}{\errorfailedtopatch}
\def\mytikzcd@addtosavedpaths#1{\xdef\tikzcd@savedpaths{\unexpanded\expandafter{\tikzcd@savedpaths}#1}}
\def\mytikzcd@intertext{
\@ifnextchar[{\mytikzcd@intertext@}{\mytikzcd@intertext@[0pt]}
}
\def\mytikzcd@intertext@[#1]#2{
\setbox\mytikzcd@trialbox=\vbox{\hsize\textwidth #2}
\expandafter\\\expandafter[\the\dimexpr\ht\mytikzcd@trialbox+\dp\mytikzcd@trialbox+#1]
\edef\mytikzcd@lmargin{\if@mparswitch\ifodd\thepage\space \Gm@lmargin\else \Gm@rmargin\fi\else \Gm@lmargin\fi}
\@xp\mytikzcd@findcolumn\@xp{\tikzcd@savedpaths}{1}
\mytikzcd@addtosavedpaths{\unexpanded{\path[overlay] let \p1=(current page.west), \p2 =} (\noexpand\tikzcdmatrixname-\the\numexpr\pgfmatrixcurrentrow-1\relax-\mytikzcd@column), \noexpand\p3 = (\noexpand\tikzcdmatrixname-\the\pgfmatrixcurrentrow-1) in
node[anchor=west,xshift=\mytikzcd@lmargin-2pt] at \unexpanded{(\x1,0.5*\y2+0.5*\y3) {\parbox{\textwidth}{#2}};}
}
}
\def\mytikzcd@findcolumn#1#2{
\def\mytikzcd@targetrow{#2}
\expandafter\mytikzcd@findcolumn@\detokenize{#1\def\tikzcd@currentcolumn{x}\def\tikzcd@currentrow{6}}\@nil
}
\bgroup\lccode`\(=`\{\lccode`\)=`\}\lowercase{\egroup
\edef\mytikzcd@findcolumn@argspec{\unexpanded{#1}\detokenize{\def\tikzcd@currentcolumn}\unexpanded{(#2)}\detokenize{\def\tikzcd@currentrow}\unexpanded{(#3)}}
}
\@xp\def\@xp\mytikzcd@findcolumn@\mytikzcd@findcolumn@argspec{
\expandafter\ifx\detokenize{x}#2
\ifnum\mytikzcd@row<\the\numexpr\pgfmatrixcurrentrow-1\relax\def\mytikzcd@column{1}\fi
\@xp\@gobbletonil
\else
\def\mytikzcd@column{#2}
\def\mytikzcd@row{#3}
\@xp\mytikzcd@findcolumn@
\fi
}
\def\@gobbletonil#1\@nil{}
\mytikzcdrestoreat