| 1 |
% knitting.tex |
| 2 |
% |
| 3 |
% Provides commands useful for writing knitting patterns in plain TeX |
| 4 |
% |
| 5 |
% author: Ariel Barton |
| 6 |
% |
| 7 |
% Copyright Ariel Barton, 2010 |
| 8 |
% |
| 9 |
% This work may be distributed and/or modified under the |
| 10 |
% conditions of the LaTeX Project Public License, either |
| 11 |
% version 1.3 of this license or (at your option) any |
| 12 |
% later version. |
| 13 |
% The latest version of the license is in |
| 14 |
% http://www.latex-project.org/lppl.txt |
| 15 |
% and version 1.3 or later is part of all distributions of |
| 16 |
% LaTeX version 2003/06/01 or later. |
| 17 |
% |
| 18 |
% This work has the LPPL maintenance status "author-maintained". |
| 19 |
% |
| 20 |
% The complete list of files considered part of this work is in |
| 21 |
% the file `knitting-doc.pdf' and its source code `knitting-doc.tex'. |
| 22 |
% |
| 23 |
% Version: 3 |
| 24 |
|
| 25 |
% Date: 2019/04/03 |
| 26 |
|
| 27 |
%\pdfmapfile{+knitfont.map} |
| 28 |
|
| 29 |
\ifnum\catcode`\@=\catcode`A \else |
| 30 |
\chardef\catcountknit=\catcode`@ |
| 31 |
\catcode`@=11 |
| 32 |
\fi |
| 33 |
|
| 34 |
% |
| 35 |
% Boolean variables |
| 36 |
% |
| 37 |
|
| 38 |
\newif \ifchartsonly \chartsonlyfalse |
| 39 |
\newif \ifgrid |
| 40 |
\newif \ifknitsymbol |
| 41 |
\newif \ifresetrn \resetrntrue |
| 42 |
\newif \ifleftrn@knit |
| 43 |
\newif \ifshowrn@knit \showrn@knittrue |
| 44 |
\newif \ifpdf@knit |
| 45 |
\newif \ifcountingout@knit |
| 46 |
\newif \ifCountStsThisRow@knit \CountStsThisRow@knittrue |
| 47 |
\pdf@knittrue |
| 48 |
\ifx \pdfoutput \undefined \pdf@knitfalse \fi |
| 49 |
\ifx \pdfoutput \relax \pdf@knitfalse \fi |
| 50 |
|
| 51 |
% |
| 52 |
% Color commands |
| 53 |
% |
| 54 |
|
| 55 |
% This defines pdfTeX-friendly or dvips-friendly color. |
| 56 |
% Change them to use your driver's syntax if you insist on |
| 57 |
% not using pdfTeX. |
| 58 |
|
| 59 |
% For black lines, just say \let \knitlinecolor \relax |
| 60 |
% If grayscale really just isn't working at all, |
| 61 |
% go down and redefine \changeknitsize |
| 62 |
\ifpdf@knit |
| 63 |
\ifnum \pdftexversion < 140 |
| 64 |
\def\forecolor {\pdfliteral {0 g 0 G}\aftergroup\makenormalcolorknit} |
| 65 |
\def\purlgray {\pdfliteral {0.65 g 0.65 G}\aftergroup\makenormalcolorknit} |
| 66 |
\def\gridcolor {\pdfliteral {0.3 g 0.3 G}\aftergroup\makenormalcolorknit} |
| 67 |
\def\knitlinecolor {\pdfliteral {0.7 0 0 rg 0.7 0 0 RG}\aftergroup\makenormalcolorknit} |
| 68 |
\def\rncolor{\pdfliteral {0.55 0 0 rg 0.55 0 0 RG}\aftergroup\makenormalcolorknit} |
| 69 |
\def\rnarrowcolor{\pdfliteral {0.35 0 0 rg 0.35 0 0 RG}\aftergroup\makenormalcolorknit} |
| 70 |
\def\makenormalcolorknit{\ifcase \passnum@knit \pdfliteral {0.65 g 0.65 G}\or \pdfliteral {0.3 g 0.3 G}\else \pdfliteral {0 g 0 G}\fi} |
| 71 |
\else |
| 72 |
\def\forecolor {\pdfcolorstack 0 push {0 g 0 G}\aftergroup\makenormalcolorknit} |
| 73 |
\def\purlgray {\pdfcolorstack 0 push {0.65 g 0.65 G}\aftergroup\makenormalcolorknit} |
| 74 |
\def\gridcolor {\pdfcolorstack 0 push {0.3 g 0.3 G}\aftergroup\makenormalcolorknit} |
| 75 |
\def\knitlinecolor {\pdfcolorstack 0 push {0.7 0 0 rg 0.7 0 0 RG}\aftergroup\makenormalcolorknit} |
| 76 |
\def\rncolor{\pdfcolorstack 0 push {0.55 0 0 rg 0.55 0 0 RG}\aftergroup\makenormalcolorknit} |
| 77 |
\def\rnarrowcolor{\pdfcolorstack 0 push {0.35 0 0 rg 0.35 0 0 RG}\aftergroup\makenormalcolorknit} |
| 78 |
\def\makenormalcolorknit{\pdfcolorstack 0 pop} |
| 79 |
\fi |
| 80 |
\else |
| 81 |
\def\forecolor {\special{color push gray 0}\aftergroup\makenormalcolorknit} |
| 82 |
\def\purlgray {\special{color push gray 0.65}\aftergroup\makenormalcolorknit} |
| 83 |
\def\gridcolor {\special{color push gray 0.3}\aftergroup\makenormalcolorknit} |
| 84 |
\def\knitlinecolor {\special{color push rgb 0.7 0 0}\aftergroup\makenormalcolorknit} |
| 85 |
\def\rncolor{\special{color push rgb 0.55 0 0}\aftergroup\makenormalcolorknit} |
| 86 |
\def\rnarrowcolor{\special{color push rgb 0.35 0 0}\aftergroup\makenormalcolorknit} |
| 87 |
\def\makenormalcolorknit{\special{color pop}} |
| 88 |
\fi |
| 89 |
\def\knitoverlinecolor{\knitlinecolor} |
| 90 |
|
| 91 |
% |
| 92 |
% Plain TeX-only material (change knit size) |
| 93 |
% |
| 94 |
|
| 95 |
\def \changeknitsize#1{\fontsize@knit = #1 |
| 96 |
\font\knitsf = cmss10 at \fontsize@knit |
| 97 |
\font\knitrm = cmr10 at \fontsize@knit |
| 98 |
\font\knitsfsmall@knit = cmss8 at 0.8\fontsize@knit |
| 99 |
\font\cablesf@knit = cmss8 at 0.8\fontsize@knit |
| 100 |
\font\cablesfsmall@knit = ecss0600 at 0.6\fontsize@knit |
| 101 |
% I would use cmss as the sans serif font here, |
| 102 |
% but cmss6 doesn't exist. |
| 103 |
% |
| 104 |
\font\gff@knit = knitgn at \fontsize@knit |
| 105 |
\font\wff@knit = knitwn at \fontsize@knit |
| 106 |
\font\nff@knit = knitnn at \fontsize@knit |
| 107 |
\font\mff@knit = knitmn at \fontsize@knit |
| 108 |
% |
| 109 |
\font\ggf@knit = knitgg at \fontsize@knit |
| 110 |
\font\wgf@knit = knitwg at \fontsize@knit |
| 111 |
\font\mgf@knit = knitmg at \fontsize@knit |
| 112 |
% |
| 113 |
\font\gpf@knit = knitgp at \fontsize@knit |
| 114 |
\font\wpf@knit = knitwp at \fontsize@knit |
| 115 |
\font\npf@knit = knitnp at \fontsize@knit |
| 116 |
\font\mpf@knit = knitmp at \fontsize@knit |
| 117 |
% |
| 118 |
\font\raisen@knit = knitnr at \fontsize@knit |
| 119 |
\font\lowern@knit = knitnl at \fontsize@knit |
| 120 |
\font\raisem@knit = knitmr at \fontsize@knit |
| 121 |
\font\lowerm@knit = knitml at \fontsize@knit |
| 122 |
\let \raiseg@knit \raisem@knit |
| 123 |
\let \raisew@knit \raisem@knit |
| 124 |
\let \lowerg@knit \lowerm@knit |
| 125 |
\let \lowerw@knit \lowerm@knit |
| 126 |
% |
| 127 |
\font \nstsout@knit = knitn_sc_out at \fontsize@knit |
| 128 |
\font \nstsin@knit = knitn_sc_in at \fontsize@knit |
| 129 |
\font \gstsout@knit = knitg_sc_out at \fontsize@knit |
| 130 |
\font \gstsin@knit = knitg_sc_in at \fontsize@knit |
| 131 |
\let \wstsout@knit \gstsout@knit |
| 132 |
\let \wstsin@knit \gstsin@knit |
| 133 |
\let \mstsout@knit \nstsout@knit |
| 134 |
\let \mstsin@knit \nstsin@knit |
| 135 |
% |
| 136 |
%%% Use the following if you can't get the grays to work. |
| 137 |
%%% In this case, don't use \Purl or \purlbox. |
| 138 |
% \let \gridpf@knit \nullfont |
| 139 |
% \let \widepf@knit \nullfont |
| 140 |
% \let \nogridpf@knit \nullfont |
| 141 |
% \let \purlgray \relax |
| 142 |
} |
| 143 |
\let \ngf@knit \nullfont |
| 144 |
|
| 145 |
|
| 146 |
% |
| 147 |
% Dimensions |
| 148 |
% |
| 149 |
|
| 150 |
\newdimen \leftgap@knit |
| 151 |
\newdimen \bgshift@knit |
| 152 |
\newdimen \chartwidth@knit |
| 153 |
\newdimen \stitchcountwidth@knit |
| 154 |
\newdimen \rnleftwd@knit |
| 155 |
\newdimen \rnrightwd@knit |
| 156 |
\newdimen \fontsize@knit |
| 157 |
|
| 158 |
\newbox\bgbox@knit |
| 159 |
\newbox\fgbox@knit |
| 160 |
\newbox\ggbox@knit |
| 161 |
|
| 162 |
\newcount \rownumber |
| 163 |
\newcount \tempcount@knit |
| 164 |
\newcount \rownumberskip \rownumberskip = 1 |
| 165 |
\newcount \stitchcountin |
| 166 |
\newcount \stitchcountinprev |
| 167 |
\newcount \stitchcountout |
| 168 |
\newcount \shortrowstsin@knit |
| 169 |
\newcount \shortrowstsout@knit |
| 170 |
|
| 171 |
\def \passnum@knit{2} |
| 172 |
\def \stitchwd{\fontdimen6\ff@knit} |
| 173 |
\def \stitchwd@count@knit{\fontdimen6\stsout@knit} |
| 174 |
\def \stitchht{\fontdimen5\ff@knit} |
| 175 |
\def \stitchdp{\fontdimen8\ff@knit} |
| 176 |
% fontdimen9 is the LaTeX stitch height |
| 177 |
\def \gridwidth{\fontdimen10\ff@knit} |
| 178 |
\def \knitlinewd{\fontdimen11\ff@knit} |
| 179 |
\def \narrowincraise@knit{\fontdimen12\the\font} |
| 180 |
\def \fontvoffset@knit{\fontdimen13\the\font} |
| 181 |
\def \purlextend@knit{\fontdimen14\ff@knit} |
| 182 |
\def \rownumberwd{\fontdimen6\ff@knit} |
| 183 |
% The rest of them aren't \the\font because I want them to still work outside of a chart |
| 184 |
|
| 185 |
% |
| 186 |
% Fonts |
| 187 |
% |
| 188 |
|
| 189 |
\def \ff@knit{\csname \series@knit ff@knit\endcsname} |
| 190 |
\def \gf@knit{\csname \series@knit gf@knit\endcsname} |
| 191 |
\def \pf@knit{\csname \series@knit pf@knit\endcsname} |
| 192 |
\def \raiseff@knit{\csname raise\series@knit @knit\endcsname} |
| 193 |
\def \lowerff@knit{\csname lower\series@knit @knit\endcsname} |
| 194 |
\def \stsout@knit{\csname \series@knit stsout@knit\endcsname} |
| 195 |
\def \stsin@knit{\csname \series@knit stsin@knit\endcsname} |
| 196 |
|
| 197 |
\def \knitnogrid{\gridfalse\knitsymboltrue \def\series@knit{n}} |
| 198 |
\def \knitgrid{\gridtrue \knitsymbolfalse\def\series@knit{g}} |
| 199 |
\def \knitwide{\gridtrue \knitsymbolfalse\def\series@knit{w}} |
| 200 |
\def \knitmixed{\gridtrue \knitsymboltrue \def\series@knit{m}} |
| 201 |
|
| 202 |
\changeknitsize{10pt} |
| 203 |
|
| 204 |
\knitgrid |
| 205 |
|
| 206 |
% |
| 207 |
% Single-pass commands |
| 208 |
% |
| 209 |
|
| 210 |
\def \purlpass{\futurelet\next@knit\purlpass@@knit} |
| 211 |
\def \gridpass{\futurelet\next@knit\gridpass@@knit} |
| 212 |
\def \mainpass{\futurelet\next@knit\mainpass@@knit} |
| 213 |
\def \countpass{\futurelet\next@knit\mainpass@@knit} |
| 214 |
\def \purlpass@@knit{\ifx\next@knit[\def\nextstep@knit{\purlpass@knit}\else\def\nextstep@knit{\purlpass@knit[]}\fi\nextstep@knit} |
| 215 |
\def \gridpass@@knit{\ifx\next@knit[\def\nextstep@knit{\gridpass@knit}\else\def\nextstep@knit{\gridpass@knit[]}\fi\nextstep@knit} |
| 216 |
\def \mainpass@@knit{\ifx\next@knit[\def\nextstep@knit{\mainpass@knit}\else\def\nextstep@knit{\mainpass@knit[]}\fi\nextstep@knit} |
| 217 |
\def \countpass@@knit{\ifx\next@knit[\def\nextstep@knit{\countpass@knit}\else\def\nextstep@knit{\countpass@knit[]}\fi\nextstep@knit} |
| 218 |
\def \purlpass@knit[#1]#2{\ifnum\passnum@knit = 0 \def\nextstep@@knit{#2}\else \def\nextstep@@knit{#1}\fi\nextstep@@knit} |
| 219 |
\def \purlpass@knit[#1]#2{\ifnum\passnum@knit = 0 #2\else #1\fi} |
| 220 |
\def \gridpass@knit[#1]#2{\ifnum\passnum@knit = 1 #2\else #1\fi} |
| 221 |
\def \mainpass@knit[#1]#2{\ifnum\passnum@knit = 2 #2\else #1\fi} |
| 222 |
\def \countpass@knit[#1]#2{\ifnum\passnum@knit = 3 #2\else #1\fi} |
| 223 |
|
| 224 |
% |
| 225 |
% Text knit |
| 226 |
% |
| 227 |
|
| 228 |
\def \textknit#1{\leavevmode\hbox{\let\|\bar@knit\let\!\barthin@knit |
| 229 |
\ff@knit \forecolor |
| 230 |
\rlap{\pf@knit \purlgray \def\passnum@knit{0}#1}% |
| 231 |
\ifgrid\rlap{\gf@knit \gridcolor \def\passnum@knit{1}#1}\fi |
| 232 |
\def\passnum@knit{2}#1}} |
| 233 |
|
| 234 |
\def \do@endofpar@knit#1{\def\par{#1\endgraf\let\par\endgraf}} |
| 235 |
|
| 236 |
% |
| 237 |
% Special symbols |
| 238 |
% |
| 239 |
|
| 240 |
\def\narrowincreasestartnumber{1} |
| 241 |
\def\narrowdecreaseendnumber{1} |
| 242 |
|
| 243 |
\def \narrowdecrease#1{\genbobble@knit{#1}{1}{-\narrowincraise@knit}\adjuststitchcount[#1]{\narrowdecreaseendnumber}\adjuststitchcount[-1]{-1}} |
| 244 |
\def \pnarrowdecrease#1{\genbobble@knit{#1}{2}{-\narrowincraise@knit}\adjuststitchcount[#1]{\narrowdecreaseendnumber}\adjuststitchcount[-1]{-1}} |
| 245 |
\def \narrowincrease#1{\genbobble@knit{#1}{3}{\narrowincraise@knit}\adjuststitchcount[\narrowincreasestartnumber]{#1}\adjuststitchcount[-1]{-1}} |
| 246 |
\def \pnarrowincrease#1{\genbobble@knit{#1}{4}{\narrowincraise@knit}\adjuststitchcount[\narrowincreasestartnumber]{#1}\adjuststitchcount[-1]{-1}} |
| 247 |
\def \bobble#1{\genbobble@knit{#1}{0}{0pt}} |
| 248 |
|
| 249 |
\def \genbobble@knit#1#2#3{\char#2 \ifnum \passnum@knit = 2 |
| 250 |
\llap{\vbox to\stitchht{\vss \vskip\stitchdp \vskip\fontvoffset@knit \hbox to \stitchwd{\hfil\knitsfsmall@knit #1\hfil}\vskip #3\vss}}\fi} |
| 251 |
|
| 252 |
\def \wideincrease#1{\strut@knit |
| 253 |
\ifnum\passnum@knit = 3 \narrowincrease{#1}\else |
| 254 |
\hbox to #1\stitchwd{\char25 |
| 255 |
\hskip-0.1pt\leaders\hbox{\char22}\hfil\hskip-0.1pt |
| 256 |
\char29 |
| 257 |
\hskip-0.1pt\leaders\hbox{\char22}\hfil\hskip-0.1pt |
| 258 |
\char26}\fi} |
| 259 |
\def \widedecrease#1{\strut@knit |
| 260 |
\ifnum #1 = 5 \char31 \else |
| 261 |
\ifnum\passnum@knit = 3 \narrowdecrease{#1}\else |
| 262 |
\hbox to #1\stitchwd{\char27 |
| 263 |
\hskip-0.1pt\leaders\hbox{\char22}\hfil\hskip-0.1pt |
| 264 |
\char30 |
| 265 |
\hskip-0.1pt\leaders\hbox{\char22}\hfil\hskip-0.1pt |
| 266 |
\char28}\fi\fi} |
| 267 |
|
| 268 |
% Standard chart commands |
| 269 |
|
| 270 |
% \obeylines is normally defined with \let^^M\par, not \def^^M{\par}; |
| 271 |
% doing it this way makes it cooperate with \do@endofpar. |
| 272 |
|
| 273 |
{\catcode`\^^M = \active \catcode`\| = \active |
| 274 |
\global\def\commands@knit{% |
| 275 |
\let\[\pnarrowincrease |
| 276 |
\let\]\pnarrowdecrease |
| 277 |
\let\<\narrowincrease |
| 278 |
\let\>\narrowdecrease |
| 279 |
\let\@\bobble |
| 280 |
\let \! \barthin@knit |
| 281 |
\let \| \bar@knit |
| 282 |
\let | \bar@knit |
| 283 |
\let \_ \horizlinenarrow@knit |
| 284 |
\let \= \horizlinewide@knit |
| 285 |
\let \- \horizline@knit |
| 286 |
\let\overline\overline@knit |
| 287 |
\let\underline\underline@knit |
| 288 |
\let\rn\rn@knit |
| 289 |
\let\rnbox\rnbox@knit |
| 290 |
\let\rnboxleft\rnboxleft@knit |
| 291 |
\let\rnboxright\rnboxright@knit |
| 292 |
\let\rnleft\rnleft@knit |
| 293 |
\let\rnright\rnright@knit |
| 294 |
\let\nonumber\relax |
| 295 |
\let\par\endgraf %Just in case someone's redefined it |
| 296 |
\leftgap@knit=0pt |
| 297 |
\def~{\ifnum\passnum@knit=3 \else \ifvmode \advance \leftgap@knit by \stitchwd |
| 298 |
\else \kern \stitchwd \fi \fi}% |
| 299 |
\def^^M{\par}% |
| 300 |
\def\\{\par}% |
| 301 |
}% |
| 302 |
} |
| 303 |
|
| 304 |
\def \strut@knit{\vrule width 0pt height \stitchht depth \stitchdp} |
| 305 |
|
| 306 |
% Drawing lines on the chart |
| 307 |
|
| 308 |
\def \horizlinenarrow@knit{\ifnum\passnum@knit<3 \ifvmode\nonumber\leavevmode\fi \dimen0 = \stitchwd \advance \dimen0 \knitlinewd |
| 309 |
\ifnum\passnum@knit = 2 |
| 310 |
\hskip -0.5\knitlinewd\smash{{\knitoverlinecolor \vrule width \dimen0 height 0.5\knitlinewd depth 0.5\knitlinewd}}\hskip -0.5\knitlinewd |
| 311 |
\else\hskip \stitchwd \fi\fi} |
| 312 |
\def \horizlinewide@knit#1{\ifnum\passnum@knit<3 \ifvmode\nonumber\leavevmode\fi \dimen0 = #1\stitchwd \advance \dimen0 \knitlinewd |
| 313 |
\ifnum\passnum@knit = 2 |
| 314 |
\smash{{\knitoverlinecolor \vrule width \dimen0 height 0.5\knitlinewd depth 0.5\knitlinewd}} |
| 315 |
\else\hskip \dimen0 \fi\fi} |
| 316 |
|
| 317 |
\def \horizline@knit{\futurelet\next@knit\horizline@@knit} |
| 318 |
\def \horizline@@knit{\ifx\next@knit*% |
| 319 |
\def\nextstep@knit{\horizlinestar@knit}\else |
| 320 |
\def\nextstep@knit{\horizlinenostar@knit}\fi\nextstep@knit} |
| 321 |
|
| 322 |
\def \horizlinestar@knit#1{\nonumber\nostitchcount\overlinestar@knit{\hskip#1\stitchwd}} |
| 323 |
\def \horizlinenostar@knit#1{\nonumber\nostitchcount\overlinenostar@knit{\hskip#1\stitchwd}} |
| 324 |
|
| 325 |
\def \bar@knit{\ifnum\passnum@knit < 3 \leavevmode |
| 326 |
\ifgrid |
| 327 |
\ifnum \passnum@knit = 0 |
| 328 |
\hbox{{\knitlinecolor \vrule width \knitlinewd depth \stitchdp height \stitchht}}% |
| 329 |
\else |
| 330 |
\kern \knitlinewd |
| 331 |
\fi |
| 332 |
\else |
| 333 |
\ifnum \passnum@knit = 2 |
| 334 |
\hbox{\knitlinecolor \vrule width \knitlinewd depth \stitchdp height \stitchht}% |
| 335 |
\else |
| 336 |
\kern \knitlinewd |
| 337 |
\fi |
| 338 |
\fi\fi} |
| 339 |
|
| 340 |
\def \barthintop@knit{0pt} |
| 341 |
\def \barthinbot@knit{0pt} |
| 342 |
|
| 343 |
\def \barthin@knit{\leavevmode\strut@knit |
| 344 |
\ifnum \passnum@knit = 2 |
| 345 |
\dimen2 = \stitchht \advance \dimen2 \barthintop@knit |
| 346 |
\dimen3 = \stitchdp \advance \dimen3 \barthinbot@knit |
| 347 |
\smash{\hbox to 0pt{\hss \knitlinecolor \vrule width \knitlinewd depth \dimen3 height \dimen2\hss}}% |
| 348 |
\fi} |
| 349 |
|
| 350 |
\def \overline@knit{\futurelet\next@knit\overline@@knit} |
| 351 |
\def \overline@@knit{\ifx\next@knit*% |
| 352 |
\def\nextstep@knit{\overlinestar@knit}\else |
| 353 |
\def\nextstep@knit{\overlinenostar@knit}\fi\nextstep@knit} |
| 354 |
|
| 355 |
\def \overlinenostar@knit#1{\leavevmode{\def\barthintop@knit{\knitlinewd}% |
| 356 |
\setbox0 = \hbox{#1}% |
| 357 |
\ifgrid |
| 358 |
\ifnum \passnum@knit = 0 |
| 359 |
\dimen1=\wd0 \advance\dimen1 by \gridwidth |
| 360 |
{\rlap{\raise\ht0\hbox{\hskip -0.5\gridwidth\knitoverlinecolor \vrule width \dimen1 height \knitlinewd depth 0pt}}}% |
| 361 |
\else |
| 362 |
\raise\ht0\hbox{\vrule width 0pt height \knitlinewd depth 0pt}% |
| 363 |
\fi |
| 364 |
\else |
| 365 |
\ifnum \passnum@knit = 2 |
| 366 |
\dimen1=\wd0 \advance\dimen1 by \gridwidth |
| 367 |
{\rlap{\raise\ht0\hbox{\hskip -0.5\gridwidth\knitoverlinecolor \vrule width \dimen1 height \knitlinewd depth 0pt}}}% |
| 368 |
\else |
| 369 |
\dimen0=\ht0 \advance \dimen0 \knitlinewd |
| 370 |
\vrule width 0pt height \dimen0 depth 0pt |
| 371 |
\fi \fi |
| 372 |
#1}} |
| 373 |
|
| 374 |
\def \overlinestar@knit#1#2{\leavevmode{\def\barthintop@knit{0.5\knitlinewd}% The #1 is to eat the * |
| 375 |
\setbox0 = \hbox{#2}% |
| 376 |
\ifnum \passnum@knit = 2 |
| 377 |
\dimen1=\wd0 \advance\dimen1 by \gridwidth |
| 378 |
\smash{\rlap{\raise\ht0\hbox{\hskip -0.5\gridwidth\knitoverlinecolor \vrule width \dimen1 height 0.5\knitlinewd depth 0.5\knitlinewd}}}% |
| 379 |
\fi |
| 380 |
#2}} |
| 381 |
|
| 382 |
\def \underline@knit{\futurelet\next@knit\underline@@knit} |
| 383 |
\def \underline@@knit{\ifx\next@knit*% |
| 384 |
\def\nextstep@knit{\underlinestar@knit}\else |
| 385 |
\def\nextstep@knit{\underlinenostar@knit}\fi\nextstep@knit} |
| 386 |
|
| 387 |
\def \underlinenostar@knit#1{\leavevmode{\def\barthinbot@knit{\knitlinewd}% |
| 388 |
\setbox0 = \hbox{#1}% |
| 389 |
\ifgrid |
| 390 |
\ifnum \passnum@knit = 0 |
| 391 |
\dimen1=\wd0 \advance\dimen1 by \gridwidth |
| 392 |
\rlap{\raise-\dp0\hbox{\hskip -0.5\gridwidth\knitoverlinecolor \vrule width \dimen1 height 0pt depth \knitlinewd \hskip -0.5\gridwidth}}% |
| 393 |
\else |
| 394 |
\rlap{\raise-\dp0\hbox{\vrule width 0pt height 0pt depth \knitlinewd}}% |
| 395 |
\fi |
| 396 |
\else |
| 397 |
\ifnum \passnum@knit = 2 |
| 398 |
\dimen1=\wd0 \advance\dimen1 by \gridwidth |
| 399 |
\rlap{\raise-\dp0\hbox{\hskip -0.5\gridwidth\knitoverlinecolor \vrule width \dimen1 height 0pt depth \knitlinewd \hskip -0.5\gridwidth}}% |
| 400 |
\else |
| 401 |
\rlap{\raise-\dp0\hbox{\vrule width 0pt height 0pt depth \knitlinewd}}% |
| 402 |
\fi \fi |
| 403 |
#1}} |
| 404 |
|
| 405 |
\def \underlinestar@knit#1#2{\leavevmode{\def\barthinbot@knit{0.5\knitlinewd}% |
| 406 |
\setbox0 = \hbox{#2}% |
| 407 |
\ifnum \passnum@knit = 2 |
| 408 |
\dimen1=\wd0 \advance\dimen1 by \gridwidth |
| 409 |
\smash{\rlap{\raise-\dp0\hbox{\hskip -0.5\gridwidth\knitoverlinecolor \vrule width \dimen1 height 0.5\knitlinewd depth 0.5\knitlinewd \hskip -0.5\gridwidth}}}% |
| 410 |
\fi |
| 411 |
#2}} |
| 412 |
|
| 413 |
% Fancy cabling |
| 414 |
|
| 415 |
% \ifnum \passnum@knit = 3 \leavevmode \fi causes problems |
| 416 |
% due to the weird things we do automatically at the start of a paragraph |
| 417 |
\def\doifcounting@knit#1{} |
| 418 |
|
| 419 |
\def\cablebackground#1{\doifcounting@knit{\leavevmode}% |
| 420 |
\ifnum \passnum@knit = 0 \leavevmode \hbox to \stitchwd{#1\hss {\raiseff@knit \def\passnum@knit{2}\forecolor#1}}\else \char255 \fi} |
| 421 |
\def\cableforeground#1{\doifcounting@knit{\leavevmode}% |
| 422 |
\ifnum \passnum@knit = 0 \leavevmode \hbox to \stitchwd{#1\hss {\lowerff@knit \def\passnum@knit{2}\forecolor#1}}\else \char254 \fi} |
| 423 |
|
| 424 |
\def\orphancablewarning@knit{\message{Package knit warning: Orphaned half cable on input line \the\inputlineno.}} |
| 425 |
|
| 426 |
\def \cableleft#1#2{\leavevmode{\ifgrid\knitmixed\fi |
| 427 |
\ifcase\passnum@knit |
| 428 |
\hbox{\pf@knit #1#2}% |
| 429 |
\or |
| 430 |
\setbox0=\hbox{\pf@knit #1#2}% |
| 431 |
\hbox to \wd0{\char6\leaders\hbox{\char5}\hfil\char6}% |
| 432 |
\or |
| 433 |
\hbox{\let\knitsf \cablesf@knit \let \knitsfsmall@knit \cablesfsmall@knit % |
| 434 |
\setbox1=\hbox{#1}% |
| 435 |
\setbox2=\hbox{#2}% |
| 436 |
\ifdim \wd1 = 0pt \orphancablewarning@knit \fi |
| 437 |
\ifdim \wd2 = 0pt \orphancablewarning@knit \fi |
| 438 |
{\lowerff@knit \rlap{#1}\hbox to \wd1{\leaders\hbox to \stitchwd{\hfil\char15}\hfil\ifdim\wd1>0pt \hskip\stitchwd\char10\fi}% |
| 439 |
\ifdim\wd1>0pt \ifdim \wd2>0pt \char13\fi \fi }% |
| 440 |
{\raiseff@knit \rlap{#2}\hbox to \wd2{\ifdim\wd2>0pt \char12\hskip\stitchwd\fi\leaders\hbox to \stitchwd{\char8\hfil}\hfil}}}% |
| 441 |
\else |
| 442 |
#1#2\fi}} |
| 443 |
\def \cableright#1#2{\leavevmode{\ifgrid\knitmixed\fi |
| 444 |
\ifcase\passnum@knit |
| 445 |
\hbox{\pf@knit #1#2}% |
| 446 |
\or |
| 447 |
\setbox0=\hbox{\pf@knit #1#2}% |
| 448 |
\hbox to \wd0{\char6\leaders\hbox{\char5}\hfil\char6}% |
| 449 |
\or |
| 450 |
\hbox{\let\knitsf \cablesf@knit \let \knitsfsmall@knit \cablesfsmall@knit % |
| 451 |
\setbox1=\hbox{#1}% |
| 452 |
\setbox2=\hbox{#2}% |
| 453 |
\ifdim \wd1 = 0pt \orphancablewarning@knit \fi |
| 454 |
\ifdim \wd2 = 0pt \orphancablewarning@knit \fi |
| 455 |
{\raiseff@knit \rlap{#1}\hbox to \wd1{\leaders\hbox to \stitchwd{\hfil\char16}\hfil\ifdim\wd1>0pt \hskip\stitchwd\char9\fi}% |
| 456 |
\ifdim\wd1>0pt \ifdim \wd2>0pt \char14\fi \fi }% |
| 457 |
{\lowerff@knit \rlap{#2}\hbox to \wd2{\ifdim\wd2>0pt \char11\hskip\stitchwd \fi\leaders\hbox to \stitchwd{\char7\hfil}\hfil}}}% |
| 458 |
\else |
| 459 |
#1#2\fi}} |
| 460 |
|
| 461 |
% Knit, purl, knitboxes |
| 462 |
|
| 463 |
\def \knit#1{\strut@knit\hbox to #1\stitchwd{\leaders\hbox{-}\hfil}} |
| 464 |
\def \purl#1{\strut@knit\hbox to #1\stitchwd{\leaders\hbox{=}\hfil}} |
| 465 |
|
| 466 |
\def \knitboxbackground{} |
| 467 |
\def \purlboxbackground{\purlgray } |
| 468 |
\def \purlboxforeground{} |
| 469 |
\def \knitboxforeground{} |
| 470 |
|
| 471 |
\def \Knit{\futurelet\next@knit\Knit@knit} |
| 472 |
\def \Knit@knit{\ifx\next@knit[% |
| 473 |
\def\nextstep@knit{\Knit@@knit}\else |
| 474 |
\def\nextstep@knit{\Knit@@knit[0]}\fi\nextstep@knit} |
| 475 |
\def \Knit@@knit[#1]#2#3{\strut@knit |
| 476 |
\setbox0 = \hbox{\knitsf #2}% |
| 477 |
\ifcase \passnum@knit |
| 478 |
\ifx \empty \knitboxbackground |
| 479 |
\vrule width #3\stitchwd height 0pt depth 0pt |
| 480 |
\else |
| 481 |
{\knitboxbackground \purlbackground{\vrule width #3\stitchwd depth \stitchdp height \stitchht}}\fi |
| 482 |
\or |
| 483 |
\ifknitsymbol |
| 484 |
\hbox to #3\stitchwd{\char6\leaders\hbox{\char5}\hfil\char6}% |
| 485 |
\else |
| 486 |
\hbox{\hbox to #3\stitchwd{% |
| 487 |
\leaders \hbox to \stitchwd{\char6\hfil\char6}\hfil |
| 488 |
\hskip \wd0 |
| 489 |
\leaders \hbox to \stitchwd{\char6\hfil\char6}\hfil}% |
| 490 |
\hskip -#3\stitchwd |
| 491 |
\hbox to #3\stitchwd{\char6\leaders\hbox{\char5}\hfil\char6}}% |
| 492 |
\fi |
| 493 |
\or |
| 494 |
\hbox to #3\stitchwd{% |
| 495 |
{\knitboxforeground\leaders\hbox{-}% |
| 496 |
\ifnum #1>0 \hskip #1\stitchwd plus 1fil minus #1\stitchwd \else\hfil\fi |
| 497 |
}% |
| 498 |
\lower\stitchdp\vbox to\stitchht{\vss\vskip\fontvoffset@knit\hbox{\knitsf #2}\vss\vskip\stitchdp} |
| 499 |
{\knitboxforeground \count255 = -#1 \leaders\hbox{-}% |
| 500 |
\ifnum #1<0 \hskip \count255\stitchwd plus 1fil minus \count255\stitchwd \else\hfil\fi |
| 501 |
}}% |
| 502 |
\or |
| 503 |
\hbox to \Knitstitchcount{#2}{#3}\stitchwd{\hfil} |
| 504 |
\fi} |
| 505 |
\def \Purl{\futurelet\next@knit\Purl@knit} |
| 506 |
\def \Purl@knit{\ifx\next@knit[% |
| 507 |
\def\nextstep@knit{\Purl@@knit}\else |
| 508 |
\def\nextstep@knit{\Purl@@knit[0]}\fi\nextstep@knit} |
| 509 |
\def \Purl@@knit[#1]#2#3{\strut@knit |
| 510 |
\setbox0 = \hbox{\knitsf #2}% |
| 511 |
\ifcase \passnum@knit |
| 512 |
\ifx \empty \purlboxbackground |
| 513 |
\vrule width #3\stitchwd height 0pt depth 0pt |
| 514 |
\else |
| 515 |
{\purlboxbackground \purlbackground{\vrule width #3\stitchwd depth \stitchdp height \stitchht}}\fi |
| 516 |
\or |
| 517 |
\ifknitsymbol |
| 518 |
\hbox to #3\stitchwd{\char6\leaders\hbox{\char5}\hfil\char6}% |
| 519 |
\else |
| 520 |
\hbox{\hbox to #3\stitchwd{% |
| 521 |
\leaders \hbox to \stitchwd{\char6\hfil\char6}\hfil |
| 522 |
\hskip \wd0 |
| 523 |
\leaders \hbox to \stitchwd{\char6\hfil\char6}\hfil}% |
| 524 |
\hskip -#3\stitchwd |
| 525 |
\hbox to #3\stitchwd{\char6\leaders\hbox{\char5}\hfil\char6}}% |
| 526 |
\fi |
| 527 |
\or |
| 528 |
\hbox to #3\stitchwd{% |
| 529 |
{\purlboxforeground\leaders\hbox{=}% |
| 530 |
\ifnum #1>0 \hskip #1\stitchwd plus 1fil minus #1\stitchwd \else\hfil\fi |
| 531 |
}% |
| 532 |
\lower\stitchdp\vbox to\stitchht{\vss\vskip\fontvoffset@knit\hbox{\knitsf #2}\vss\vskip\stitchdp} |
| 533 |
{\purlboxforeground \count255 = -#1 \leaders\hbox{=}% |
| 534 |
\ifnum #1<0 \hskip \count255\stitchwd plus 1fil minus \count255\stitchwd \else\hfil\fi |
| 535 |
}}% |
| 536 |
\or |
| 537 |
\hbox to \Purlstitchcount{#2}{#3}\stitchwd{\hfil} |
| 538 |
\fi} |
| 539 |
|
| 540 |
\def \Knitstitchcount#1#2{#2} |
| 541 |
\def \Purlstitchcount#1#2{#2} |
| 542 |
\def \knitboxstitchcount#1#2{#2} |
| 543 |
\def \purlboxstitchcount#1#2{#2} |
| 544 |
|
| 545 |
\def \knitbox{\futurelet\next@knit\knitbox@knit} |
| 546 |
\def \knitbox@knit{\ifx\next@knit[% |
| 547 |
\def\nextstep@knit{\knitbox@@knit}\else |
| 548 |
\def\nextstep@knit{\knitbox@@knit[0]}\fi\nextstep@knit} |
| 549 |
\def \knitbox@@knit[#1]#2#3{\strut@knit |
| 550 |
\ifcase \passnum@knit |
| 551 |
\ifx \empty \knitboxbackground |
| 552 |
\vrule width #3\stitchwd height 0pt depth 0pt |
| 553 |
\else |
| 554 |
{\knitboxbackground \purlbackground{\vrule width #3\stitchwd depth \stitchdp height \stitchht}}\fi |
| 555 |
\or |
| 556 |
\hbox to #3\stitchwd{\char6\leaders\hbox{\char5}\hfil\char6}% |
| 557 |
\or |
| 558 |
\lower\stitchdp\vbox to\stitchht{% |
| 559 |
\vss\vskip\fontvoffset@knit |
| 560 |
\hbox to #3\stitchwd{\ifnum #1>0 \hskip #1\stitchwd plus 1fil minus #1\stitchwd \else\hfil\fi |
| 561 |
{\knitsf #2}% |
| 562 |
\count255 = -#1 \ifnum #1<0 \hskip \count255\stitchwd plus 1fil minus \count255\stitchwd \else\hfil\fi}% |
| 563 |
\vss\vskip\stitchdp}% |
| 564 |
\or |
| 565 |
\hbox to \knitboxstitchcount{#2}{#3}\stitchwd{\hfil} |
| 566 |
\fi} |
| 567 |
\def \purlbox{\futurelet\next@knit\purlbox@knit} |
| 568 |
\def \purlbox@knit{\ifx\next@knit[% |
| 569 |
\def\nextstep@knit{\purlbox@@knit}\else |
| 570 |
\def\nextstep@knit{\purlbox@@knit[0]}\fi\nextstep@knit} |
| 571 |
\def \purlbox@@knit[#1]#2#3{\strut@knit |
| 572 |
\ifcase \passnum@knit |
| 573 |
\ifx \empty \purlboxbackground |
| 574 |
\vrule width #3\stitchwd height 0pt depth 0pt |
| 575 |
\else |
| 576 |
{\purlboxbackground \purlbackground{\vrule width #3\stitchwd depth \stitchdp height \stitchht}}\fi |
| 577 |
\or |
| 578 |
\hbox to #3\stitchwd{\char6\leaders\hbox{\char5}\hfil\char6}% |
| 579 |
\or |
| 580 |
\lower\stitchdp\vbox to\stitchht{% |
| 581 |
\vss\vskip\fontvoffset@knit |
| 582 |
\hbox to #3\stitchwd{\ifnum #1>0 \hskip #1\stitchwd plus 1fil minus #1\stitchwd \else\hfil\fi |
| 583 |
{\knitsf #2}% |
| 584 |
\count255 = -#1 \ifnum #1<0 \hskip \count255\stitchwd plus 1fil minus \count255\stitchwd \else\hfil\fi}% |
| 585 |
\vss\vskip\stitchdp}% |
| 586 |
\or |
| 587 |
\hbox to \purlboxstitchcount{#2}{#3}\stitchwd{\hfil}% |
| 588 |
\fi} |
| 589 |
|
| 590 |
\def \purlbackground#1{% |
| 591 |
\ifnum\passnum@knit=0 |
| 592 |
\setbox0=\hbox{#1}% |
| 593 |
\dimen0 = \wd0 \advance\dimen0 2\purlextend@knit |
| 594 |
\dimen1 = \stitchht \advance\dimen1 \purlextend@knit |
| 595 |
\dimen2 = \stitchdp \advance\dimen2 \purlextend@knit |
| 596 |
\vrule width 0pt height \ht0 depth \dp0 |
| 597 |
\smash{\vrule width \dimen0 height \dimen1 depth \dimen2}% |
| 598 |
\kern-\purlextend@knit |
| 599 |
\else#1\fi} |
| 600 |
|
| 601 |
\def \widesymbol{\futurelet\next@knit\widesymbol@knit} |
| 602 |
\def \widesymbol@knit{\ifx\next@knit[% |
| 603 |
\def\nextstep@knit{\widesymbol@@knit}\else |
| 604 |
\def\nextstep@knit{\widesymbol@@knit[0]}\fi\nextstep@knit} |
| 605 |
\def \widesymbol@@knit[#1]#2#3{\strut@knit |
| 606 |
\ifcase \passnum@knit |
| 607 |
\knitbox{}{#3}\or |
| 608 |
\knitbox{}{#3}\or |
| 609 |
\hbox to #3\stitchwd{\ifnum #1>0 \hskip #1\stitchwd plus 1fil minus #1\stitchwd \else\hfil\fi |
| 610 |
#2% |
| 611 |
\count255 = -#1 \ifnum #1<0 \hskip \count255\stitchwd plus 1fil minus \count255\stitchwd \else\hfil\fi}\else |
| 612 |
\widesymbolspacer{#2}{#3}\relax\fi} |
| 613 |
|
| 614 |
\def\widesymbolspacer#1#2{#1} |
| 615 |
|
| 616 |
|
| 617 |
% Row number commands |
| 618 |
|
| 619 |
\def \numberrow#1#2#3{\ifnum\passnum@knit=3 \ifvmode\vskip\stitchht\fi\else |
| 620 |
\ifvmode\nonumber\leavevmode\fi |
| 621 |
\strut@knit |
| 622 |
\count255=#1 |
| 623 |
\hbox to \stitchwd{\hss\ifnum \passnum@knit = 2 \rncolor \knitrm#1\fi\hss}% |
| 624 |
\ifnum #1 > #3 |
| 625 |
\advance\count255 -1 |
| 626 |
\loop \ifnum \count255>#3 |
| 627 |
\tempcount@knit = \count255 |
| 628 |
\divide\tempcount@knit #2 |
| 629 |
\multiply \tempcount@knit #2 |
| 630 |
\ifnum\tempcount@knit = \count255 |
| 631 |
\hbox to \stitchwd{\hss\ifnum \passnum@knit = 2 \rncolor \knitrm\the\count255 \fi \hss}% |
| 632 |
\else |
| 633 |
\kern\stitchwd |
| 634 |
\fi |
| 635 |
\advance\count255 -1 |
| 636 |
\repeat |
| 637 |
\else |
| 638 |
\advance\count255 1 |
| 639 |
\loop \ifnum \count255<#3 |
| 640 |
\tempcount@knit = \count255 |
| 641 |
\divide\tempcount@knit #2 |
| 642 |
\multiply \tempcount@knit #2 |
| 643 |
\ifnum\tempcount@knit = \count255 |
| 644 |
\hbox to \stitchwd{\hss\ifnum \passnum@knit = 2 \rncolor \knitrm\the\count255 \fi \hss}% |
| 645 |
\else |
| 646 |
\kern\stitchwd |
| 647 |
\fi |
| 648 |
\advance\count255 1 |
| 649 |
\repeat |
| 650 |
\fi |
| 651 |
\hbox to \stitchwd{\hss\ifnum \passnum@knit = 2 \rncolor \knitrm#3\fi \hss}% |
| 652 |
\fi} |
| 653 |
|
| 654 |
\def \rnoddonly{\def\rncore@knit##1{\ifshowrn@knit \ifodd\rownumber \csname print##1rownumber\endcsname{\therownumber}\fi\fi}} |
| 655 |
\def \rnevenonly{\def\rncore@knit##1{\ifshowrn@knit \ifodd\rownumber \else\csname print##1rownumber\endcsname{\therownumber}\fi\fi}} |
| 656 |
\def \rnnormal{\def\rncore@knit##1{\ifshowrn@knit \csname print##1rownumber\endcsname{\therownumber}\fi}} |
| 657 |
|
| 658 |
\def \rncore@knit#1{\ifshowrn@knit \csname print#1rownumber\endcsname{\therownumber}\fi} |
| 659 |
\def \rnstep@knit{\ifshowrn@knit |
| 660 |
\ifnum \passnum@knit = 2 \global\advance\rownumber -\rownumberskip \relax\fi |
| 661 |
\ifnum \passnum@knit = 0 \global\advance\rownumber -\rownumberskip \relax\fi |
| 662 |
\else\global\showrn@knittrue\fi} |
| 663 |
|
| 664 |
\def \printrownumber#1{{\rncolor \knitrm #1}} |
| 665 |
\def \printrightrownumber#1{\knitleftarrowhead{\rncolor \knitrm #1}} |
| 666 |
\def \printleftrownumber#1{{\rncolor \knitrm #1}\knitrightarrowhead} |
| 667 |
\def \knitrightarrowhead{{\rnarrowcolor \char125}} |
| 668 |
\def \knitleftarrowhead{{\rnarrowcolor \char123}} |
| 669 |
|
| 670 |
\def \therownumber{\number\rownumber} |
| 671 |
|
| 672 |
\def \rn@knit{\ifnum \passnum@knit < 3 \leavevmode |
| 673 |
\hbox to \rownumberwd{\hss\ifnum \passnum@knit = 2 \rncore@knit{}\fi\rnstep@knit\hss}\fi} |
| 674 |
\def \rnleft@knit{\ifnum \passnum@knit < 3 \leavevmode |
| 675 |
\setbox0 = \hbox{\ifnum \passnum@knit = 2 \rncore@knit{left}\fi\rnstep@knit} |
| 676 |
\dimen0 = \wd0 %\advance \dimen0 -\rownumberwd |
| 677 |
\ifchartsonly\advance \dimen0 1pt\fi |
| 678 |
\ifdim \dimen0 > \rnleftwd@knit \global\rnleftwd@knit = \dimen0 \fi |
| 679 |
\hbox to 0pt{\hss\box0}\fi} |
| 680 |
\def \rnright@knit{\ifnum \passnum@knit < 3 \leavevmode |
| 681 |
\setbox0 = \hbox{\ifnum \passnum@knit = 2 \rncore@knit{right}\fi\rnstep@knit} |
| 682 |
\dimen0 = \wd0 %\advance \dimen0 -\rownumberwd |
| 683 |
\ifchartsonly\advance \dimen0 1pt\fi |
| 684 |
\ifdim \dimen0 > \rnrightwd@knit \global\rnrightwd@knit = \dimen0 \fi |
| 685 |
\hbox to 0pt{\box0\hss}\fi} |
| 686 |
|
| 687 |
\def \rnbox@knit#1{\ifnum \passnum@knit < 3 \leavevmode |
| 688 |
\hbox to \rownumberwd{\hss\ifnum \passnum@knit = 2 {\printrownumber{#1}}\fi\hss}\fi} |
| 689 |
\def \rnboxleft@knit#1{\ifnum \passnum@knit < 3 \leavevmode |
| 690 |
\setbox0 = \hbox{\ifnum \passnum@knit = 2 {\printleftrownumber{#1}}\fi} |
| 691 |
\dimen0 = \wd0 %\advance \dimen0 -\rownumberwd |
| 692 |
\ifchartsonly\advance \dimen0 1pt\fi |
| 693 |
\ifdim \dimen0 > \rnleftwd@knit \global\rnleftwd@knit = \dimen0 \fi |
| 694 |
\hbox to 0pt{\hss\box0}\fi} |
| 695 |
\def \rnboxright@knit#1{\ifnum \passnum@knit < 3 \leavevmode |
| 696 |
\setbox0 = \hbox{\ifnum \passnum@knit = 2 {\printrightrownumber{#1}}\fi} |
| 697 |
\dimen0 = \wd0 %\advance \dimen0 -\rownumberwd |
| 698 |
\ifchartsonly \advance \dimen0 1pt \fi |
| 699 |
\ifdim \dimen0 > \rnrightwd@knit \global\rnrightwd@knit = \dimen0 \fi |
| 700 |
\hbox to 0pt{\box0\hss}\fi} |
| 701 |
|
| 702 |
% Title for the chart |
| 703 |
\def\charttitle@knit{} |
| 704 |
\def\titlechart#1{\def\charttitle@knit{#1}} |
| 705 |
|
| 706 |
% The chart commands |
| 707 |
|
| 708 |
\def \chart{\futurelet\next@knit\chart@@knit} |
| 709 |
\def \chart@@knit{\ifx\next@knit[% |
| 710 |
\def\nextstep@knit{\smallpage@knit\obeylines \catcode`\|=\active \catcode`\# = 12 \chart@knit}\else |
| 711 |
\def\nextstep@knit{\smallpage@knit\obeylines \catcode`\|=\active \catcode`\# = 12 \chart@knit[]}\fi\nextstep@knit} |
| 712 |
|
| 713 |
% Some special stuff for chartsonly mode |
| 714 |
\let\extracommands@knit\relax |
| 715 |
\def \smallpage@knit{\noindent\hbox\bgroup} |
| 716 |
\let\endsmallpage@knit\egroup |
| 717 |
|
| 718 |
% The chart command proper |
| 719 |
\long\def\chart@knit[#1]#2{% |
| 720 |
\global \chartwidth@knit = 0pt |
| 721 |
\ifresetrn \rownumber = 0 \else \tempcount@knit = \rownumber \fi |
| 722 |
\setbox\bgbox@knit=\vbox{\def\passnum@knit{0}\hsize=\maxdimen |
| 723 |
\pf@knit |
| 724 |
\lineskip=0pt |
| 725 |
\parskip=0pt |
| 726 |
\baselineskip=0pt |
| 727 |
\parindent=0pt |
| 728 |
\emergencystretch = \stitchwd |
| 729 |
\leftskip=0pt |
| 730 |
\rightskip=0pt |
| 731 |
\parfillskip=0pt plus 1fil |
| 732 |
\ifresetrn\else\let\rnstep@knit\relax\fi |
| 733 |
\commands@knit\extracommands@knit |
| 734 |
\def\nonumber{\global\showrn@knitfalse}% |
| 735 |
\csname auto#1@knit\endcsname #2\par}% |
| 736 |
\ifresetrn \tempcount@knit = -\rownumber \fi |
| 737 |
\ifgrid |
| 738 |
\setbox\ggbox@knit=\vbox{\def\passnum@knit{1}\hsize=\maxdimen |
| 739 |
\gf@knit |
| 740 |
\lineskip=0pt |
| 741 |
\parskip=0pt |
| 742 |
\baselineskip=0pt |
| 743 |
\parindent=0pt |
| 744 |
\emergencystretch = \stitchwd |
| 745 |
\leftskip=0pt |
| 746 |
\rightskip=0pt |
| 747 |
\parfillskip=0pt plus 1fil |
| 748 |
\commands@knit\extracommands@knit |
| 749 |
\def\nonumber{\global\showrn@knitfalse}% |
| 750 |
\csname auto#1@knit\endcsname #2\par}% |
| 751 |
\fi |
| 752 |
\rownumber = \tempcount@knit % |
| 753 |
\global \rnleftwd@knit = 0pt |
| 754 |
\global \rnrightwd@knit = 0pt |
| 755 |
\setbox\fgbox@knit=\vbox{\def\passnum@knit{2}\hsize=\maxdimen |
| 756 |
\ff@knit |
| 757 |
\lineskip=0pt |
| 758 |
\parskip=0pt |
| 759 |
\baselineskip=0pt |
| 760 |
\parindent=0pt |
| 761 |
\emergencystretch = \stitchwd |
| 762 |
\leftskip=0pt |
| 763 |
\rightskip=0pt |
| 764 |
\parfillskip=0pt plus 1fil |
| 765 |
\commands@knit\extracommands@knit |
| 766 |
\def\nonumber{\global\showrn@knitfalse}% |
| 767 |
\csname auto#1@knit\endcsname #2\par}% |
| 768 |
\global\advance \chartwidth@knit \rnleftwd@knit |
| 769 |
\global\advance \chartwidth@knit \rnrightwd@knit |
| 770 |
\ifchartsonly \global\advance \chartwidth@knit 0.5\gridwidth \fi |
| 771 |
\hbox to \chartwidth@knit{\hskip \rnleftwd@knit |
| 772 |
\rlap{\purlgray \box\bgbox@knit}% |
| 773 |
\ifgrid\rlap{\gridcolor \box\ggbox@knit}\fi |
| 774 |
% |
| 775 |
\ifchartsonly |
| 776 |
\dimen2 = \dp \fgbox@knit \dimen3 = \ht \fgbox@knit |
| 777 |
\advance\dimen2 0.5\gridwidth \advance\dimen3 0.5\gridwidth |
| 778 |
\vrule width 0pt height \dimen3 depth \dimen2 |
| 779 |
\fi |
| 780 |
% If we are doing charts only, we want to enlarge things enough that |
| 781 |
% we can see the grid on all sides. |
| 782 |
% But if we aren't, we want adjacent charts to merge seamlessly |
| 783 |
% because using separate charts is the only way to allow charts to |
| 784 |
% break across pages. |
| 785 |
\vbox{% |
| 786 |
\ifx\empty\charttitle@knit\empty\else |
| 787 |
\hbox to \chartwidth@knit{\hskip \rnleftwd@knit\printcharttitle{\charttitle@knit}\hskip \rnrightwd@knit}\fi |
| 788 |
\box\fgbox@knit}% |
| 789 |
\hss}% |
| 790 |
\endsmallpage@knit |
| 791 |
\gdef\charttitle@knit{} |
| 792 |
} |
| 793 |
|
| 794 |
\def\printcharttitle#1{\hfil\vrule depth 3pt height 9pt width 0pt \relax #1\hfil} |
| 795 |
|
| 796 |
% Special charts only macros |
| 797 |
|
| 798 |
\newif \ifchartsonlysideways \chartsonlysidewaysfalse |
| 799 |
|
| 800 |
\def \chartsonly{\chartsonlytrue |
| 801 |
\ifpdf@knit\else\errmessage{Package knit error: \chartsonly should only be used with pdfTeX.}\fi% |
| 802 |
\hoffset=-1in |
| 803 |
\voffset=-1in |
| 804 |
\vsize = 120in |
| 805 |
\topskip = 0pt % Causes problems in one-row charts if this isn't present |
| 806 |
\def\smallpage{\vfil\break |
| 807 |
\global\chartwidth@knit=0pt |
| 808 |
\setbox0 = \vbox\bgroup |
| 809 |
\def\smallpage@knit{\let\endsmallpage@knit\egroup \noindent \hbox\bgroup}% |
| 810 |
} |
| 811 |
\def\endsmallpage{\egroup% |
| 812 |
\ifchartsonlysideways |
| 813 |
% |
| 814 |
\pdfpageheight=\wd0 |
| 815 |
% |
| 816 |
\dimen0=\ht0 \advance \dimen0 by \dp0 |
| 817 |
\pdfpagewidth=\dimen0 |
| 818 |
% |
| 819 |
\ifdim \pdfpagewidth > \vsize |
| 820 |
%{\newlinechar=`| |
| 821 |
%\message{||The chart ending on line \the\inputlineno\space is too big.} |
| 822 |
%\message{|Compensate by increasing \string\vsize\space or by breaking the chart into pieces.}% |
| 823 |
%\message{|What do you want such a big chart for, anyway?||}}% |
| 824 |
\fi |
| 825 |
% |
| 826 |
% Commands borrowed from samplepdf.tex |
| 827 |
\setbox1=\hbox{\copy0}% |
| 828 |
\wd1 = 0pt |
| 829 |
\ht1 = 0pt |
| 830 |
\dp1 = 0pt |
| 831 |
\vtop{\vskip\wd0 |
| 832 |
\leftline{\hskip-2pt\hskip\ht0\hskip\dp0% |
| 833 |
\pdfliteral{q 0 1 -1 0 0 0 cm}% |
| 834 |
\box1 |
| 835 |
\pdfliteral{Q}}} |
| 836 |
\else |
| 837 |
% |
| 838 |
\pdfpagewidth=\wd0 |
| 839 |
% |
| 840 |
\dimen0=\ht0 \advance \dimen0 by \dp0 |
| 841 |
\pdfpageheight=\dimen0 |
| 842 |
% |
| 843 |
\ifdim \pdfpageheight > \vsize |
| 844 |
%{\newlinechar=`| |
| 845 |
%\message{||The chart ending on line \the\inputlineno\space is too big.} |
| 846 |
%\message{Compensate by increasing \string\vsize\space or by breaking the chart into pieces.}% |
| 847 |
%\message{What do you want such a big chart for, anyway?||}}% |
| 848 |
\fi |
| 849 |
% |
| 850 |
\box0 |
| 851 |
\fi |
| 852 |
\vfil\break |
| 853 |
} |
| 854 |
\let\smallpage@knit\smallpage |
| 855 |
\let\endsmallpage@knit\endsmallpage |
| 856 |
\def\extracommands@knit{% |
| 857 |
\leftskip = 0.5\gridwidth |
| 858 |
\rightskip = 0.5\gridwidth |
| 859 |
%\vskip \gridwidth |
| 860 |
} |
| 861 |
} |
| 862 |
\let\smallpage\begingroup |
| 863 |
\let\endsmallpage\endgroup |
| 864 |
|
| 865 |
% Autonumbering macros |
| 866 |
|
| 867 |
\def \everypar@knit{\hskip\leftgap@knit \leftgap@knit=0pt \relax} |
| 868 |
|
| 869 |
\def \auto@knit{\let\nonumber\relax \everypar={\everypar@knit\do@endofpar@knit{\adjustchartwidth@knit}}} |
| 870 |
\def \autoleft@knit{\everypar={\everypar@knit\rnleft@knit\do@endofpar@knit{\adjustchartwidth@knit}}} |
| 871 |
\def \autoright@knit{\everypar={\everypar@knit\do@endofpar@knit{\rnright@knit\adjustchartwidth@knit}}} |
| 872 |
\def \autooddleft@knit{\everypar={\everypar@knit |
| 873 |
\ifodd \rownumber % |
| 874 |
\rnleft@knit\do@endofpar@knit{\adjustchartwidth@knit}% |
| 875 |
\else %\hskip\rownumberwd |
| 876 |
\do@endofpar@knit{\rnright@knit\adjustchartwidth@knit}\fi}} |
| 877 |
\def \autooddright@knit{\everypar={\everypar@knit |
| 878 |
\ifodd \rownumber %\hskip\rownumberwd |
| 879 |
\do@endofpar@knit{\rnright@knit\adjustchartwidth@knit}% |
| 880 |
\else\rnleft@knit\do@endofpar@knit{\adjustchartwidth@knit}\fi}} |
| 881 |
\def \autoboth@knit{\everypar={\everypar@knit\rnleft@knit\global\advance\rownumber 1 \do@endofpar@knit{\rnright@knit\adjustchartwidth@knit}}} |
| 882 |
\let\autoevenleft@knit\autooddright@knit |
| 883 |
\let\autoevenright@knit\autooddleft@knit |
| 884 |
|
| 885 |
\def \adjustchartwidth@knit{\endgraf |
| 886 |
\ifnum \passnum@knit = 2 \setbox0=\lastbox |
| 887 |
\setbox1=\hbox{\unhcopy0\unskip}% |
| 888 |
\box0 |
| 889 |
\ifdim\wd1 >\chartwidth@knit \global\chartwidth@knit=\wd1\fi\fi} |
| 890 |
|
| 891 |
% Stitch-counting macros |
| 892 |
|
| 893 |
\def \adjuststitchcount{\futurelet\next@knit\adjuststitchcount@knit} |
| 894 |
\def \adjuststitchcount@knit{\ifx\next@knit[% |
| 895 |
\def\nextstep@knit{\adjuststitchcount@@knit}\else |
| 896 |
\def\nextstep@knit{\adjuststitchcount@@knit[\relax]}\fi\nextstep@knit} |
| 897 |
\def \adjuststitchcount@@knit[#1]#2{% |
| 898 |
\leavevmode\ifnum\passnum@knit=3 \null |
| 899 |
\ifcountingout@knit \kern #2\stitchwd \else \ifx#1\relax \kern#2\stitchwd \else \kern #1\stitchwd \fi \fi \null\fi} |
| 900 |
|
| 901 |
\def \stitchcountwarningbar{% |
| 902 |
\ifnum \stitchcountinprev = \stitchcountout \else |
| 903 |
\ifnum \stitchcountinprev > -99 |
| 904 |
\vrule width \overfullrule |
| 905 |
\message{Package knit warning: Stitch count mismatch on input line \the\inputlineno.} |
| 906 |
\fi \fi} |
| 907 |
|
| 908 |
\def \countstitches#1{% |
| 909 |
\global\stitchcountinprev = \stitchcountin |
| 910 |
\setbox0 = \hbox{\def\passnum@knit{3}\countingout@knittrue \let\stitchwd\stitchwd@count@knit \stsout@knit #1}% |
| 911 |
\stitchcountout = \wd0 |
| 912 |
\dimen0 = 0.5\stitchwd@count@knit \advance \stitchcountout \dimen0 |
| 913 |
\global\divide \stitchcountout \stitchwd@count@knit |
| 914 |
\setbox1 = \hbox{\def\passnum@knit{3}\countingout@knitfalse \let\stitchwd\stitchwd@count@knit \stsin@knit #1}% |
| 915 |
\stitchcountin = \wd1 |
| 916 |
\dimen1 = 0.5\stitchwd@count@knit \advance \stitchcountin \dimen1 |
| 917 |
\global\divide \stitchcountin \stitchwd@count@knit |
| 918 |
} |
| 919 |
|
| 920 |
\def \stitchcountchart{\futurelet\next@knit\stitchcountchart@knit} |
| 921 |
\def \stitchcountchart@knit{\ifx\next@knit[% |
| 922 |
\def\nextstep@knit{\stitchcountchart@@knit}\else |
| 923 |
\def\nextstep@knit{\stitchcountchart@@knit[]}\fi\nextstep@knit} |
| 924 |
\def \stitchcountchart@@knit[#1]{\begingroup \catcode`\|=\active \catcode`\# = 12 \def\chartrn@knit{#1}\obeylines \afterassignment \printstitchcountchart@knit \toks0 =} |
| 925 |
|
| 926 |
\def \printstitchcountchart@knit{\smallpage@knit\hbox{% |
| 927 |
\ifx\relax\printleftstitchcount\else\ifx \empty \printleftstitchcount\else |
| 928 |
\let\printstitchcount@knit\printleftstitchcount |
| 929 |
\def\stitchcountside@knit{0}\makestitchcounts@knit \fi\fi |
| 930 |
\chart[\chartrn@knit]{\the\toks0}% |
| 931 |
\ifx\relax\printrightstitchcount\else\ifx \empty \printrightstitchcount\else |
| 932 |
\let\printstitchcount@knit\printrightstitchcount |
| 933 |
\def\stitchcountside@knit{1}\makestitchcounts@knit\fi\fi |
| 934 |
}\endsmallpage@knit |
| 935 |
\endgroup} |
| 936 |
|
| 937 |
{\obeylines |
| 938 |
\gdef\countstitcheseachrow@knit#1^^M{% |
| 939 |
\setbox1 = \hbox{#1}% |
| 940 |
\ifCountStsThisRow@knit% |
| 941 |
\countstitches{#1}% |
| 942 |
\setstitchcountlabel@knit% |
| 943 |
\else% |
| 944 |
\global\CountStsThisRow@knittrue% |
| 945 |
\setbox0=\hbox{}% |
| 946 |
\fi% |
| 947 |
\printstitchcountlabel@knit} |
| 948 |
\gdef\shortrows@countstitcheseachrow@knit#1^^M{\countstitches{#1} % |
| 949 |
\ifx \relax \shortrowrowcount@knit % |
| 950 |
\global\advance \shortrowstsin@knit \stitchcountin \global\advance \shortrowstsout@knit \stitchcountout % |
| 951 |
\global\let \shortrowrowcount@knit 2 |
| 952 |
% For some reason, we MUST NOT have a % after the 2. |
| 953 |
\else% |
| 954 |
\global\advance \shortrowstsin@knit -\stitchcountout \global\advance \shortrowstsout@knit -\stitchcountin % |
| 955 |
\global\let \shortrowrowcount@knit \relax |
| 956 |
\fi% |
| 957 |
\global\stitchcountin = \stitchcountinprev % |
| 958 |
} |
| 959 |
\gdef\shortrows@printstitchcountlabel@knit#1^^M{\setbox1 = \hbox{#1}\printstitchcountlabel@knit\setbox0=\hbox{}} |
| 960 |
\gdef\shortrows#1{% |
| 961 |
\ifnum \passnum@knit = 3 |
| 962 |
\shortrowstsin@knit = 0 \shortrowstsout@knit = 0 \global\let \shortrowrowcount@knit \relax % |
| 963 |
\setbox2 = \vbox{\everypar = {\shortrows@countstitcheseachrow@knit}% |
| 964 |
#1 |
| 965 |
}% |
| 966 |
\ifx \shortrowrowcount@knit \relax |
| 967 |
\advance \stitchcountin \shortrowstsin@knit \advance \stitchcountin -\shortrowstsout@knit % |
| 968 |
\else |
| 969 |
\stitchcountinprev = \stitchcountin \stitchcountin = \shortrowstsin@knit \stitchcountout = \shortrowstsout@knit % |
| 970 |
\fi % |
| 971 |
\setstitchcountlabel@knit% |
| 972 |
\vbox{\everypar = {\shortrows@printstitchcountlabel@knit}% |
| 973 |
\ifx \shortrowrowcount@knit \relax \setbox0=\hbox{} \else |
| 974 |
\ifCountStsThisRow@knit\else \setbox0=\hbox{} \global\CountStsThisRow@knittrue \fi \fi |
| 975 |
#1 |
| 976 |
}% |
| 977 |
\else% |
| 978 |
#1 |
| 979 |
\fi% |
| 980 |
\par} |
| 981 |
} |
| 982 |
|
| 983 |
\def\setstitchcountlabel@knit{\setbox0=\hbox{\def\passnum@knit{2}\strut@knit \printstitchcount@knit\stitchcountwarningbar}} |
| 984 |
\def\printstitchcountlabel@knit{\ifdim \wd0 > \stitchcountwidth@knit \global\stitchcountwidth@knit = \wd0 \fi |
| 985 |
\hbox to 0pt{\ifnum\stitchcountside@knit = 0 \hss\fi |
| 986 |
\vrule width 0pt height \ht1 depth \dp1 \smash{\box0}% |
| 987 |
\ifnum\stitchcountside@knit = 1 \hss\fi}% |
| 988 |
\par} |
| 989 |
|
| 990 |
\def\makestitchcounts@knit{\hbox{\setbox1=\vbox{\stitchcountin = -1001 |
| 991 |
\global\stitchcountwidth@knit=0pt |
| 992 |
\global\CountStsThisRow@knittrue |
| 993 |
\parindent=0pt |
| 994 |
\def\passnum@knit{3} |
| 995 |
\def\doifcounting@knit##1{##1} |
| 996 |
\ff@knit |
| 997 |
\commands@knit |
| 998 |
\everypar={\countstitcheseachrow@knit} \offinterlineskip |
| 999 |
\the\toks0 |
| 1000 |
}% |
| 1001 |
\ifnum\stitchcountside@knit = 0 |
| 1002 |
\hskip \stitchcountwidth@knit\rlap{\box1}% |
| 1003 |
\else |
| 1004 |
\rlap{\box1}\hskip \stitchcountwidth@knit |
| 1005 |
\fi |
| 1006 |
}} |
| 1007 |
|
| 1008 |
\def\nostitchcount{\ifnum \passnum@knit = 3 \global \CountStsThisRow@knitfalse \fi} |
| 1009 |
|
| 1010 |
\def \knitdebug{\def \printleftstitchcount{{\rncolor \knitrm(\the\stitchcountout\ out, \the\stitchcountin\ in) }}} |
| 1011 |
|
| 1012 |
\def \printleftstitchcount{{\rncolor \knitrm(\the\stitchcountout\ sts) }} |
| 1013 |
\def \printrightstitchcount{} |
| 1014 |
|
| 1015 |
\def \knitdebugging{\def \printleftstitchcount{{\rncolor \knitrm(\the\stitchcountout\ out/\the\stitchcountin\ in) }}} |
| 1016 |
|
| 1017 |
\catcode`\@=\catcountknit |
| 1018 |
|