# whizzy-tikz / whizzy-tikz.sty

  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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148  % TODO: resize the whole picture to scale it -- easyish % TODO: use a name/label somehow % TODO: make it work for lines, rectangles etc. %{{{ old \advinode code \tikzset{ % This is the workhorse style advi/.style={ % We do the advi stuff after the node has been placed so that we can % get access to its width and height. What this means is that our % node ends up being equivalent to % \node[at=(x-value,y-value)] {node text} [advi/set advi={x=,y=}]; append after command={[advi/set advi={#1}]}, % As the advi boxes are specified by lower-left corner, we anchor our % node at the lower-left so that the given coordinate is the node % coordinate anchor=south west, % The parameter #1 is of the form "x=,y=". We trick % TikZ into taking that as defining some keys in the "/tikz/advi" % directory advi/.cd, #1, % We use the values that have just been set, namely /tikz/advi/x % and /tikz/advi/y to specify the location of the node via the % at key. We need to give the full path as we're currently in at % /tikz/advi /tikz/at={(\pgfkeysvalueof{/tikz/advi/x},\pgfkeysvalueof{/tikz/advi/y})} }, % This next bit ensures that the /tikz/advi/x and y keys can be % used to store values. advi/.cd, x/.initial=0, y/.initial=0, % This is the part that specifies the boxes in the dvi. This is % actually executed after the node has been processed set advi/.code={ \pgfpointxy{1}{1} \advixunit \pgf@x \adviyunit \pgf@y % As the node has been processed, we can get its width and height by % looking at a couple of anchors. \tikz@scan@one@point\pgfutil@firstofone(\tikzlastnode.north east) \pgf@xa=\pgf@x \pgf@ya=\pgf@y \tikz@scan@one@point\pgfutil@firstofone(\tikzlastnode.south west) % We adjust the values to be multiples of ems as that's the default % for advi/whizzytex \pgfmathsetmacro{\advi@node@w}{(\pgf@xa - \pgf@x)/\the\advi@edit@xunit}% \pgfmathsetmacro{\advi@node@h}{(\pgf@ya - \pgf@y)/\the\advi@edit@yunit}% \pgfmathsetmacro{\advi@node@x}{(\pgf@x)/\the\advi@edit@xunit}% \pgfmathsetmacro{\advi@node@y}{(\pgf@y)/\the\advi@edit@yunit}% \tikz@scan@one@point\pgfutil@firstofone(\tikzlastnode) \pgfmathsetmacro{\advi@node@xm}{(\pgf@x)/\the\advi@edit@xunit}% \pgfmathsetmacro{\advi@node@ym}{(\pgf@y)/\the\advi@edit@yunit}% % Finally, we call the \adviedit command % \advi@special % {edit\space % comm="\string\advinode"\space % name="really long name:\advi@node@x:\advi@node@y"\space % line=\the\inputlineno\space % file=\jobname\space % xunit=1em\space % yunit=1em\space % x=\advi@node@x\space % y=\advi@node@y\space % w=\advi@node@w\space % h=\advi@node@h\space % d=0.0000\space % } % \adviedit{comm=\advinode,w=\advi@node@w,h=\advi@node@h,x=\advi@node@x,y=\advi@node@y}{} \adviedit{comm=\advinode,w=\advi@node@w,h=\advi@node@h,#1}{} } } % This is the command that whizzytex will look for. \newcommand{\advinode}[1]{% \node[advi={#1}] } %}}} % Monkey patch TikZ to keep track of the initial input, so that we can have an exact match. % Original code is found in: % /usr/local/texlive/2011/texmf-dist/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex \def\tikz@scan@no@calculator#1(#2){% \edef\tikz@temp{(#2)}% \global\def\my@node@def{#2}% \expandafter\tikz@@scan@@no@calculator\expandafter#1\tikz@temp% } \tikzset{ % This is the workhorse style ADVI/.style={ % We do the advi stuff after the node has been placed so that we can % get access to its width and height. append after command={[ADVI/set advi={#1}]}, ADVI/.cd, % For some reason setting the values of type, precision, and duplicate % here don't work. But I think they should... #1, }, % This next bit ensures that the /tikz/advi/type and precision keys can be % used to store values. ADVI/.cd, type/.initial=node, precision/.initial=4, duplicate/.initial=no, % This is the part that specifies the boxes in the dvi. This is % actually executed after the node has been processed set advi/.code={ \let\this@nodes@def\my@node@def \pgfpointxy{1}{1} \advixunit \pgf@x \adviyunit \pgf@y % As the node has been processed, we can get its width and height by % looking at a couple of anchors. \tikz@scan@one@point\pgfutil@firstofone(\tikzlastnode.north east) \pgf@xa=\pgf@x \pgf@ya=\pgf@y \tikz@scan@one@point\pgfutil@firstofone(\tikzlastnode.south west) % We adjust the values to be multiples of ems as that's the default % for advi/whizzytex \pgfmathsetmacro{\advi@node@w}{(\pgf@xa - \pgf@x)/\the\advi@edit@xunit}% \pgfmathsetmacro{\advi@node@h}{(\pgf@ya - \pgf@y)/\the\advi@edit@yunit}% \pgfmathsetmacro{\advi@node@x}{(\pgf@x)/\the\advi@edit@xunit}% \pgfmathsetmacro{\advi@node@y}{(\pgf@y)/\the\advi@edit@yunit}% % \tikz@scan@one@point\pgfutil@firstofone(\tikzlastnode) \pgfmathsetmacro{\advi@node@xm}{(\pgf@x)/\the\advi@edit@xunit}% \pgfmathsetmacro{\advi@node@ym}{(\pgf@y)/\the\advi@edit@yunit}% % TODO: Why do I have to do this? Why didn't it take before? \tikzset{/tikz/ADVI/.cd,#1} % Finally, we call the \adviedit command \adviedit[tikz:\pgfkeysvalueof{/tikz/ADVI/type}:% \pgfkeysvalueof{/tikz/ADVI/precision}:\pgfkeysvalueof{/tikz/ADVI/duplicate}% @\this@nodes@def @\advi@node@x @\advi@node@y @\advi@node@xm @\advi@node@ym]% {comm=\advinode,w=\advi@node@w,h=\advi@node@h,x=\advi@node@x,y=\advi@node@y,line=\the\inputlineno}{} } } % Local Variables: % TeX-master: "test" % End: