Debian Codegraph @

texmf-dist/tex/latex/knitting/knitting.sty

raw
1 % knitting.sty
2 %
3 % Provides commands useful for writing knitting patterns in LaTeX,
4 % including commands to typeset knit charts, and to switch to larger
5 % pages mid-document.
6 %
7 % author: Ariel Barton
8 %
9 % Copyright Ariel Barton, 2010
10 %
11 % This work may be distributed and/or modified under the
12 % conditions of the LaTeX Project Public License, either
13 % version 1.3 of this license or (at your option) any
14 % later version.
15 % The latest version of the license is in
16 % http://www.latex-project.org/lppl.txt
17 % and version 1.3 or later is part of all distributions of
18 % LaTeX version 2003/06/01 or later.
19 %
20 % This work has the LPPL maintenance status "author-maintained".
21 %
22 % The complete list of files considered part of this work is in
23 % the file `knitting-doc.pdf' and its source code `knitting-doc.tex'.
24 %
25 % Version: 3
26
27 \ProvidesPackage{knitting}[2019/04/03]
28
29 %\pdfmapfile{+knitfont.map}
30
31 %
32 % Boolean variables
33 %
34
35 \newif \ifchartsonly \chartsonlyfalse
36 \newif \ifgrid
37 \newif \ifknitsymbol
38 \newif \ifresetrn \resetrntrue
39 \newif \ifleftrn@knit
40 \newif \ifshowrn@knit \showrn@knittrue
41 \newif \ifpdf@knit
42 \newif \ifcountingout@knit
43 \newif \ifCountStsThisRow@knit \CountStsThisRow@knittrue
44 \pdf@knittrue
45 \ifx \pdfoutput \undefined \pdf@knitfalse \fi
46 \ifx \pdfoutput \relax \pdf@knitfalse \fi
47
48 %
49 % Color commands
50 %
51
52 \RequirePackage{color}
53
54 \definecolor{purlgray}{gray}{0.65}
55 \definecolor{knitlinecolor}{rgb}{0.7,0,0}
56 \definecolor{gridcolor}{gray}{0.3}
57 \definecolor{forecolor}{gray}{0}
58 \definecolor{rncolor}{rgb}{0.6,0,0}
59 \definecolor{rnarrowcolor}{rgb}{0.45,0,0}
60
61 %
62 % LaTeX-only material (options and fullpages)
63 %
64
65 \DeclareOption{chartsonly}{\chartsonlytrue}
66
67 \ProcessOptions
68
69 % Every dimension I could think of affecting the
70 % main page body. It's an environment instead of a command since I want
71 % a way to switch back to normal pages. Dimensions I don't change are
72 % \marginparsep,\marginparwidth,\marginparpush,\paperheight,\paperwidth
73
74 \newenvironment{fullpages}{
75 \clearpage
76 \pagestyle{plain}
77 \setlength{\hoffset}{0pt}
78 \setlength{\voffset}{0pt}
79 \setlength{\oddsidemargin}{0pt}
80 \setlength{\evensidemargin}{0pt}
81 \setlength{\topmargin}{0pt}
82 \setlength{\headheight}{0pt}
83 \setlength{\headsep}{0pt}
84 \setlength{\textheight}{\paperheight}
85 \addtolength{\textheight}{-\footskip}
86 \addtolength{\textheight}{-2in}
87 \setlength{\textwidth}{\paperwidth}
88 \addtolength{\textwidth}{-2in}
89 % This next bit is borrowed from Peter Wilson's chngpage.sty
90 % package. I didn't want to just \usepackage{chngpage} because it
91 % behaves like \addtolength and I wanted \setlength, and loading the
92 % whole package for one eight-line snippet of code just seemed
93 % needlessly complicated.
94 \setlength{\@colht}{\textheight}\setlength{\@colroom}{\textheight}%
95 \setlength{\vsize}{\textheight}\setlength{\columnwidth}{\textwidth}%
96 \if@twocolumn%
97 \advance\columnwidth-\columnsep \divide\columnwidth\tw@%
98 \@firstcolumntrue%
99 \fi%
100 \setlength{\hsize}{\columnwidth}%
101 \setlength{\linewidth}{\hsize}%
102 }
103 {\clearpage}
104
105 %
106 % Dimensions
107 %
108
109 \newlength \leftgap@knit
110 \newlength \bgshift@knit
111 \newlength \chartwidth@knit
112 \newlength \stitchcountwidth@knit
113 \newlength \rnleftwd@knit
114 \newlength \rnrightwd@knit
115
116 \newbox\bgbox@knit
117 \newbox\fgbox@knit
118 \newbox\ggbox@knit
119
120 \newcounter{rownumber}
121 \newcounter{tempcount@knit}
122 \newcounter{rownumberskip} \c@rownumberskip = 1
123 \newcounter{stitchcountin}
124 \newcounter{stitchcountinprev}
125 \newcounter{stitchcountout}
126 \newcounter{shortrowstsin@knit}
127 \newcounter{shortrowstsout@knit}
128
129 \newcommand \passnum@knit{2}
130 \newcommand \stitchwd{\fontdimen6\csname U/knit/\series@knit/n/\f@size\endcsname}
131 \newcommand \stitchwd@count@knit{\fontdimen6\csname U/knit/\series@knit/out/\f@size\endcsname}
132 \newcommand \stitchdp{\fontdimen8\csname U/knit/\series@knit/n/\f@size\endcsname}
133 \newcommand \stitchht{\fontdimen9\csname U/knit/\series@knit/n/\f@size\endcsname}
134 \newcommand \gridwidth{\fontdimen10\csname U/knit/\series@knit/n/\f@size\endcsname}
135 \newcommand \knitlinewd{\fontdimen11\csname U/knit/\series@knit/n/\f@size\endcsname}
136 \newcommand \narrowincraise@knit{\fontdimen12\the\font}
137 \newcommand \fontvoffset@knit{\fontdimen13\the\font}
138 \newcommand \purlextend@knit{\fontdimen14\csname U/knit/\series@knit/n/\f@size\endcsname}
139 \newcommand \rownumberwd{\fontdimen6\csname U/knit/\series@knit/n/10\endcsname}
140 % The rest of them aren't \the\font because I want them to still work outside of a chart
141
142 %
143 % Fonts
144 %
145
146 \newcommand \ff@knit{\fontencoding{U}\fontfamily{knit}\fontseries{\series@knit}\fontshape{n}\selectfont}
147 \newcommand \gf@knit{\fontencoding{U}\fontfamily{knit}\fontseries{\series@knit}\fontshape{g}\selectfont}
148 \newcommand \pf@knit{\fontencoding{U}\fontfamily{knit}\fontseries{\series@knit}\fontshape{p}\selectfont}
149 \newcommand \raiseff@knit{\fontencoding{U}\fontfamily{knit}\fontseries{\series@knit}\fontshape{r}\selectfont}
150 \newcommand \lowerff@knit{\fontencoding{U}\fontfamily{knit}\fontseries{\series@knit}\fontshape{l}\selectfont}
151
152 \DeclareTextFontCommand {\knitsfsmall@knit}{\dimen0=\f@size pt\fontfamily{cmss}\fontseries{m}\fontshape{n}\fontsize{0.8\dimen0}{\f@baselineskip}\selectfont}
153 \DeclareTextFontCommand {\cablesf@knit}{\dimen0=\f@size pt\fontfamily{cmss}\fontseries{m}\fontshape{n}\fontsize{0.8\dimen0}{\f@baselineskip}\selectfont}
154 \DeclareTextFontCommand{\cablesfsmall@knit}{\dimen0=\f@size pt\fontfamily{cmss}\fontseries{m}\fontshape{n}\fontsize{0.6\dimen0}{\f@baselineskip}\selectfont}
155
156 % Some extra effort (the {\ff@knit}) is made to make sure that the fonts actually exist.
157 % This is done so that the fonts are defined before they are used,
158 % which is necessary to make \gridwidth work
159 \newcommand \knitnogrid{\gridfalse\knitsymboltrue \def\series@knit{n}{\ff@knit}}
160 \newcommand \knitgrid{\gridtrue \knitsymbolfalse\def\series@knit{g}{\ff@knit}}
161 \newcommand \knitwide{\gridtrue \knitsymbolfalse\def\series@knit{w}{\ff@knit}}
162 \newcommand \knitmixed{\gridtrue \knitsymboltrue \def\series@knit{m}{\ff@knit}}
163
164 \knitgrid
165
166 %
167 % Single-pass commands
168 %
169
170 \newcommand \purlpass[2][]{\ifnum\passnum@knit = 0 #2\else #1\fi}
171 \newcommand \gridpass[2][]{\ifnum\passnum@knit = 1 #2\else #1\fi}
172 \newcommand \mainpass[2][]{\ifnum\passnum@knit = 2 #2\else #1\fi}
173 \newcommand \countpass[2][]{\ifnum\passnum@knit = 3 #2\else #1\fi}
174
175 %
176 % Text knit
177 %
178
179 \newcommand \textknit[1]{\mbox{\let\|\bar@knit\let\!\barthin@knit
180 \ff@knit \color{forecolor}%
181 \rlap{\pf@knit \color{purlgray}\def\passnum@knit{0}#1}%
182 \ifgrid\rlap{\gf@knit \color{gridcolor}\def\passnum@knit{1}#1}\fi
183 \def\passnum@knit{2}#1}}
184
185 \newcommand \do@endofpar@knit[1]{\def\par{#1\endgraf\let\par\endgraf}}
186
187 %
188 % Special symbols
189 %
190
191 \newcommand \narrowdecrease[1]{\genbobble@knit{#1}{1}{-\narrowincraise@knit}\adjuststitchcount[#1]{0}\adjuststitchcount[-1]{0}}
192 \newcommand \pnarrowdecrease[1]{\genbobble@knit{#1}{2}{-\narrowincraise@knit}\adjuststitchcount[#1]{0}\adjuststitchcount[-1]{0}}
193 \newcommand \narrowincrease[1]{\genbobble@knit{#1}{3}{\narrowincraise@knit}\adjuststitchcount[0]{#1}\adjuststitchcount[0]{-1}}
194 \newcommand \pnarrowincrease[1]{\genbobble@knit{#1}{4}{\narrowincraise@knit}\adjuststitchcount[0]{#1}\adjuststitchcount[0]{-1}}
195 \newcommand \bobble[1]{\genbobble@knit{#1}{0}{0pt}}
196
197 \newcommand \genbobble@knit[3]{\char#2 \ifnum \passnum@knit = 2
198 \llap{\lower \stitchdp \vbox to\stitchht{\vss \vskip\fontvoffset@knit \hbox to \stitchwd{\hfil\knitsfsmall@knit{#1}\hfil}\vskip #3\vss}}\fi}
199
200
201 \newcommand \wideincrease[1]{\strut@knit
202 \ifnum\passnum@knit = 3 \narrowincrease{#1}\else
203 \hbox to #1\stitchwd{\char25
204 \hskip-0.1pt\leaders\hbox{\char22}\hfil\hskip-0.1pt
205 \char29
206 \hskip-0.1pt\leaders\hbox{\char22}\hfil\hskip-0.1pt
207 \char26}\fi}
208 \newcommand \widedecrease[1]{\strut@knit
209 \ifnum #1 = 5 \char31 \else
210 \ifnum\passnum@knit = 3 \narrowdecrease{#1}\else
211 \hbox to #1\stitchwd{\char27
212 \hskip-0.1pt\leaders\hbox{\char22}\hfil\hskip-0.1pt
213 \char30
214 \hskip-0.1pt\leaders\hbox{\char22}\hfil\hskip-0.1pt
215 \char28}\fi\fi}
216
217 % Standard chart commands
218
219 % \obeylines is normally defined with \let^^M\par, not \def^^M{\par};
220 % doing it this way makes it cooperate with \do@endofpar.
221
222 {\catcode`\^^M = \active \catcode`\| = \active
223 \global\def\commands@knit{%
224 \setlength{\fboxsep}{0pt}%
225 \let\[\pnarrowincrease
226 \let\]\pnarrowdecrease
227 \let\<\narrowincrease
228 \let\>\narrowdecrease
229 \let\@\bobble
230 \let \! \barthin@knit
231 \let \| \bar@knit
232 \let | \bar@knit
233 \let \_ \horizlinenarrow@knit
234 \let \= \horizlinewide@knit
235 \let \- \horizline@knit
236 \let\overline\overline@knit
237 \let\underline\underline@knit
238 \let\rn\rn@knit
239 \let\rnbox\rnbox@knit
240 \let\rnboxleft\rnboxleft@knit
241 \let\rnboxright\rnboxright@knit
242 \let\rnleft\rnleft@knit
243 \let\rnright\rnright@knit
244 \let\nonumber\relax
245 \let\par\endgraf %Just in case someone's redefined it
246 \leftgap@knit=0pt
247 \def~{\ifnum\passnum@knit=3 \else \ifvmode \advance \leftgap@knit by \stitchwd
248 \else \kern \stitchwd \fi \fi}%
249 \def^^M{\par}%
250 \def\\{\par}%
251 }%
252 }
253
254 \newcommand \strut@knit{\rule[-\stitchdp]{0pt}{\stitchht}}
255
256 % Drawing lines on the chart
257
258 \newcommand \horizlinenarrow@knit{\ifnum\passnum@knit<3 \ifvmode\nonumber\leavevmode\fi \dimen0 = \stitchwd \advance \dimen0 \knitlinewd
259 \ifnum\passnum@knit = 2
260 \hskip -0.5\knitlinewd\smash{{\color{knitlinecolor}\vrule width \dimen0 height 0.5\knitlinewd depth 0.5\knitlinewd}}\hskip -0.5\knitlinewd
261 \else\hskip \stitchwd \fi\fi}
262 \newcommand \horizlinewide@knit[1]{\ifnum\passnum@knit<3 \ifvmode\nonumber\leavevmode\fi \dimen0 = #1\stitchwd \advance \dimen0 \knitlinewd
263 \ifnum\passnum@knit = 2
264 \smash{{\color{knitlinecolor}\vrule width \dimen0 height 0.5\knitlinewd depth 0.5\knitlinewd}}
265 \else\hskip \dimen0 \fi\fi}
266
267 \newcommand \horizline@knit{\@ifstar \horizlinestar@knit \horizlinenostar@knit}
268
269 \newcommand \horizlinestar@knit[1]{\nonumber\nostitchcount\overlinestar@knit{\hskip#1\stitchwd}}
270 \newcommand \horizlinenostar@knit[1]{\nonumber\nostitchcount\overlinenostar@knit{\hskip#1\stitchwd}}
271
272
273 \newcommand \bar@knit{\ifnum\passnum@knit < 3 \leavevmode
274 \ifgrid
275 \ifnum \passnum@knit = 0
276 \hbox{\color{knitlinecolor}\rule[-\stitchdp]{\knitlinewd}{\stitchht}}%
277 \else
278 \kern \knitlinewd
279 \fi
280 \else
281 \ifnum \passnum@knit = 2
282 \hbox{\color{knitlinecolor}\rule[-\stitchdp]{\knitlinewd}{\stitchht}}%
283 \else
284 \kern \knitlinewd
285 \fi
286 \fi\fi}
287
288 \newcommand \barthintop@knit{0pt}
289 \newcommand \barthinbot@knit{0pt}
290
291 \newcommand \barthin@knit{\leavevmode\strut@knit
292 \ifnum \passnum@knit = 2
293 \dimen2 = \stitchht \advance \dimen2 \barthintop@knit
294 \advance \dimen2 \barthinbot@knit
295 \dimen3 = \stitchdp \advance \dimen3 \barthinbot@knit
296 \smash{\hbox to 0pt{\hss \color{knitlinecolor}\rule[-\dimen3]{\knitlinewd}{\dimen2}\hss}}%
297 \fi}
298
299 \newcommand \overline@knit{\@ifstar \overlinestar@knit \overlinenostar@knit}
300 \newcommand \underline@knit{\@ifstar \underlinestar@knit \underlinenostar@knit}
301
302 \newcommand \overlinenostar@knit[1]{\leavevmode{\def\barthintop@knit{\knitlinewd}%
303 \setbox0 = \hbox{#1}%
304 \ifgrid
305 \ifnum \passnum@knit = 0
306 \dimen1=\wd0 \advance\dimen1 by \gridwidth
307 {\rlap{\hskip -0.5\gridwidth\color{knitlinecolor}\rule[\ht0]{\dimen1}{\knitlinewd}}}
308 \else
309 \rule[\ht0]{0pt}{\knitlinewd}
310 \fi
311 \else
312 \ifnum \passnum@knit = 2
313 \dimen1=\wd0 \advance\dimen1 by \gridwidth
314 {\rlap{\hskip -0.5\gridwidth\color{knitlinecolor}\rule[\ht0]{\dimen1}{\knitlinewd}}}%
315 \else
316 \rule[\ht0]{0pt}{\knitlinewd}
317 \fi \fi
318 #1}}
319
320 \newcommand \overlinestar@knit[1]{\leavevmode{\def\barthintop@knit{0.5\knitlinewd}%
321 \setbox0 = \hbox{#1}%
322 \ifnum \passnum@knit = 2
323 \dimen1=\wd0 \advance\dimen1 by \gridwidth
324 \dimen2=\ht0 \advance\dimen2 by -0.5\knitlinewd
325 \smash{\rlap{\hskip -0.5\gridwidth\color{knitlinecolor}\rule[\dimen2]{\dimen1}{\knitlinewd}}}%
326 \fi
327 #1}}
328
329 \newcommand \underlinenostar@knit[1]{\leavevmode{\def\barthinbot@knit{\knitlinewd}%
330 \setbox0 = \hbox{#1}%
331 \ifgrid
332 \ifnum \passnum@knit = 0
333 \dimen1=\wd0 \advance\dimen1 by \gridwidth
334 \rlap{\raisebox{-\dp0}{\hskip -0.5\gridwidth\color{knitlinecolor}\rule[-\knitlinewd]{\dimen1}{\knitlinewd}\hskip -0.5\gridwidth}}%
335 \else
336 \rlap{\raisebox{-\dp0}{\vrule width 0pt height 0pt depth \knitlinewd}}%
337 \fi
338 \else
339 \ifnum \passnum@knit = 2
340 \dimen1=\wd0 \advance\dimen1 by \gridwidth
341 \rlap{\raisebox{-\dp0}{\hskip -0.5\gridwidth\color{knitlinecolor}\rule[-\knitlinewd]{\dimen1}{\knitlinewd}\hskip -0.5\gridwidth}}%
342 \else
343 \rlap{\raisebox{-\dp0}{\vrule width 0pt height 0pt depth \knitlinewd}}%
344 \fi \fi
345 #1}}
346
347 \newcommand \underlinestar@knit[1]{\leavevmode{\def\barthinbot@knit{0.5\knitlinewd}%
348 \setbox0 = \hbox{#1}%
349 \ifnum \passnum@knit = 2
350 \dimen1=\wd0 \advance\dimen1 by \gridwidth
351 \smash{\rlap{\raisebox{-\dp0}{\hskip -0.5\gridwidth\color{knitlinecolor}\rule[-0.5\knitlinewd]{\dimen1}{\knitlinewd}}\hskip -0.5\gridwidth}}%
352 \fi
353 #1}}
354
355 % Fancy cabling
356
357 % \ifnum \passnum@knit = 3 \leavevmode \fi causes problems
358 % due to the weird things we do automatically at the start of a paragraph
359 \def\doifcounting@knit#1{}
360
361 \def\cablebackground#1{\doifcounting@knit{\leavevmode}%
362 \ifnum \passnum@knit = 0 \leavevmode \hbox to \stitchwd{#1\hss {\raiseff@knit \def\passnum@knit{2}\color{forecolor}#1}}\else \char255 \fi}
363 \def\cableforeground#1{\doifcounting@knit{\leavevmode}%
364 \ifnum \passnum@knit = 0 \leavevmode \hbox to \stitchwd{#1\hss {\lowerff@knit \def\passnum@knit{2}\color{forecolor}#1}}\else \char254 \fi}
365
366 \def\orphancablewarning@knit{\typeout{Package knit warning: Orphaned half cable on input line \the\inputlineno.}}
367
368 \newcommand \cableleft[2]{\leavevmode{\ifgrid\knitmixed\fi
369 \ifcase\passnum@knit
370 \hbox{\pf@knit #1#2}%
371 \or
372 \setbox0=\hbox{\pf@knit #1#2}%
373 \hbox to \wd0{\char6\leaders\hbox{\char5}\hfil\char6}%
374 \or
375 \hbox{\let \textsf \cablesf@knit \let \knitsfsmall@knit \cablesfsmall@knit %
376 \setbox1=\hbox{#1}%
377 \setbox2=\hbox{#2}%
378 \ifdim \wd1 = 0pt \orphancablewarning@knit \fi
379 \ifdim \wd2 = 0pt \orphancablewarning@knit \fi
380 {\lowerff@knit \rlap{#1}\hbox to \wd1{\leaders\hbox to \stitchwd{\hfil\char15}\hfil\ifdim\wd1>0pt \hskip\stitchwd\char10\fi}%
381 \ifdim\wd1>0pt \ifdim \wd2>0pt \char13\fi \fi }%
382 {\raiseff@knit \rlap{#2}\hbox to \wd2{\ifdim\wd2>0pt \char12\hskip\stitchwd\fi\leaders\hbox to \stitchwd{\char8\hfil}\hfil}}}%
383 \else
384 #1#2\fi}}
385 \newcommand \cableright[2]{\leavevmode{\ifgrid\knitmixed\fi
386 \ifcase\passnum@knit
387 \hbox{\pf@knit #1#2}%
388 \or
389 \setbox0=\hbox{\pf@knit #1#2}%
390 \hbox to \wd0{\char6\leaders\hbox{\char5}\hfil\char6}%
391 \or
392 \hbox{\let\textsf \cablesf@knit \let \knitsfsmall@knit \cablesfsmall@knit %
393 \setbox1=\hbox{#1}%
394 \setbox2=\hbox{#2}%
395 \ifdim \wd1 = 0pt \orphancablewarning@knit \fi
396 \ifdim \wd2 = 0pt \orphancablewarning@knit \fi
397 {\raiseff@knit \rlap{#1}\hbox to \wd1{\leaders\hbox to \stitchwd{\hfil\char16}\hfil\ifdim\wd1>0pt \hskip\stitchwd\char9\fi}%
398 \ifdim\wd1>0pt \ifdim \wd2>0pt \char14\fi \fi }%
399 {\lowerff@knit \rlap{#2}\hbox to \wd2{\ifdim\wd2>0pt \char11\hskip\stitchwd \fi\leaders\hbox to \stitchwd{\char7\hfil}\hfil}}}%
400 \else
401 #1#2\fi}}
402
403 % Knit, purl, knitboxes
404
405 \newcommand \knit[1]{\strut@knit\hbox to #1\stitchwd{\leaders\hbox{-}\hfil}}
406 \newcommand \purl[1]{\strut@knit\hbox to #1\stitchwd{\leaders\hbox{=}\hfil}}
407
408 \newcommand \knitboxbackground{}
409 \newcommand \purlboxbackground{\color{purlgray}}
410 \newcommand \purlboxforeground{}
411 \newcommand \knitboxforeground{}
412
413 \newcommand \Knit[3][0]{\strut@knit%
414 \setbox0 = \hbox{\fontseries{m}\fontshape{n}\textsf{#2}}%
415 \ifcase \passnum@knit
416 \ifx \empty@knit \knitboxbackground
417 \rule{#3\stitchwd}{0pt}%
418 \else
419 {\knitboxbackground \purlbackground{\rule[-\stitchdp]{#3\stitchwd}{\stitchht}}}\fi
420 \or
421 \ifknitsymbol
422 \hbox to #3\stitchwd{\char6\leaders\hbox{\char5}\hfil\char6}%
423 \else
424 \hbox{\hbox to #3\stitchwd{%
425 \leaders \hbox to \stitchwd{\char6\hfil\char6}\hfil
426 \hskip \wd0
427 \leaders \hbox to \stitchwd{\char6\hfil\char6}\hfil}%
428 \hskip -#3\stitchwd
429 \hbox to #3\stitchwd{\char6\leaders\hbox{\char5}\hfil\char6}}%
430 \fi
431 \or
432 \hbox to #3\stitchwd{%
433 {\knitboxforeground\leaders\hbox{-}%
434 \ifnum #1>0 \hskip #1\stitchwd plus 1fil minus #1\stitchwd \else\hfil\fi
435 }%
436 \lower\stitchdp\vbox to\stitchht{\vss\vskip\fontvoffset@knit\hbox{\fontseries{m}\fontshape{n}\textsf{#2}}\vss}
437 {\knitboxforeground \count255 = -#1 \leaders\hbox{-}%
438 \ifnum #1<0 \hskip \count255\stitchwd plus 1fil minus \count255\stitchwd \else\hfil\fi
439 }}%
440 \or
441 \hbox to \Knitstitchcount{#2}{#3}\stitchwd{\hfil}
442 \fi}
443 \newcommand \Purl[3][0]{\strut@knit%
444 \setbox0 = \hbox{\fontseries{m}\fontshape{n}\textsf{#2}}%
445 \ifcase \passnum@knit
446 \ifx \empty@knit \purlboxbackground
447 \rule{#3\stitchwd}{0pt}%
448 \else
449 {\purlboxbackground \purlbackground{\rule[-\stitchdp]{#3\stitchwd}{\stitchht}}}\fi
450 \or
451 \ifknitsymbol
452 \hbox to #3\stitchwd{\char6\leaders\hbox{\char5}\hfil\char6}%
453 \else
454 \hbox{\hbox to #3\stitchwd{%
455 \leaders \hbox to \stitchwd{\char6\hfil\char6}\hfil
456 \hskip \wd0
457 \leaders \hbox to \stitchwd{\char6\hfil\char6}\hfil}%
458 \hskip -#3\stitchwd
459 \hbox to #3\stitchwd{\char6\leaders\hbox{\char5}\hfil\char6}}%
460 \fi
461 \or
462 \hbox to #3\stitchwd{%
463 {\purlboxforeground\leaders\hbox{=}%
464 \ifnum #1>0 \hskip #1\stitchwd plus 1fil minus #1\stitchwd \else\hfil\fi
465 }%
466 \lower\stitchdp\vbox to\stitchht{\vss\vskip\fontvoffset@knit\hbox{\fontseries{m}\fontshape{n}\textsf{#2}}\vss}
467 {\purlboxforeground \count255 = -#1 \leaders\hbox{=}%
468 \ifnum #1<0 \hskip \count255\stitchwd plus 1fil minus \count255\stitchwd \else\hfil\fi
469 }}%
470 \or
471 \hbox to \Purlstitchcount{#2}{#3}\stitchwd{\hfil}
472 \fi}
473
474 \newcommand \Knitstitchcount[2]{#2}
475 \newcommand \Purlstitchcount[2]{#2}
476 \newcommand \knitboxstitchcount[2]{#2}
477 \newcommand \purlboxstitchcount[2]{#2}
478
479 \newcommand \knitbox[3][0]{\strut@knit%
480 \ifcase \passnum@knit
481 \ifx \empty@knit \knitboxbackground
482 \rule{#3\stitchwd}{0pt}%
483 \else
484 {\knitboxbackground \purlbackground{\rule[-\stitchdp]{#3\stitchwd}{\stitchht}}}\fi
485 \or
486 \hbox to #3\stitchwd{\char6\leaders\hbox{\char5}\hfil\char6}%
487 \or
488 \lower\stitchdp\vbox to\stitchht{%
489 \vss\vskip\fontvoffset@knit
490 \hbox to #3\stitchwd{\ifnum #1>0 \hskip #1\stitchwd plus 1fil minus #1\stitchwd \else\hfil\fi
491 {\fontseries{m}\fontshape{n}\textsf{#2}}%
492 \count255 = -#1 \ifnum #1<0 \hskip \count255\stitchwd plus 1fil minus \count255\stitchwd \else\hfil\fi}%
493 \vss}%
494 \or
495 \hbox to \knitboxstitchcount{#2}{#3}\stitchwd{\hfil}
496 \fi}
497 \newcommand \purlbox[3][0]{\strut@knit%
498 \ifcase \passnum@knit
499 \ifx \empty@knit \purlboxbackground
500 \rule{#3\stitchwd}{0pt}%
501 \else
502 {\purlboxbackground \purlbackground{\rule[-\stitchdp]{#3\stitchwd}{\stitchht}}}\fi
503 \or
504 \hbox to #3\stitchwd{\char6\leaders\hbox{\char5}\hfil\char6}%
505 \or
506 \lower\stitchdp\vbox to\stitchht{%
507 \vss\vskip\fontvoffset@knit
508 \hbox to #3\stitchwd{\ifnum #1>0 \hskip #1\stitchwd plus 1fil minus #1\stitchwd \else\hfil\fi
509 {\fontseries{m}\fontshape{n}\textsf{#2}}%
510 \count255 = -#1 \ifnum #1<0 \hskip \count255\stitchwd plus 1fil minus \count255\stitchwd \else\hfil\fi}%
511 \vss}%
512 \or
513 \hbox to \purlboxstitchcount{#2}{#3}\stitchwd{\hfil}%
514 \fi}
515
516 \newcommand \purlbackground[1]{\leavevmode\setbox0=\hbox{#1}%
517 \dimen0 = \wd0 \advance\dimen0 2\purlextend@knit
518 \dimen1 = \stitchht \advance\dimen1 \purlextend@knit
519 \dimen2 = \stitchdp \advance\dimen2 \purlextend@knit
520 \ifnum \passnum@knit = 0 \kern-\purlextend@knit
521 \vrule width 0pt height \ht0 depth \dp0
522 \smash{\rule[-\dimen2]{\dimen0}{\dimen1}}%
523 \kern-\purlextend@knit
524 \else\box0\fi}
525
526 \newcommand \widesymbol[3][0]{\strut@knit
527 \ifcase \passnum@knit
528 \knitbox{}{#3}\or
529 \knitbox{}{#3}\or
530 \hbox to #3\stitchwd{\ifnum #1>0 \hskip #1\stitchwd plus 1fil minus #1\stitchwd \else\hfil\fi
531 #2%
532 \count255 = -#1 \ifnum #1<0 \hskip \count255\stitchwd plus 1fil minus \count255\stitchwd \else\hfil\fi}\else
533 \widesymbolspacer{#2}{#3}\relax\fi}
534
535 \newcommand \widesymbolspacer[2]{#1}
536
537 % Row number commands
538
539 \newcommand \numberrow[3]{\ifnum\passnum@knit=3 \ifvmode\vskip\stitchht\fi\else
540 \ifvmode\nonumber\leavevmode\fi
541 \strut@knit
542 \count255=#1
543 \hbox to \stitchwd{\hss\ifnum \passnum@knit = 2 \color{rncolor}\textnormal{#1}\fi\hss}%
544 \ifnum #1 > #3
545 \advance\count255 -1
546 \loop \ifnum \count255>#3
547 \c@tempcount@knit = \count255
548 \divide\c@tempcount@knit #2
549 \multiply \c@tempcount@knit #2
550 \ifnum\c@tempcount@knit = \count255
551 \hbox to \stitchwd{\hss\ifnum \passnum@knit = 2 \color{rncolor}\textnormal{\the\count255}\fi \hss}%
552 \else
553 \kern\stitchwd
554 \fi
555 \advance\count255 -1
556 \repeat
557 \else
558 \advance\count255 1
559 \loop \ifnum \count255<#3
560 \c@tempcount@knit = \count255
561 \divide\c@tempcount@knit #2
562 \multiply \c@tempcount@knit #2
563 \ifnum\c@tempcount@knit = \count255
564 \hbox to \stitchwd{\hss\ifnum \passnum@knit = 2 \color{rncolor}\textnormal{\the\count255}\fi \hss}%
565 \else
566 \kern\stitchwd
567 \fi
568 \advance\count255 1
569 \repeat
570 \fi
571 \hbox to \stitchwd{\hss\ifnum \passnum@knit = 2 \color{rncolor}\textnormal{#3}\fi \hss}%
572 \fi}
573
574 \newcommand \rnoddonly{\def\rncore@knit##1{\ifshowrn@knit \ifodd\c@rownumber \csname print##1rownumber\endcsname{\therownumber}\fi\fi}}
575 \newcommand \rnevenonly{\def\rncore@knit##1{\ifshowrn@knit \ifodd\c@rownumber \else\csname print##1rownumber\endcsname{\therownumber}\fi\fi}}
576 \newcommand \rnnormal{\def\rncore@knit##1{\ifshowrn@knit \csname print##1rownumber\endcsname{\therownumber}\fi}}
577
578 \newcommand \rncore@knit[1]{\ifshowrn@knit \csname print#1rownumber\endcsname{\therownumber}\fi}
579 \newcommand \rnstep@knit{\ifshowrn@knit
580 \ifnum \passnum@knit = 2 \global\advance\c@rownumber -\c@rownumberskip \relax\fi
581 \ifnum \passnum@knit = 0 \global\advance\c@rownumber -\c@rownumberskip \relax\fi
582 \else\global\showrn@knittrue\fi}
583
584 \newcommand \printrownumber[1]{{\color{rncolor}\textnormal{#1}}}
585 \newcommand \printrightrownumber[1]{\knitleftarrowhead{\color{rncolor}\textnormal{#1}}}
586 \newcommand \printleftrownumber[1]{{\color{rncolor}\textnormal{#1}}\knitrightarrowhead}
587 \newcommand \knitrightarrowhead{{\color{rnarrowcolor}\char125}}
588 \newcommand \knitleftarrowhead{{\color{rnarrowcolor}\char123}}
589
590 %\newcommand \therownumber{\arabic{rownumber}}
591 % \newcount automatically generates a \therownumber command
592
593 \newcommand \rn@knit{\ifnum \passnum@knit < 3 \leavevmode
594 \hbox to \rownumberwd{\hss\ifnum \passnum@knit = 2 \rncore@knit{}\fi\rnstep@knit\hss}\fi}
595 \newcommand \rnleft@knit{\ifnum \passnum@knit < 3 \leavevmode
596 \setbox0 = \hbox{\ifnum \passnum@knit = 2 \rncore@knit{left}\fi\rnstep@knit}
597 \dimen0 = \wd0 %\advance \dimen0 -\rownumberwd
598 \ifchartsonly\advance \dimen0 1pt\fi
599 \ifdim \dimen0 > \rnleftwd@knit \global\rnleftwd@knit = \dimen0 \fi
600 \hbox to 0pt{\hss\box0}\fi}
601 \newcommand \rnright@knit{\ifnum \passnum@knit < 3 \leavevmode
602 \setbox0 = \hbox{\ifnum \passnum@knit = 2 \rncore@knit{right}\fi\rnstep@knit}
603 \dimen0 = \wd0 %\advance \dimen0 -\rownumberwd
604 \ifchartsonly\advance \dimen0 1pt\fi
605 \ifdim \dimen0 > \rnrightwd@knit \global\rnrightwd@knit = \dimen0 \fi
606 \hbox to 0pt{\box0\hss}\fi}
607
608 \newcommand \rnbox@knit[1]{\ifnum \passnum@knit < 3 \leavevmode
609 \hbox to \rownumberwd{\hss\ifnum \passnum@knit = 2 {\printrownumber{#1}}\fi\hss}\fi}
610 \newcommand \rnboxleft@knit[1]{\ifnum \passnum@knit < 3 \leavevmode
611 \setbox0 = \hbox{\ifnum \passnum@knit = 2 {\printleftrownumber{#1}}\fi}
612 \dimen0 = \wd0 %\advance \dimen0 -\rownumberwd
613 \ifchartsonly\advance \dimen0 1pt\fi
614 \ifdim \dimen0 > \rnleftwd@knit \global\rnleftwd@knit = \dimen0 \fi
615 \hbox to 0pt{\hss\box0}\fi}
616 \newcommand \rnboxright@knit[1]{\ifnum \passnum@knit < 3 \leavevmode
617 \setbox0 = \hbox{\ifnum \passnum@knit = 2 {\printrightrownumber{#1}}\fi}
618 \dimen0 = \wd0 %\advance \dimen0 -\rownumberwd
619 \ifchartsonly \advance \dimen0 1pt \fi
620 \ifdim \dimen0 > \rnrightwd@knit \global\rnrightwd@knit = \dimen0 \fi
621 \hbox to 0pt{\box0\hss}\fi}
622
623 % The chart commands
624
625 \newcommand \chart[1][]{\smallpage@knit\obeylines \catcode`\|=\active \catcode`\# = 12 \catcode`\& = 12 \chart@knit{#1}}
626
627 % Some special stuff for chartsonly mode
628 \let\extracommands@knit\relax
629 \newcommand \smallpage@knit{\noindent\hbox\bgroup}
630 \let\endsmallpage@knit\egroup
631
632 % The chart command proper
633 \newcommand \chart@knit[2]{%
634 \global \chartwidth@knit = 0pt
635 \ifresetrn \c@rownumber = 0 \else \c@tempcount@knit = \c@rownumber \fi
636 \setbox\bgbox@knit=\vbox{\def\passnum@knit{0}\hsize=\maxdimen
637 \ff@knit % This is kind of silly, but to make \stitchht work, we need to be sure that the foreground font exists.
638 \pf@knit
639 \lineskip=0pt
640 \parskip=0pt
641 \baselineskip=0pt
642 \parindent=0pt
643 \emergencystretch = \stitchwd
644 \leftskip=0pt
645 \rightskip=0pt
646 \parfillskip=0pt plus 1fil
647 \ifresetrn\else\let\rnstep@knit\relax\fi
648 \commands@knit\extracommands@knit
649 \def\nonumber{\global\showrn@knitfalse}%
650 \csname auto#1@knit\endcsname #2\par}%
651 \ifresetrn \c@tempcount@knit = -\c@rownumber \fi
652 \ifgrid
653 \setbox\ggbox@knit=\vbox{\def\passnum@knit{1}\hsize=\maxdimen
654 \gf@knit
655 \lineskip=0pt
656 \parskip=0pt
657 \baselineskip=0pt
658 \parindent=0pt
659 \emergencystretch = \stitchwd
660 \leftskip=0pt
661 \rightskip=0pt
662 \parfillskip=0pt plus 1fil
663 \commands@knit\extracommands@knit
664 \def\nonumber{\global\showrn@knitfalse}%
665 \csname auto#1@knit\endcsname #2\par}%
666 \fi
667 \c@rownumber = \c@tempcount@knit %
668 \global \rnleftwd@knit = 0pt
669 \global \rnrightwd@knit = 0pt
670 \setbox\fgbox@knit=\vbox{\def\passnum@knit{2}\hsize=\maxdimen
671 \ff@knit
672 \color{forecolor}
673 \lineskip=0pt
674 \parskip=0pt
675 \baselineskip=0pt
676 \parindent=0pt
677 \emergencystretch = \stitchwd
678 \leftskip=0pt
679 \rightskip=0pt
680 \parfillskip=0pt plus 1fil
681 \commands@knit\extracommands@knit
682 \def\nonumber{\global\showrn@knitfalse}%
683 \csname auto#1@knit\endcsname #2\par}%
684 \global\advance \chartwidth@knit \rnleftwd@knit
685 \global\advance \chartwidth@knit \rnrightwd@knit
686 \hbox to \chartwidth@knit{\hskip \rnleftwd@knit
687 \rlap{\color{purlgray}\box\bgbox@knit}%
688 \ifgrid\rlap{\color{gridcolor}\box\ggbox@knit}\fi
689 \ifchartsonly
690 \dimen2 = \dp \fgbox@knit \dimen3 = \ht \fgbox@knit
691 \advance\dimen2 0.5\gridwidth \advance\dimen3 0.5\gridwidth
692 \vrule width 0pt height \dimen3 depth \dimen2
693 \fi
694 % If we are doing charts only, we want to enlarge things enough that
695 % we can see the grid on all sides.
696 % But if we aren't, we want adjacent charts to merge seamlessly
697 % because using separate charts is the only way to allow charts to
698 % break across pages.
699 \box\fgbox@knit%
700 \hss}%
701 \endsmallpage@knit
702 }
703
704 % Special charts only macros
705
706 \ifchartsonly
707 \ifpdf@knit\else\errmessage{Package knit error: \chartsonly should only be used with pdfTeX.}\fi%
708 \hoffset=-1in
709 \voffset=-1in
710 \oddsidemargin=0pt
711 \evensidemargin=0pt
712 \topmargin=0pt
713 \headheight=0pt
714 \headsep=0pt
715 \footskip=0pt
716 \textheight=120in
717 \topskip = 0pt % Causes problems in one-row charts if this isn't present
718 \newenvironment{smallpage}{\clearpage
719 \hsize=\textwidth \columnwidth = \textwidth
720 \global\chartwidth@knit=0pt
721 \setbox0 = \vbox\bgroup
722 \def\smallpage@knit{\let\endsmallpage@knit\egroup \noindent \hbox\bgroup}%
723 }
724 {\egroup%
725 %
726 \pdfpagewidth=\wd0
727 %
728 \dimen0=\ht0 \advance \dimen0 by \dp0
729 \pdfpageheight=\dimen0
730 %
731 \ifdim\pdfpageheight>\textheight
732 \typeout{}
733 \typeout{You need to increase \string\textheight\space in the preamble.}
734 \typeout{What do you want such a big chart for, anyway?}
735 \typeout{}
736 \fi
737 %
738 \box0
739 \clearpage
740 }
741 \let\smallpage@knit\smallpage
742 \let\endsmallpage@knit\endsmallpage
743 \def\extracommands@knit{%
744 \leftskip = 0.5\gridwidth
745 \rightskip = 0.5\gridwidth
746 }
747 \else
748 \let\smallpage\begingroup
749 \let\endsmallpage\endgroup
750 \fi
751
752 % Autonumbering macros
753
754 \newcommand \everypar@knit{\hskip\leftgap@knit \leftgap@knit=0pt \relax}
755
756 \newcommand \auto@knit{\let\nonumber\relax \everypar={\everypar@knit\do@endofpar@knit{\adjustchartwidth@knit}}}
757 \newcommand \autoleft@knit{\everypar={\everypar@knit\rnleft@knit\do@endofpar@knit{\adjustchartwidth@knit}}}
758 \newcommand \autoright@knit{\everypar={\everypar@knit\do@endofpar@knit{\rnright@knit\adjustchartwidth@knit}}}
759 \newcommand \autooddleft@knit{\everypar={\everypar@knit
760 \ifodd \c@rownumber %
761 \rnleft@knit\do@endofpar@knit{\adjustchartwidth@knit}%
762 \else %\hskip\rownumberwd
763 \do@endofpar@knit{\rnright@knit\adjustchartwidth@knit}\fi}}
764 \newcommand \autooddright@knit{\everypar={\everypar@knit
765 \ifodd \c@rownumber %\hskip\rownumberwd
766 \do@endofpar@knit{\rnright@knit\adjustchartwidth@knit}%
767 \else\rnleft@knit\do@endofpar@knit{\adjustchartwidth@knit}\fi}}
768 \newcommand \autoboth@knit{\everypar={\everypar@knit\rnleft@knit\global\advance\c@rownumber 1 \do@endofpar@knit{\rnright@knit\adjustchartwidth@knit}}}
769 \let\autoevenleft@knit\autooddright@knit
770 \let\autoevenright@knit\autooddleft@knit
771
772 \newcommand \adjustchartwidth@knit{\endgraf
773 \ifnum \passnum@knit = 2 \setbox0=\lastbox
774 \setbox1=\hbox{\unhcopy0\unskip}%
775 \box0
776 \ifdim\wd1 >\chartwidth@knit \global\chartwidth@knit=\wd1\fi\fi}
777
778 % Stitch-counting macros
779
780 \newcommand \adjuststitchcount[2][\temp@knit]{\def\temp@knit{#2}%
781 \leavevmode\ifnum\passnum@knit=3 \null
782 \ifcountingout@knit \kern #2\stitchwd \else \kern #1\stitchwd \fi \null\fi}
783
784 \newcommand \stitchcountwarningbar{%
785 \ifnum \c@stitchcountinprev = \c@stitchcountout \else
786 \ifnum \c@stitchcountinprev > -99
787 \vrule width \overfullrule
788 \typeout{Package knit warning: Stitch count mismatch on input line \the\inputlineno.}
789 \fi \fi}
790
791 \newcommand \countstitches[1]{%
792 \global\c@stitchcountinprev = \c@stitchcountin
793 \setbox0 = \hbox{\def\passnum@knit{3}\countingout@knittrue \let\stitchwd\stitchwd@count@knit \fontshape{out}\selectfont #1}%
794 \c@stitchcountout = \wd0
795 \dimen0 = 0.5\stitchwd@count@knit \advance \c@stitchcountout \dimen0
796 \global\divide \c@stitchcountout \stitchwd@count@knit
797 \setbox1 = \hbox{\def\passnum@knit{3}\countingout@knitfalse \let\stitchwd\stitchwd@count@knit \fontshape{in}\selectfont #1}%
798 \c@stitchcountin = \wd1
799 \dimen1 = 0.5\stitchwd@count@knit \advance \c@stitchcountin \dimen1
800 \global\divide \c@stitchcountin \stitchwd@count@knit
801 }
802
803 \newcommand \stitchcountchart[1][]{\begingroup \catcode`\|=\active \catcode`\# = 12 \catcode`\& = 12 \def\chartrn@knit{#1}\obeylines \afterassignment \printstitchcountchart@knit \toks0 =}
804
805 \newcommand \printstitchcountchart@knit{\smallpage@knit\hbox{%
806 \ifx\relax\printleftstitchcount\else\ifx \empty@knit \printleftstitchcount\else
807 \let\printstitchcount@knit\printleftstitchcount
808 \def\stitchcountside@knit{0}\makestitchcounts@knit \fi\fi
809 \chart[\chartrn@knit]{\the\toks0}%
810 \ifx\relax\printrightstitchcount\else\ifx \empty@knit \printrightstitchcount\else
811 \let\printstitchcount@knit\printrightstitchcount
812 \def\stitchcountside@knit{1}\makestitchcounts@knit\fi\fi
813 }\endsmallpage@knit
814 \endgroup}
815
816 {\obeylines
817 \gdef\countstitcheseachrow@knit#1^^M{%
818 \setbox1 = \hbox{#1}%
819 \ifCountStsThisRow@knit%
820 \countstitches{#1}%
821 \setstitchcountlabel@knit%
822 \else%
823 \global\CountStsThisRow@knittrue%
824 \setbox0=\hbox{}%
825 \fi%
826 \printstitchcountlabel@knit}
827 \gdef\shortrows@countstitcheseachrow@knit#1^^M{\countstitches{#1} %
828 \ifx \relax \shortrowrowcount@knit %
829 \global\advance \c@shortrowstsin@knit \c@stitchcountin \global\advance \c@shortrowstsout@knit \c@stitchcountout %
830 \global\let \shortrowrowcount@knit 2
831 % For some reason, we MUST NOT have a % after the 2.
832 \else%
833 \global\advance \c@shortrowstsin@knit -\c@stitchcountout \global\advance \c@shortrowstsout@knit -\c@stitchcountin %
834 \global\let \shortrowrowcount@knit \relax
835 \fi%
836 \global\c@stitchcountin = \c@stitchcountinprev %
837 }
838 \gdef\shortrows@printstitchcountlabel@knit#1^^M{\setbox1 = \hbox{#1}\printstitchcountlabel@knit\setbox0=\hbox{}}
839 \gdef\shortrows#1{\ifnum \passnum@knit = 3
840 \c@shortrowstsin@knit = 0 \c@shortrowstsout@knit = 0 \global\let \shortrowrowcount@knit \relax %
841 \setbox2 = \vbox{\everypar = {\shortrows@countstitcheseachrow@knit}%
842 #1
843 }%
844 \ifx \shortrowrowcount@knit \relax \advance \c@stitchcountin \c@shortrowstsin@knit \advance \c@stitchcountin -\c@shortrowstsout@knit %
845 \else
846 \c@stitchcountinprev = \c@stitchcountin \c@stitchcountin = \c@shortrowstsin@knit \c@stitchcountout = \c@shortrowstsout@knit %
847 \fi %
848 \setstitchcountlabel@knit%
849 \vbox{\everypar = {\shortrows@printstitchcountlabel@knit}%
850 \ifx \shortrowrowcount@knit \relax \setbox0=\hbox{} \else
851 \ifCountStsThisRow@knit\else \setbox0=\hbox{} \global\CountStsThisRow@knittrue \fi \fi
852 % If there are an even number of short rows, we don't know the stitch count,
853 % so we don't print it
854 #1
855 }%
856 \else%
857 #1
858 \fi%
859 \par}
860 }
861
862 \def\setstitchcountlabel@knit{\setbox0=\hbox{\def\passnum@knit{2}\strut@knit \printstitchcount@knit\stitchcountwarningbar}}
863 \def\printstitchcountlabel@knit{\ifdim \wd0 > \stitchcountwidth@knit \global\stitchcountwidth@knit = \wd0 \fi
864 \hbox to 0pt{\ifnum\stitchcountside@knit = 0 \hss\fi
865 \vrule width 0pt height \ht1 depth \dp1 \smash{\box0}%
866 \ifnum\stitchcountside@knit = 1 \hss\fi}%
867 \par}
868
869 \def\makestitchcounts@knit{\hbox{\setbox1=\vbox{\c@stitchcountin = -1001
870 \global\stitchcountwidth@knit=0pt
871 \global\CountStsThisRow@knittrue
872 \parindent=0pt
873 \def\passnum@knit{3}
874 \def\doifcounting@knit##1{##1}
875 \ff@knit
876 \commands@knit
877 \everypar={\countstitcheseachrow@knit} \offinterlineskip
878 \the\toks0
879 }%
880 \ifnum\stitchcountside@knit = 0
881 \hskip \stitchcountwidth@knit\rlap{\box1}%
882 \else
883 \rlap{\box1}\hskip \stitchcountwidth@knit
884 \fi
885 }}
886
887 \def\nostitchcount{\ifnum \passnum@knit = 3 \global \CountStsThisRow@knitfalse \fi}
888
889 \newcommand \printleftstitchcount{{\color{rncolor}\textnormal{(\thestitchcountout\ sts) }}}
890 \newcommand \printrightstitchcount{}
891
892 \newcommand \knitdebug{\renewcommand \printleftstitchcount{{\color{rncolor}\textnormal{(\thestitchcountout\ out, \thestitchcountin\ in) }}}}
893
894
895
896 \newcommand \empty@knit{}
897 % This is needed because the plain TeX \empty is
898 % defined with \def and not \newcommand
899