| 1 |
% Copyright 2019 by Till Tantau |
| 2 |
% |
| 3 |
% This file may be distributed and/or modified |
| 4 |
% |
| 5 |
% 1. under the LaTeX Project Public License and/or |
| 6 |
% 2. under the GNU Public License. |
| 7 |
% |
| 8 |
% See the file doc/generic/pgf/licenses/LICENSE for more details. |
| 9 |
|
| 10 |
\ProvidesFileRCS{pgfmodulematrix.code.tex} |
| 11 |
|
| 12 |
\usepgfmodule{shapes}% |
| 13 |
|
| 14 |
\newif\ifpgfmatrix |
| 15 |
\newif\ifpgf@matrix@correct@call |
| 16 |
|
| 17 |
\newif\ifpgf@matrix@fixed |
| 18 |
|
| 19 |
\newcount\pgfmatrixcurrentrow |
| 20 |
|
| 21 |
\newcount\pgfmatrixcurrentcolumn |
| 22 |
\newcount\pgf@matrix@numberofcolumns |
| 23 |
|
| 24 |
\let\pgf@matrix@cell=\pgfnodeparttextbox % alias |
| 25 |
\let\pgf@matrix@box=\pgf@matrix@cell % alias |
| 26 |
|
| 27 |
\long\def\pgfmatrixbeforeassemblenode#1{% |
| 28 |
\long\def\pgf@matrix@before@assemnble@node{#1}} |
| 29 |
\pgfmatrixbeforeassemblenode{} |
| 30 |
|
| 31 |
% Sets the default row or column sep |
| 32 |
% |
| 33 |
% #1 = default row or column sep list |
| 34 |
% |
| 35 |
% Description: |
| 36 |
% |
| 37 |
% Sets the macro \pgfmatrixrowsep or \pgfmatrixcolumnsep to #1. |
| 38 |
% |
| 39 |
% Example: |
| 40 |
% |
| 41 |
% \pgfsetmatrixrowsep{5pt} |
| 42 |
|
| 43 |
\def\pgfsetmatrixrowsep#1{\def\pgfmatrixrowsep{#1}}% |
| 44 |
\def\pgfsetmatrixcolumnsep#1{\def\pgfmatrixcolumnsep{#1}}% |
| 45 |
|
| 46 |
\def\pgfmatrixrowsep{0pt}% |
| 47 |
\def\pgfmatrixcolumnsep{0pt}% |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
% The pgfmatrix command creates a node that contains a matrix. Like |
| 52 |
% the \pgfnode command, it is to be used inside a pgfpicture |
| 53 |
% environment. |
| 54 |
% |
| 55 |
% #1 = shape type |
| 56 |
% #2 = anchor |
| 57 |
% #3 = name for later reference |
| 58 |
% #4 = path usage command |
| 59 |
% #5 = inner shift |
| 60 |
% #6 = startup code |
| 61 |
% #7 = the matrix code (may contain verbatim stuff) |
| 62 |
% |
| 63 |
% Description: |
| 64 |
% |
| 65 |
% This command creates a node that contains a matrix. For |
| 66 |
% each cell of the matrix, drawing commands may be given. These |
| 67 |
% commands will create a cell picture and a bounding box is computed |
| 68 |
% for each cell picture. The cell picture is then placed inside the |
| 69 |
% cell. The position inside the cell is computed according to the |
| 70 |
% following rules: |
| 71 |
% |
| 72 |
% 1. In each column, the origins of the cell pictures are all on a |
| 73 |
% vertical line. |
| 74 |
% 2. In each row, the origins of the cell pictures are all on a |
| 75 |
% horizontal line. |
| 76 |
% 3. All cells in the same row have the same height and depth. |
| 77 |
% 4. All cells in the same column have the same width. |
| 78 |
% 5. The size of cells are chosen minimal such that the boxes fit into |
| 79 |
% the cells and still meet the above requirement. |
| 80 |
% |
| 81 |
% Next, the whole resulting matrix, which is given as #7, is placed |
| 82 |
% inside a node whose name is given as #3, whose shape is #1, and |
| 83 |
% whose anchor is #2. This means that the resulting node is shifted |
| 84 |
% such that the given anchor lies at the origin. Then, as for a normal |
| 85 |
% node, the #4 path usage command is used for the node. |
| 86 |
% |
| 87 |
% The parameter #5 is an additional negative shift for the node. Normally, such |
| 88 |
% a shift could be given beforehand (that is, the shift could be |
| 89 |
% preapplied to the current transformation matrix). However, when #5 |
| 90 |
% is evaluated, you can refer to temporary positions of nodes inside |
| 91 |
% the matrix. In detail, the following happens: When the matrix has |
| 92 |
% been typeset, all nodes in the matrix temporarily get assigned their |
| 93 |
% positions in the matrix box. The origin of this coordinate system is |
| 94 |
% at the left baseline end of the matrix box, which corresponds to the |
| 95 |
% text anchor. The position #5 is then interpreted inside this |
| 96 |
% coordinate system and then used for shifting. |
| 97 |
% |
| 98 |
% The idea behind using the parameter #5 is the following: If you |
| 99 |
% specify "text" as anchor #2 and specify \pgfpointanchor{inner |
| 100 |
% node}{some anchor} for parameter #5, where inner node is a node that |
| 101 |
% is created in the matrix, then the whole matrix will be shifted such |
| 102 |
% that inner node.some anchor lies at the origin of the whole picture. |
| 103 |
% |
| 104 |
% At the beginning and at the end of each cell, the macros |
| 105 |
% \pgfmatrixbegincode and \pgfmatrixendcode are called. Inside these |
| 106 |
% macros you can use \pgfmatrixcurrentcolumn and \pgfmatrixcurrentrow |
| 107 |
% to access the current row and column. |
| 108 |
% |
| 109 |
% Before each column except for the first, an extra space given by the |
| 110 |
% macro \pgfmatrixcolumnsep is added. Additionally, an extra space |
| 111 |
% given by the optional argument of the \pgfmatrixnextcell commands in |
| 112 |
% the first line are added, which may vary between columns. Between |
| 113 |
% rows, an extra space given by the macro \pgfmatrixrowsep is |
| 114 |
% added. You can also change this value for each row by using a \gdef. |
| 115 |
% |
| 116 |
% |
| 117 |
% Lines are ended using the command \pgfmatrixendrow. The command \\ |
| 118 |
% is \let to be the same, but \\ is sometimes overridden by, say, |
| 119 |
% minipage, so it's good to have \pgfmatrixendrow as a "fallback". |
| 120 |
% |
| 121 |
% Inside the matrix, \\ must be used to end every line ***including |
| 122 |
% the last***. You can pass an optional parameter to \\ as in \\[2pt] |
| 123 |
% to give an additional space after this particular line. |
| 124 |
% |
| 125 |
% The usage of \\ at the end of the matrix is important since this |
| 126 |
% command is used to find the end of the matrix. What happens is that |
| 127 |
% \\ followed by a closing brace ends the matrix. |
| 128 |
% |
| 129 |
% Inside the matrix, you must use \pgfmatrixnextcell to separate |
| 130 |
% columns. The reason is that two columns are used internally for |
| 131 |
% every single column shown. The macro \pgfmatrixnextcell is yields |
| 132 |
% (more or less) two && (and some further trickery). |
| 133 |
% |
| 134 |
% The parameter #6 is executed at the beginning of the matrix |
| 135 |
% group. It is inside the protecting group of the matrix, but outside |
| 136 |
% the matrix itself. It can be used for different purposes: 1) It can be |
| 137 |
% used to simplify the next cell macro. 2) It can be used to issue an |
| 138 |
% \aftergroup command. 3) It can be used to setup local settings. For |
| 139 |
% example, by setting #6 to \let\&=\pgfmatrixnextcell you can use \& |
| 140 |
% instead of \pgfmatrixnextcell. You can also set the catcode of & to |
| 141 |
% active. |
| 142 |
% |
| 143 |
% |
| 144 |
% Example: |
| 145 |
% |
| 146 |
% \begin{tikzpicture} |
| 147 |
% |
| 148 |
% \draw (0,0) circle (1mm); % b.north will lie on the center of this circle |
| 149 |
% |
| 150 |
% \pgfmatrix{rectangle}{text}{mymatrix}{\pgfusepath{}}{\pgfpointanchor{b}{north}}{\let\&=\pgfmatrixnextcell} |
| 151 |
% { |
| 152 |
% \draw (0,0) circle (1cm); \& \node (a) [draw] {Hallo}; \\ |
| 153 |
% \node (b) [draw] {Welt}; \& \draw (0,0) circle (5mm); \\ |
| 154 |
% } |
| 155 |
% |
| 156 |
% \draw [->] (a) -- (b); |
| 157 |
% |
| 158 |
% \end{tikzpicture} |
| 159 |
|
| 160 |
\def\pgfmatrix#1#2#3#4#5#6{% |
| 161 |
\ifpgfmatrix% |
| 162 |
\pgferror{You cannot nest pgfmatrix environments, yet} |
| 163 |
\fi% |
| 164 |
\bgroup% |
| 165 |
\everycr{}% |
| 166 |
#6% |
| 167 |
\def\pgf@matrix@par@shape{#1}% |
| 168 |
\def\pgf@matrix@par@anchor{#2}% |
| 169 |
\def\pgf@matrix@par@name{#3}% |
| 170 |
\def\pgf@matrix@par@usage{#4}% |
| 171 |
\def\pgf@matrix@par@shift{#5}% |
| 172 |
% the matrix must have a name: |
| 173 |
\ifx\pgf@matrix@par@name\pgfutil@empty% |
| 174 |
\def\pgf@matrix@par@name{pgf@matrix@internal}% |
| 175 |
\fi% |
| 176 |
\pgfmatrixcurrentrow=0\relax% |
| 177 |
\pgfmatrixcurrentcolumn=0\relax% |
| 178 |
\pgf@matrix@numberofcolumns=0\relax% |
| 179 |
\let\\=\pgfmatrixendrow% |
| 180 |
\tabskip=0pt% |
| 181 |
\offinterlineskip% |
| 182 |
\pgfmatrixtrue% |
| 183 |
\let\pgf@matrix@node@list=\pgfutil@empty% |
| 184 |
\expandafter\let\csname pgf@matrix@column@finish@1\endcsname=\pgfutil@empty% |
| 185 |
\let\pgf@matrix@row@finish=\pgfutil@empty% |
| 186 |
% |
| 187 |
% Get rid of bgroup |
| 188 |
% |
| 189 |
\afterassignment\pgf@matrix@cont\let\pgf@next=% |
| 190 |
}% |
| 191 |
\def\pgf@matrix@cont{% |
| 192 |
\setbox\pgf@matrix@box=\hbox\bgroup\vbox\bgroup% |
| 193 |
\halign\bgroup% |
| 194 |
\pgf@matrix@init@row% |
| 195 |
\pgf@matrix@step@column% |
| 196 |
{% |
| 197 |
\pgf@matrix@startcell% |
| 198 |
##% |
| 199 |
\pgf@matrix@endcell% |
| 200 |
}% |
| 201 |
&% |
| 202 |
##\pgf@matrix@padding&&% |
| 203 |
\pgf@matrix@step@column% |
| 204 |
{% |
| 205 |
\pgf@matrix@startcell% |
| 206 |
##% |
| 207 |
\pgf@matrix@endcell% |
| 208 |
}&% |
| 209 |
##\pgf@matrix@padding% |
| 210 |
\cr% |
| 211 |
}% |
| 212 |
|
| 213 |
\def\pgf@end@matrix{% |
| 214 |
\egroup\egroup% |
| 215 |
\egroup% |
| 216 |
% |
| 217 |
% Inject custom tokens before assembling the node holding the matrix. Can |
| 218 |
% be used to apply additional settings. |
| 219 |
% |
| 220 |
\pgf@matrix@before@assemnble@node |
| 221 |
% |
| 222 |
% If there are named nodes, we must adjust their coordinates. |
| 223 |
% |
| 224 |
\ifx\pgf@matrix@node@list\pgfutil@empty% |
| 225 |
\else% |
| 226 |
% Ok, this means we got a lot of work to do... |
| 227 |
\pgf@matrix@compute@origin% |
| 228 |
\pgf@matrix@shift@nodes@initial% |
| 229 |
\fi% |
| 230 |
% |
| 231 |
% Compute additional shift |
| 232 |
% |
| 233 |
\pgftransformresetnontranslations% |
| 234 |
\pgftransformshift{\pgf@process{\pgftransformreset\pgf@matrix@par@shift\pgf@x=-\pgf@x\pgf@y=-\pgf@y}}% |
| 235 |
% |
| 236 |
% Create node |
| 237 |
% |
| 238 |
\pgfmultipartnode{\pgf@matrix@par@shape}{\pgf@matrix@par@anchor}{\pgf@matrix@par@name}{\pgf@matrix@par@usage}% |
| 239 |
% |
| 240 |
% If there are named nodes, we must adjust their coordinates, again. |
| 241 |
% |
| 242 |
\ifx\pgf@matrix@node@list\pgfutil@empty% |
| 243 |
\else% |
| 244 |
{% |
| 245 |
\pgftransformreset% |
| 246 |
\pgf@process{\pgfpointanchor{\pgf@matrix@par@name}{text}}% |
| 247 |
\xdef\pgf@matrix@offset{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}% |
| 248 |
\pgf@matrix@shift@nodes@secondary{\pgf@matrix@offset}% |
| 249 |
}% |
| 250 |
\fi% |
| 251 |
}% |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
% Ending a cell |
| 257 |
% |
| 258 |
% #1 = (optional) spacing between previous and next column. This |
| 259 |
% parameter only has an effect in the first row. |
| 260 |
% |
| 261 |
% Description: |
| 262 |
% |
| 263 |
% This command ends a cell of a matrix. |
| 264 |
% |
| 265 |
% Example: |
| 266 |
% |
| 267 |
% \pgfmatrix{rectangle}{text}{mymatrix}{\pgfusepath{}}{\pgfpointanchor{b}{north}}{} |
| 268 |
% { |
| 269 |
% \draw (0,0) circle (1cm); \pgfmatrixnextcell[1cm] \node (a) [draw] {Hallo}; \\ |
| 270 |
% \node (b) [draw] {Welt}; \pgfmatrixnextcell \draw (0,0) circle (5mm); \\ |
| 271 |
% } |
| 272 |
|
| 273 |
\def\pgfmatrixnextcell{% |
| 274 |
% if the cell contains nothing, the following \let will be at the |
| 275 |
% beginning (macro expansion has stopped here since neither \omit |
| 276 |
% nor \span was found) |
| 277 |
\let\pgf@matrix@signal@cell@end=\pgf@matrix@signal@cell@end% |
| 278 |
\pgfutil@ifnextchar[{\pgf@matrix@cell@cont}{\pgf@matrix@cell@cont[0pt]}}%}% |
| 279 |
|
| 280 |
\def\pgf@matrix@cell@cont[#1]{% |
| 281 |
\xdef\pgf@matrix@last@nextcell@options{#1}% |
| 282 |
&\pgf@matrix@correct@calltrue&% |
| 283 |
}% |
| 284 |
|
| 285 |
|
| 286 |
\def\pgf@matrix@fixed@text{between origins}% |
| 287 |
\def\pgf@matrix@natural@text{between borders}% |
| 288 |
|
| 289 |
\def\pgf@matrix@addtolength#1#2{\edef\pgf@temp{#2}\expandafter\pgf@matrix@addtolength@\expandafter#1#2,\pgf@stop}% |
| 290 |
\def\pgf@matrix@addtolength@#1#2,#3\pgf@stop{% |
| 291 |
\pgfkeys@spdef\pgf@temp{#2}% |
| 292 |
\ifx\pgf@temp\pgfutil@empty% |
| 293 |
\else% |
| 294 |
\ifx\pgf@temp\pgf@matrix@fixed@text% |
| 295 |
\global\pgf@matrix@fixedtrue% |
| 296 |
\else% |
| 297 |
\ifx\pgf@temp\pgf@matrix@natural@text% |
| 298 |
\global\pgf@matrix@fixedfalse% |
| 299 |
\else% |
| 300 |
\pgfmathaddtolength{#1}{#2}% |
| 301 |
\fi% |
| 302 |
\fi% |
| 303 |
\fi% |
| 304 |
\def\pgf@temp{#3}% |
| 305 |
\ifx\pgf@temp\pgfutil@empty% |
| 306 |
\else% |
| 307 |
\pgf@matrix@addtolength@#1#3\pgf@stop% |
| 308 |
\fi% |
| 309 |
}% |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
% Init a line |
| 314 |
|
| 315 |
\def\pgf@matrix@init@row{% |
| 316 |
\relax% |
| 317 |
\global\advance\pgfmatrixcurrentrow by 1\relax% |
| 318 |
\global\pgfmatrixcurrentcolumn=0\relax% |
| 319 |
\expandafter\gdef\csname pgf@matrix@maxy\the\pgfmatrixcurrentrow\endcsname{0pt}% |
| 320 |
\expandafter\gdef\csname pgf@matrix@miny\the\pgfmatrixcurrentrow\endcsname{0pt}% |
| 321 |
}% |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
% Step the row column number |
| 326 |
|
| 327 |
\def\pgf@matrix@step@column{% |
| 328 |
\relax% |
| 329 |
\global\advance\pgfmatrixcurrentcolumn by1\relax% |
| 330 |
}% |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
% Start a cell |
| 335 |
|
| 336 |
\def\pgf@matrix@startcell{% |
| 337 |
% |
| 338 |
% Step 1: Init the list of nodes for this cell |
| 339 |
% |
| 340 |
\let\pgf@nodecallback=\pgf@matrix@nodecallback% |
| 341 |
% |
| 342 |
% Step 2: Setup the bounding box |
| 343 |
% |
| 344 |
\pgfinterruptboundingbox% |
| 345 |
% |
| 346 |
% Step 3: Reset the transformation matrix |
| 347 |
% |
| 348 |
\pgftransformreset% |
| 349 |
% |
| 350 |
% Step 4: Collect everything in a cell box |
| 351 |
% |
| 352 |
\setbox\pgf@matrix@cell=\hbox\bgroup\bgroup% |
| 353 |
% make sure that cell pictures are not affected if matrices have |
| 354 |
% 'overlay' option on: |
| 355 |
\pgf@relevantforpicturesizetrue |
| 356 |
\pgfsys@beginpicture% |
| 357 |
\normalbaselines% |
| 358 |
% Find out whether the cell is empty: |
| 359 |
\pgfutil@ifnextchar\let% |
| 360 |
{% ok, candidate, check following symbol |
| 361 |
\afterassignment\pgf@matrix@empty@check\let\pgf@matrix@temp=% get rid of \let |
| 362 |
}% |
| 363 |
{% no, not empty |
| 364 |
\pgf@matrix@empty@cell@false% |
| 365 |
\pgfmatrixbegincode% |
| 366 |
}% |
| 367 |
}% |
| 368 |
|
| 369 |
\def\pgf@matrix@empty@check{\futurelet\pgf@matrix@check@token\pgf@matrix@empty@check@cont}% |
| 370 |
\def\pgf@matrix@empty@check@cont{% |
| 371 |
\ifx\pgf@matrix@check@token\pgf@matrix@signal@cell@end% |
| 372 |
\pgf@matrix@empty@cell@true% |
| 373 |
\expandafter% |
| 374 |
\pgfmatrixemptycode% |
| 375 |
\expandafter% |
| 376 |
\let% reinserted |
| 377 |
\else% |
| 378 |
\pgf@matrix@empty@cell@false% |
| 379 |
\expandafter% |
| 380 |
\pgfmatrixbegincode% |
| 381 |
\expandafter |
| 382 |
\let% reinserted |
| 383 |
\fi% |
| 384 |
}% |
| 385 |
|
| 386 |
\newif\ifpgf@matrix@empty@cell@ |
| 387 |
|
| 388 |
|
| 389 |
% End a cell |
| 390 |
|
| 391 |
\def\pgf@matrix@endcell{% |
| 392 |
\ifpgf@matrix@empty@cell@% |
| 393 |
\else% |
| 394 |
\expandafter\expandafter\expandafter\pgfmatrixendcode% |
| 395 |
\expandafter\ifpgf@matrix@last@cell@in@row\expandafter\pgf@matrix@last@cell@in@rowtrue\expandafter\fi% |
| 396 |
\fi% |
| 397 |
\pgfsys@endpicture% |
| 398 |
\ifnum\pgfmatrixcurrentcolumn<\pgf@matrix@numberofcolumns% |
| 399 |
\else% |
| 400 |
\ifpgf@matrix@last@cell@in@row\else% |
| 401 |
{% |
| 402 |
\global\pgf@matrix@fixedfalse% |
| 403 |
\pgf@x=0pt% |
| 404 |
\pgf@matrix@addtolength{\pgf@x}{\pgfmatrixcolumnsep}% |
| 405 |
\pgf@matrix@addtolength{\pgf@x}{\pgf@matrix@last@nextcell@options}% |
| 406 |
\ifpgf@matrix@fixed% |
| 407 |
\expandafter\pgfutil@g@addto@macro\csname pgf@matrix@column@finish@\the\pgfmatrixcurrentcolumn\endcsname% |
| 408 |
{\global\pgf@picmaxx=0pt}% |
| 409 |
\fi% |
| 410 |
\advance\pgfmatrixcurrentcolumn by1\relax % only temporary for the following: |
| 411 |
\expandafter\xdef\csname pgf@matrix@column@sep@\the\pgfmatrixcurrentcolumn\endcsname{\the\pgf@x}% |
| 412 |
\ifpgf@matrix@fixed% |
| 413 |
\expandafter\gdef\csname pgf@matrix@column@finish@\the\pgfmatrixcurrentcolumn\endcsname{\global\pgf@picminx=0pt}% |
| 414 |
\else% |
| 415 |
\expandafter\global\expandafter\let\csname pgf@matrix@column@finish@\the\pgfmatrixcurrentcolumn\endcsname=\pgfutil@empty% |
| 416 |
\fi% |
| 417 |
}% |
| 418 |
\fi\fi% |
| 419 |
% Special case of the empty picture |
| 420 |
\ifdim\pgf@picmaxx=-16000pt\relax% |
| 421 |
\global\pgf@picmaxx=0pt\relax% |
| 422 |
\global\pgf@picminx=0pt\relax% |
| 423 |
\global\pgf@picmaxy=0pt\relax% |
| 424 |
\global\pgf@picminy=0pt\relax% |
| 425 |
\fi% |
| 426 |
\csname pgf@matrix@column@finish@\the\pgfmatrixcurrentcolumn\endcsname% |
| 427 |
\pgf@matrix@row@finish% |
| 428 |
\egroup\egroup% |
| 429 |
% |
| 430 |
% Step 5: Horizontal gap |
| 431 |
% |
| 432 |
\ifnum\pgfmatrixcurrentcolumn>1\relax% |
| 433 |
\pgf@y=\csname pgf@matrix@column@sep@\the\pgfmatrixcurrentcolumn\endcsname\relax% |
| 434 |
\advance\pgf@picminx by-\pgf@y% |
| 435 |
\fi% |
| 436 |
% |
| 437 |
% Step 6: Protocol and adjust height and depth |
| 438 |
% |
| 439 |
% Step 6.1: Protocol... |
| 440 |
% |
| 441 |
\ifdim\pgf@picmaxy>\csname pgf@matrix@maxy\the\pgfmatrixcurrentrow\endcsname% |
| 442 |
\expandafter\xdef\csname pgf@matrix@maxy\the\pgfmatrixcurrentrow\endcsname{\the\pgf@picmaxy}% |
| 443 |
\fi% |
| 444 |
\ifdim\pgf@picminy<\csname pgf@matrix@miny\the\pgfmatrixcurrentrow\endcsname% |
| 445 |
\expandafter\xdef\csname pgf@matrix@miny\the\pgfmatrixcurrentrow\endcsname{\the\pgf@picminy}% |
| 446 |
\fi% |
| 447 |
% |
| 448 |
% Step 6.2: and setup. |
| 449 |
% |
| 450 |
\ht\pgf@matrix@cell=\pgf@picmaxy% |
| 451 |
\dp\pgf@matrix@cell=-\pgf@picminy% |
| 452 |
% |
| 453 |
% Step 7: Protocol and adjust left and right width |
| 454 |
% |
| 455 |
% Step 7.1: Protocol... |
| 456 |
% |
| 457 |
\ifnum\pgfmatrixcurrentcolumn>\pgf@matrix@numberofcolumns\relax% |
| 458 |
\expandafter\xdef\csname pgf@matrix@maxx\the\pgfmatrixcurrentcolumn\endcsname{\the\pgf@picmaxx}% |
| 459 |
\expandafter\xdef\csname pgf@matrix@minx\the\pgfmatrixcurrentcolumn\endcsname{\the\pgf@picminx}% |
| 460 |
\global\pgf@matrix@numberofcolumns=\pgfmatrixcurrentcolumn\relax% |
| 461 |
\else% |
| 462 |
\ifdim\pgf@picmaxx>\csname pgf@matrix@maxx\the\pgfmatrixcurrentcolumn\endcsname% |
| 463 |
\expandafter\xdef\csname pgf@matrix@maxx\the\pgfmatrixcurrentcolumn\endcsname{\the\pgf@picmaxx}% |
| 464 |
\fi% |
| 465 |
\ifdim\pgf@picminx<\csname pgf@matrix@minx\the\pgfmatrixcurrentcolumn\endcsname% |
| 466 |
\expandafter\xdef\csname pgf@matrix@minx\the\pgfmatrixcurrentcolumn\endcsname{\the\pgf@picminx}% |
| 467 |
\fi% |
| 468 |
\fi% |
| 469 |
% |
| 470 |
% Step 7.2: and setup. |
| 471 |
% |
| 472 |
\xdef\pgf@matrix@paddingskip{\the\pgf@picmaxx}% |
| 473 |
% |
| 474 |
% Step 8: Put in the box now |
| 475 |
% |
| 476 |
\hfil\hskip-\pgf@picminx% |
| 477 |
\wd\pgf@matrix@cell=0pt% |
| 478 |
\box\pgf@matrix@cell% |
| 479 |
% |
| 480 |
% Step 9: End bounding box |
| 481 |
\endpgfinterruptboundingbox% |
| 482 |
}% |
| 483 |
|
| 484 |
% Default code for the start and end code |
| 485 |
\let\pgfmatrixbegincode=\relax |
| 486 |
\let\pgfmatrixendcode=\relax |
| 487 |
\let\pgfmatrixemptycode=\relax |
| 488 |
|
| 489 |
|
| 490 |
% The following callback is called for every node that is produced |
| 491 |
% inside a cell |
| 492 |
|
| 493 |
\def\pgf@matrix@nodecallback#1{% |
| 494 |
\def\pgf@temp{#1}% |
| 495 |
\ifx\pgf@temp\pgfutil@empty% |
| 496 |
\else% |
| 497 |
\xdef\pgf@matrix@node@list{\pgf@matrix@node@list,{#1}}% |
| 498 |
\expandafter\xdef\csname pgf@matrix@node@location@#1\endcsname{{\the\pgfmatrixcurrentrow}{\the\pgfmatrixcurrentcolumn}}% |
| 499 |
\fi% |
| 500 |
}% |
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
% Padding code |
| 505 |
|
| 506 |
\def\pgf@matrix@padding{% |
| 507 |
\ifpgf@matrix@correct@call% |
| 508 |
\else% |
| 509 |
\pgferror{Single ampersand used with wrong catcode}% |
| 510 |
\fi% |
| 511 |
\hskip\pgf@matrix@paddingskip\hfil% |
| 512 |
}% |
| 513 |
|
| 514 |
|
| 515 |
% Compute the real positions of the origins |
| 516 |
|
| 517 |
% We must now compute the real positions of the origins of all the |
| 518 |
% small pictures. To this end, we need to compute prefix sums. After |
| 519 |
% the procedure is done, the minx and the maxy will contain the origin |
| 520 |
% positions. |
| 521 |
|
| 522 |
\def\pgf@matrix@compute@origin{% |
| 523 |
% |
| 524 |
% Inverse prefix sum on the vertical positions |
| 525 |
% |
| 526 |
{% |
| 527 |
\ifnum\pgfmatrixcurrentrow>0\relax% |
| 528 |
\expandafter\gdef\csname pgf@matrix@miny\the\pgfmatrixcurrentrow\endcsname{0pt}% |
| 529 |
\fi |
| 530 |
\c@pgf@counta=\pgfmatrixcurrentrow\relax% |
| 531 |
\loop% |
| 532 |
\ifnum\c@pgf@counta>1\relax% |
| 533 |
\pgf@y=\csname pgf@matrix@miny\the\c@pgf@counta\endcsname\relax% |
| 534 |
\advance\pgf@y by\csname pgf@matrix@maxy\the\c@pgf@counta\endcsname\relax |
| 535 |
\advance\c@pgf@counta by-1\relax% |
| 536 |
\pgf@ya=\csname pgf@matrix@miny\the\c@pgf@counta\endcsname\relax% |
| 537 |
\advance\pgf@y by-\pgf@ya\relax% |
| 538 |
\expandafter\xdef\csname pgf@matrix@miny\the\c@pgf@counta\endcsname{\the\pgf@y}% |
| 539 |
\repeat% |
| 540 |
}% |
| 541 |
% |
| 542 |
% Prefix sum on the horizontal positions |
| 543 |
% |
| 544 |
{% |
| 545 |
\ifnum\pgf@matrix@numberofcolumns>0\relax% |
| 546 |
\pgf@x=\csname pgf@matrix@minx1\endcsname\relax% |
| 547 |
\pgf@x=-\pgf@x% |
| 548 |
\expandafter\xdef\csname pgf@matrix@minx1\endcsname{\the\pgf@x}% |
| 549 |
\fi |
| 550 |
\c@pgf@counta=1\relax% |
| 551 |
\loop% |
| 552 |
\ifnum\c@pgf@counta<\pgf@matrix@numberofcolumns\relax% |
| 553 |
\pgf@x=\csname pgf@matrix@minx\the\c@pgf@counta\endcsname\relax% |
| 554 |
\advance\pgf@x by\csname pgf@matrix@maxx\the\c@pgf@counta\endcsname\relax% |
| 555 |
\advance\c@pgf@counta by1\relax% |
| 556 |
\pgf@xa=\csname pgf@matrix@minx\the\c@pgf@counta\endcsname\relax% |
| 557 |
\advance\pgf@x by-\pgf@xa\relax% |
| 558 |
\expandafter\xdef\csname pgf@matrix@minx\the\c@pgf@counta\endcsname{\the\pgf@x}% |
| 559 |
\repeat% |
| 560 |
}% |
| 561 |
}% |
| 562 |
|
| 563 |
|
| 564 |
% Shift the nodes to their origins |
| 565 |
|
| 566 |
% The following procedure shifts all nodes in |
| 567 |
% \pgf@matrix@node@list to their location inside a temporary |
| 568 |
% picture. This picture will later be shifted again to its final |
| 569 |
% position in the real picture. |
| 570 |
|
| 571 |
\def\pgf@matrix@shift@nodes@initial{% |
| 572 |
{% |
| 573 |
\pgfutil@for\pgf@matrix@node@name:=\pgf@matrix@node@list\do{% |
| 574 |
\ifx\pgf@matrix@node@name\pgfutil@empty% |
| 575 |
\else% |
| 576 |
\expandafter\ifx\csname pgf@matrix@node@visited@\pgf@matrix@node@name\endcsname\relax% |
| 577 |
\pgf@shift@node{\pgf@matrix@node@name}{% |
| 578 |
\pgf@x=\csname pgf@matrix@minx% |
| 579 |
\expandafter\expandafter\expandafter\pgfutil@secondoftwo\csname pgf@matrix@node@location@\pgf@matrix@node@name\endcsname\endcsname% |
| 580 |
\pgf@y=\csname pgf@matrix@miny% |
| 581 |
\expandafter\expandafter\expandafter\pgfutil@firstoftwo\csname pgf@matrix@node@location@\pgf@matrix@node@name\endcsname\endcsname% |
| 582 |
}% |
| 583 |
\expandafter\let\csname pgf@matrix@node@visited@\pgf@matrix@node@name\endcsname=\pgfutil@empty% |
| 584 |
\fi% |
| 585 |
\fi% |
| 586 |
}% |
| 587 |
}% |
| 588 |
}% |
| 589 |
|
| 590 |
|
| 591 |
% The second shifting, done in the following procedure, shifts all |
| 592 |
% nodes to their real positions inside the real picture. |
| 593 |
|
| 594 |
\def\pgf@matrix@shift@nodes@secondary#1{% |
| 595 |
\pgfutil@for\pgf@matrix@node@name:=\pgf@matrix@node@list\do{% |
| 596 |
\ifx\pgf@matrix@node@name\pgfutil@empty% |
| 597 |
\else% |
| 598 |
\expandafter\ifx\csname pgf@matrix@node@visited@\pgf@matrix@node@name\endcsname\relax% |
| 599 |
\pgf@shift@node{\pgf@matrix@node@name}{#1}% |
| 600 |
\expandafter\let\csname pgf@matrix@node@visited@\pgf@matrix@node@name\endcsname=\pgfutil@empty% |
| 601 |
\fi% |
| 602 |
\fi% |
| 603 |
}% |
| 604 |
}% |
| 605 |
|
| 606 |
|
| 607 |
% End of line |
| 608 |
\def\pgfmatrixendrow{% |
| 609 |
% if the cell contains nothing, the following \let will be at the |
| 610 |
% beginning (macro expansion has stopped here since neither \omit |
| 611 |
% nor \span was found) |
| 612 |
\let\pgf@matrix@signal@cell@end=\pgf@matrix@signal@cell@end |
| 613 |
\pgf@matrix@last@cell@in@rowtrue% |
| 614 |
\xdef\pgf@matrix@rowsep{\pgfmatrixrowsep}% |
| 615 |
&\pgf@matrix@correct@calltrue% |
| 616 |
\global\pgf@matrix@fixedfalse% |
| 617 |
\pgf@y=0pt% |
| 618 |
\pgf@matrix@addtolength\pgf@y{\pgf@matrix@rowsep}% |
| 619 |
\pgfutil@ifnextchar[{\pgfmatrixendrow@skip}{\pgf@matrix@finish@line}% |
| 620 |
}% |
| 621 |
\newif\ifpgf@matrix@last@cell@in@row |
| 622 |
|
| 623 |
\def\pgf@matrix@signal@cell@end{\pgf@matrix@signal@cell@end}% |
| 624 |
% exact definition does not matter, only needs to be unique. |
| 625 |
|
| 626 |
\def\pgfmatrixendrow@skip[#1]{% |
| 627 |
\pgf@matrix@addtolength\pgf@y{#1}% |
| 628 |
\pgf@matrix@finish@line% |
| 629 |
}% |
| 630 |
|
| 631 |
\def\pgf@matrix@finish@line{% |
| 632 |
\global\pgf@y=\pgf@y% |
| 633 |
\pgf@ya=-\pgf@y% |
| 634 |
\global\advance\pgf@ya by\csname pgf@matrix@miny\the\pgfmatrixcurrentrow\endcsname% |
| 635 |
\expandafter\xdef\csname pgf@matrix@miny\the\pgfmatrixcurrentrow\endcsname{\the\pgf@ya}% |
| 636 |
\pgfutil@ifnextchar\egroup{\cr\pgf@end@matrix}{\pgf@matrix@no@eom@found}% |
| 637 |
}% |
| 638 |
|
| 639 |
\def\pgf@matrix@eom@found{% |
| 640 |
\cr% |
| 641 |
\pgf@end@matrix% |
| 642 |
}% |
| 643 |
|
| 644 |
\def\pgf@matrix@no@eom@found{% |
| 645 |
\cr% |
| 646 |
\noalign{\vskip\pgf@y% |
| 647 |
\ifpgf@matrix@fixed% |
| 648 |
\vskip\csname pgf@matrix@miny\the\pgfmatrixcurrentrow\endcsname% unskip |
| 649 |
\vskip\pgf@y% |
| 650 |
\pgf@y=-\pgf@y% |
| 651 |
\expandafter\xdef\csname pgf@matrix@miny\the\pgfmatrixcurrentrow\endcsname{\the\pgf@y}% |
| 652 |
\gdef\pgf@matrix@row@finish{\global\pgf@picmaxy=0pt}% |
| 653 |
\else% |
| 654 |
\global\let\pgf@matrix@row@finish=\pgfutil@empty% |
| 655 |
\fi% |
| 656 |
}% |
| 657 |
}% |
| 658 |
|
| 659 |
|
| 660 |
\endinput |