Some errors fix
[TeXnicard.git] / system / texnicard_format.tex
blob8e984d95f40b80c9e5adb884579563d095e0db92
1 % TeX format file for Plain TeXnicard.
2 % This file is licensed under the same terms as TeXnicard itself.
4 % As a special exception, if you create a document which uses this file,
5 % and link it with this file, this file does not by itself cause the
6 % resulting document to be covered by the GNU General Public License.
7 % This exception does not however invalidate any other reasons why the
8 % document might be covered by the GNU General Public License. If you
9 % modify this file, you may extend this exception to your version of the
10 % file, but you are not obligated to do so. If you do not wish to do so,
11 % delete this exception statement from your version.
14 % \def\z#1{\.{\\#1}}
15 % This is the {\TeX} format file for Plain \TeX nicard. It is meant to be
16 % compiled into a format file and used with the \.{plain.cards} file.
18 % The template for the game should then define any additional codes on top
19 % of this one to make things specific for the game card style, such as
20 % where the text goes, what fonts to use, font colors, special symbols,
21 % etc.
24 % --- Category codes ---
27 % A few category codes are the same as Plain \TeX, but they are simplified
28 % here, since not as many are needed. Also note that the underscore is now
29 % considered a letter, so it can be used in names of macros.
32 \catcode`\{=1
33 \catcode`\}=2
34 \catcode`\&=4
35 \catcode`\#=6
36 \catcode`\^=7
37 \catcode"09=10
38 \catcode`\_=11
39 \endlinechar=32
41 % --- Version ---
44 % Here is the version information to identify this format. (The output
45 % \.{cards.tex} file will complain if you try to use a different format.)
46 % (Yes, computers can complain, too. But don't anthropomorhize computers,
47 % they don't like that.)
49 % {\bf N.B.:} The category codes must be defined first! (Otherwise you
50 % will not have access to \.\{ and \.\} for begin/end of a group)
53 \def\fmtname{texnicard} \def\fmtversion{0.1}
55 % --- Escaped characters ---
58 % Since some character are special use, it will be defined here as
59 % character escape codes that expand to the normal character. This can be
60 % used with commands such as \.{\\special} and \.{\\write}.
63 \def\makecharescape#1{{
64 \uccode`*=`#1\uppercase{\gdef#1{*}}
67 \makecharescape\ %
68 \makecharescape\#
69 \makecharescape\$
70 \makecharescape\%
71 \makecharescape\&
72 \makecharescape\\
73 \makecharescape\{
74 \makecharescape\}
75 \makecharescape\^
76 \let\asciicircum=\^
78 % --- Count registers ---
80 \countdef\pageno=0
81 \countdef\resolution=1
82 \countdef\px_card_width=2
83 \countdef\px_card_height=3
84 \countdef\countA=10
85 \countdef\countB=11
86 \countdef\fontshrink=12
87 \countdef\maxfontshrink=13
88 \countdef\countC=14
89 \countdef\totallines=15
90 \countdef\parbreaklines=16
91 \countdef\layer_selected=17
92 \countdef\fontscale=18
94 \pageno=0
95 \fontshrink=0
96 \maxfontshrink=20
97 \parbreaklines=0
99 % --- Dimension registers ---
101 \dimendef\maxdimen=10
102 \dimendef\dimenA=11
103 \dimendef\dimenB=12
104 \dimendef\card_width=13
105 \dimendef\card_height=14
106 \dimendef\dimenC=15
107 \dimendef\lineskiplimit_change=16
109 \maxdimen=16383.99999pt
111 % --- Skip registers ---
113 \skipdef\smallskipamount=10
114 \skipdef\medskipamount=11
115 \skipdef\bigskipamount=12
116 \skipdef\skipA=13
117 \skipdef\skipB=14
118 \skipdef\skipC=15
119 \skipdef\parskip_change=16
120 \skipdef\baselineskip_change=17
121 \skipdef\lineskip_change=18
123 \smallskipamount=3pt plus 1pt minus 1pt
124 \medskipamount=6pt plus 2pt minus 2pt
125 \bigskipamount=12pt plus 4pt minus 4pt
127 % --- Token registers ---
129 \toksdef\backgroundcolor=10
130 \toksdef\toksA=11
131 \toksdef\toksB=12
132 \toksdef\toksC=13
133 \toksdef\fontcs=14
135 \backgroundcolor={none}
137 % --- Tracing parameters ---
140 % These parameters are used to set tracing so that you will get output
141 % of \z{showbox} and things like that to standard output, with the full
142 % information of the box included. This can then be read back in later.
145 \errorcontextlines=5
146 \showboxbreadth=20000
147 \showboxdepth=20000
148 \tracinglostchars=1
149 \tracingonline=1
151 % --- Programming macros ---
153 \let\outer=\Undefined
154 \let\nexp=\noexpand
155 \let\exp=\expandafter
156 \let\(=\csname
157 \let\)=\endcsname
158 \def\space{ }
159 \def\empty{}
160 \def\gobble#1{}
161 \let\bgroup={
162 \let\egroup=}
163 \def\nullbox{\hbox{}}
164 {\catcode`\$=3 \global\let\mathshift=$}
167 % Now we are getting loopy! (Just like Plain \TeX; nothing special.)
170 \def\loop#1\repeat{\def\loopbody{#1}\iterate}
171 \def\iterate{
172 \loopbody\let\loopnext=\iterate\else\let\loopnext=\relax\fi\loopnext
174 \let\repeat=\fi % make \loop...\if...\repeat skippable
177 % Here is a macro to reset the error count to zero.
180 \def\reset_error_count{{\setbox0=\vbox{\noindent\vrule\par}}}
183 % These macros will calculate the strech component and shrink component
184 % of a glue value.
186 % Note that the lowercase codes are temporarily changed so that when the
187 % skip register is expanded by \.{\\the}, that the category codes will be
188 % correct.
190 % (Also, the rule that kerns do not cause unexpected things to happen, is
191 % used, which is described later on.)
194 \begingroup
195 \lccode`+=`p
196 \lccode`9=`l
197 \lccode`8=`u
198 \lccode`7=`s
199 \lccode`*=`m
200 \lccode`]=`i
201 \lccode`[=`n
202 \lowercase{
204 \gdef\read_ss#1+987#2*][87#3end#4!{%
205 \skipB=#2\relax\skipC=#3\relax%
208 % \ss_of{glue}{stretch_dimen_register}{shrink_dimen_register}
209 \gdef\ss_of#1#2#3{{%
210 \skipA=#1\relax%
211 \exp\read_ss\the\skipA end +987 0pt *][87 0pt end!%
212 \kern\skipB\kern\skipC%
213 }#3=\lastkern\unkern#2=\lastkern\unkern}%
215 }\endgroup
218 % This macro sets all codes 0 to 255 in a table (such as \z{catcode}).
219 % It is generally used inside of a group.
222 % \set_all_codes{table}{value}
223 \def\set_all_codes#1#2{%
224 \countA=0
225 \loop\ifnum\countA<256
226 #1\countA=#2\relax
227 \advance\countA by 1 \repeat
231 % Since negative numbers are not allowed in \TeX nicard, we must fake it.
232 % Here is how it is faked.
235 \def\enumber#1{%
236 \ifnum#1<0
237 0 \exp\gobble\number#1 -
238 \else
239 \number#1
244 % In order to count tokens (such as how many digits fit in a symbol).
247 \def\count_tokens#1=#2{%
248 \begingroup
249 \countA=0
250 \def\xxx##1{%
251 \ifx\relax##1%
252 \let\xxx\empty
253 \else
254 \advance\countA by 1
256 \xxx
258 \xxx#2\relax
259 \kern\countA sp%
260 \endgroup #1=\lastkern \unkern
263 % --- Dealing with derived formats ---
266 % Here, a macro is defined that will allow this file to act differently
267 % when a different format file is being loaded which is based on this one.
268 % Hyphenation patterns will not be loaded, and it won't dump at the end.
269 % That way, the file it is included from can hyphenate/dump.
271 % This is a strange tricky code. It attempts to load the main input file
272 % for the job (please note the name of this file might be changed in case
273 % it is a modified version, so the filename is not hardcoded). If it is
274 % this file, the first command will be \.{\\catcode}; otherwise, the first
275 % command will be something like \.{\\input texnicard\_format}. It is done
276 % inside of a group, so that the changed definitions and changed internal
277 % parameters are restored after the group.
279 % The percentage sign is normally a comment character. While it is doing
280 % these strange things, however, it is treated as the end of line
281 % character, which causes it to insert a space and skip the rest of the
282 % line. Actual spaces are ignored. Now, the macro \.{\\input} and
283 % \.{\\catcode} will read the entire line as its parameter. After it
284 % determines which file it is, it will skip the rest of the file, and
285 % therefore will then finish the group. The definitions of \.{\\dump} and
286 % \.{\\ifbaseformat} are global, so they will be the only thing persisting
287 % from all this mess.
289 % If it is a derived (inclusion) format, the first \.{\\dump} at the end
290 % of this file doesn't work, but it will cause the next one to work. Now
291 % the other file will have these definitions and can continue with some
292 % modifications before finally dumping the format.
295 \let\real_dump=\dump
297 \begingroup
298 \def \0{
299 \endlinechar=`\%
300 \catcode`\%=5
301 \catcode32=9
302 \let \1=\input
303 \uppercase{
304 \long\def \input##1 {
305 \gdef \dump{\global\let \dump=\real_dump}
306 \global\let\ifbaseformat=\iffalse
307 \endinput
309 \long\def \catcode##1 {
310 \global\let\ifbaseformat=\iftrue
311 \endinput
314 \1\jobname\relax
316 \endgroup
318 % --- Reading \TeX's output back in ---
321 % Here is a way of reading \TeX's output of things such as: errors,
322 % \z{show}, \z{showbox}, \z{tracingparagraphs}, and so on. You should run
323 % {\TeX} with a command such as: \.{tex cards > cards.fot}
325 % Input file 15 is used to read its own output. However, nothing can be
326 % read until a \z{message} has occured, and a \z{message} does not add a
327 % termination to the output line. One way to deal with this problem is to
328 % use \z{write} and \z{message} together.
331 \def\fot_open{\openin15=\jobname.fot\fot_skip}
334 % Using \z{write} and \z{message} together solves another problem too,
335 % which is to make it to skip everything that you don't want. This macro
336 % skips up to the current point in the online output log.
339 \def\fot_skip{{%
340 \immediate\write16{\^\%}\message{}%
341 \set_all_codes\catcode{14}\catcode`\^=12%
342 \let \1=\iftrue \loop
343 \read1 to \0%
344 \ifx\0\^\let \1=\iffalse\fi
345 \1\repeat
349 % However, these kind of things are probably not needed. They are provided
350 % anyways, in case it might be necessary sometimes.
353 % --- Typesetting parameters ---
355 \adjdemerits=10000
356 \baselineskip=0pt
357 \brokenpenalty=100
358 \clubpenalty=10000
359 \doublehyphendemerits=10000
360 \emergencystretch=\maxdimen
361 \exhyphenpenalty=55
362 \finalhyphendemerits=5000
363 \hbadness=1000
364 \hfuzz=.1pt
365 \hoffset=0pt
366 \hsize=\maxdimen
367 \hyphenpenalty=60
368 \lefthyphenmin=2
369 \linepenalty=10
370 \lineskip=0pt
371 \lineskiplimit=0pt
372 \looseness=0
373 \overfullrule=0pt
374 \pagegoal=\maxdimen
375 \parfillskip=0pt plus .999fil
376 \parindent=0pt
377 \parskip=3pt plus 1pt minus .5pt
378 \pretolerance=100
379 \righthyphenmin=3
380 \splittopskip=0pt
381 \tolerance=500
382 \topskip=0pt
383 \vbadness=1000
384 \vfuzz=.1pt
385 \voffset=0pt
386 \vsize=\maxdimen
388 % --- Typesetting macros ---
390 \def\smallskip{\vskip\smallskipamount}
391 \def\medskip{\vskip\medskipamount}
392 \def\bigskip{\vskip\bigskipamount}
393 \def\noskip{\relax\ifvmode\prevdepth=-1000pt \fi}
394 \def\endpage{\par\vfil\penalty-20000 }
395 \def\br{\ifhmode\skip\parfillskip\penalty-10000 \else\noindent\fi}
396 \def\nobr{\penalty 10000 }
398 \def\thin{\hskip .16667em\relax}
399 \def\en{\hskip .5em\relax}
400 \def\em{\hskip 1em\relax}
401 \def\double_em{\hskip 2em\relax}
404 % French and non-French spacing is like Plain \TeX, but in \TeX nicard
405 % the default is French instead of non-French.
408 \def\frenchspacing{
409 \sfcode`\.=1000 \sfcode`\?=1000 \sfcode`\!=1000
410 \sfcode`\:=1000 \sfcode`\;=1000 \sfcode`\,=1000
412 \def\nonfrenchspacing{
413 \sfcode`\.=3000 \sfcode`\?=3000 \sfcode`\!=3000
414 \sfcode`\:=2000 \sfcode`\;=1500 \sfcode`\,=1250
416 \frenchspacing
419 % And so, a control sequence \z{ep} to represent end of a paragraph. Here
420 % it is used to keep track of total lines, but it can be changed to do
421 % other things too.
424 \def\ep{%
425 \par\advance\totallines by\prevgraf
426 \advance\totallines by\parbreaklines
430 % This macro digs the box by removing extra glue and penalty and kerns
431 % at the end, so that the box behind it will be accessible.
434 \def\digthis{%
435 \unskip \unskip \unkern \unkern \unpenalty \unpenalty
436 \unskip \unskip \unkern \unkern \unpenalty \unpenalty
437 \unskip \unskip \unkern \unkern \unpenalty \unpenalty
441 % Now, here is a macro to calculate the overfullness of paragraphs in
442 % a vbox, and stores the result in a dimen register.
444 % It works by unpacking the given vbox into a sequence of hboxes which
445 % represent the lines of the text in the paragraph(s). And then it will
446 % repack the boxes to their natural width and check which ones are
447 % larger when naturally. (It won't work in case of rules and whatsits.
448 % This can be overcome by placing them in their own boxes.)
450 % Everything is computed inside of a group. Now, the final result must
451 % be brought to the outside of the group. This can be done using
452 % \.{\\global}, but what if you do not want it global? So, instead we
453 % can add a kern and then take it out after the group, so that it will
454 % be moved up by one group only. (This is perfectly safe; see sections
455 % 1000 and 1061 in {\sl\TeX: The Program}.) (The other thing is that
456 % it might be a register used by this macro; using kerns in this way
457 % avoids that problem, too.)
460 % \overfullness{dimen-register}{box-register}
461 \def\overfullness#1#2{{\setbox4=\vbox{%
462 \setbox0=\copy#2
463 \dimenA=0pt
464 \unvcopy0
465 \loop
466 \digthis
467 \setbox2=\lastbox
468 \ifvoid2 \countA=0 \else \countA=1 \fi
469 \ifnum\countA=1
470 \ifhbox2
471 \dimenB=\wd2
472 \setbox3=\hbox{\unhbox2}
473 \dimenC=\wd3
474 \advance\dimenC by-\dimenB
475 \ifdim\dimenC>\dimenA \dimenA=\dimenC \fi
477 \repeat
478 \kern\dimenA}\kern\ht4
479 }#1\lastkern\unkern}
482 % It will be useful to turn off paragraph skip and so on. It should always
483 % be done after defining fonts, at least.
486 \def\offlineskip{%
487 \baselineskip=-1000pt\lineskip=0pt\lineskiplimit=\maxdimen\parskip=0pt%
488 \parshape=0\parindent=0pt\leftskip=0pt\rightskip=0pt%
489 \relax
492 % --- Fonts ---
495 % The first thing is magnifications steps. No explanation is needed; this
496 % is the same as Plain \TeX.
499 \def\magstephalf{1095 }
500 \def\magstep#1{\ifcase#1 1000\or1200\or1440\or1728\or2074\or2488\fi\relax}
503 % The second thing is fonts that will scale to fit. The largest size text
504 % can fit in the box, if it doesn't fit then it will try the smaller size,
505 % until it fits, or if it is too small and you cannot make smaller text.
507 % The current values of \z{parskip}, \z{baselineskip}, \z{lineskip}, and
508 % \z{lineskiplimit} are stored with the font definition. The current
509 % values of registers \z{parskip\_change} and so on are used as amounts
510 % that the other parameters are changed by for each smaller size of the
511 % font.
514 % \makescaledfonts{name}{file}{max_scale}{num_sizes}{change_amount}
515 \def\makescaledfonts#1#2#3#4#5{
516 \countA=0
517 \countB=#3
518 \exp\xdef \(\string#1:count\){#4}
519 \exp\xdef \(\string#1:registers\){%
520 \reg_to_mac\parskip \reg_to_mac\parskip_change
521 \reg_to_mac\baselineskip \reg_to_mac\baselineskip_change
522 \reg_to_mac\lineskip \reg_to_mac\lineskip_change
523 \reg_to_mac\lineskiplimit \reg_to_mac\lineskiplimit_change
524 \relax}
525 \loop \ifnum\countA<#4
526 \global\exp\font \(\string#1:\the\countA\)=#2 scaled \countB
527 \global\exp\font \(\string#1:#4\)=#2 scaled \countB
528 \advance\countA by 1
529 \advance\countB by #5
530 \repeat
531 \gdef#1{%
532 \fontcs={#1}%
533 \fontscale=#5
534 \multiply\fontscale by \fontshrink
535 \advance\fontscale by #3
536 \ifnum\fontshrink>#4
537 \(\string#1:#4\)%
538 \else
539 \(\string#1:\the\fontshrink\)%
541 \do_font_registers#1
546 % These are helper macros used by the above, so that line heights and so
547 % on can be affected by the amount of font shrinking.
550 \def\reg_to_mac#1{#1=\the#1}
551 \def\reg_fontshrink#1#2{%
552 \multiply#2by\fontshrink
553 \advance#1by#2\relax
555 \def\do_font_registers#1{%
556 \(\string#1:registers\)%
557 \reg_fontshrink\parskip\parskip_change
558 \reg_fontshrink\baselineskip\baselineskip_change
559 \reg_fontshrink\lineskip\lineskip_change
560 \reg_fontshrink\lineskiplimit\lineskiplimit_change
563 % --- Hyphenation ---
566 % The standard hyphenation patterns from Plain {\TeX} are used here, they
567 % should be sufficient. Hyphenation can still be turned off, and you can
568 % still make exceptions. (Sorry, if you are making a different language,
569 % you will have to recompile the format. Too bad!)
572 \ifbaseformat
573 \input hyphen
576 % --- Card layout ---
578 \def\zhbox{\hbox to 0pt}
579 \def\zvbox{\vbox to 0pt}
580 \def\zvtop{\vtop to 0pt}
582 \def\h_left#1{\zhbox{#1\hss}}
583 \def\h_center#1{\zhbox{\hss#1\hss}}
584 \def\h_right#1{\zhbox{\hss#1}}
585 \def\v_top#1{\zvbox{#1\par\vss}}
586 \def\v_middle#1{\zvbox{\vss#1\par\vss}}
587 \def\v_bottom#1{\zvbox{\vss#1}}
590 % There are two kind of positioning. You can position the top left corner
591 % of a box, or you can position the baseline of a box.
594 % \position{x}{y}{contents}
595 \def\position#1#2#3{\vbox{\kern#2\relax\hbox{\kern#1\relax#3}\vss}}
597 % \positionbase{x}{y}{contents}
598 \def\positionbase#1#2#3{\hbox{\kern#1\lower#2 #3\hss}}
600 \def\hidehrule#1#2{\kern-#1\hrule height#1 depth#2\kern-#2\relax}
601 \def\hidevrule#1#2{%
602 \kern-#1{\dimen0=#1\advance\dimen0 by #2\vrule width\dimen0}\kern-#2
606 % You can make a border with this.
609 % \border{thickness}{padding}{width}{contents}
610 \def\border#1#2#3#4{%
611 \hbox{\vrule width #1\vbox{\hrule height #1\vskip#2\hbox{\hskip#2
612 \vbox{\hsize=#3\relax#4}\hskip#2}\vskip#2\hrule height #1}%
613 \vrule width #1}%
617 % The \z{textarea} macro creates a text area on the card at a relative
618 % position. It will try the largest text size, and then make it smaller
619 % until it fits. The rules are the horizontal overfullness must be less
620 % than \z{hfuzz} and the vertical depth must be less than the specified
621 % height.
623 % Box 1 is the box of the area's contents at the current font size. It
624 % must be a vertical box containing only boxes, kerns, glues, and
625 % penalties (although there isn't much use to put penalties there). Boxes
626 % inside this one are allowed to contain anything. The reference point is
627 % moved such that the height of the box will be zero.
629 % The \z{iftrial} is set false when it is finally placing the box on the
630 % page, so that you can add things there such as centering only after it
631 % is done the trial and is now finally placing the box.
634 % \textarea{x}{y}{width}{height}{contents}
635 \def\textarea#1#2#3#4#5{%
636 \def\textarea_contents{#5}%
637 \let\iftrial=\iftrue
638 \setbox1=\vbox{}%
639 \fontshrink=0 \loop
640 \hsize=#3%
641 \setbox1=\vtop{\kern0pt\relax\textarea_contents}%
642 \ifdim\dp1<#4\relax
643 \overfullness\dimenA{1}
644 \ifdim\dimenA<\hfuzz \let\iftrial=\iffalse \fi
646 \ifnum\fontshrink=\maxfontshrink \let\iftrial=\iffalse \fi
647 \iftrial \advance\fontshrink by 1 \repeat
648 \setbox1=\vtop to#4{\kern0pt\relax\textarea_contents}%
649 \position{#1}{#2}{\box1}%
653 % It is just here so that \z{iftrial} will match \z{fi}.
656 \let \iftrial=\iffalse
659 % The boxes above will place the \z{parskip} glue before the first
660 % paragraph due to \.{\\kern0pt}. If you do not want this, you can use
661 % the \z{unparskip} command for helping.
664 \def\unparskip{\vskip-\parskip}
667 % Since the boxes in \z{textarea} are not allowed to contain rules, but
668 % you might want to put rules so we do using \z{boxrule} instead.
671 \def\boxrule#1{\noskip\vbox{\hrule#1}\noskip}
674 % You might also want to have two boxes on one line, and have it shrink
675 % the text horizontally in one or both boxes to make it fit. The baseline
676 % of the text will be at the specified coordinates.
678 % It will also check the badness of the created box. You can specify the
679 % maximum badness which is allowed. If this badness is exceeded, it will
680 % try again with a smaller size. You can specify 99999 as the maximum
681 % badness to make it try again only if the box is overfull.
683 % The font might deal with the magnification by changing only the
684 % horizontal size so that the letters can be stretched only horizontally.
686 % You can also set some fonts which do not resize, so that only one half
687 % of the box will stretch/shrink.
690 % \pairbox{x}{y}{width}{maxbadness}{ltext}{rtext}
691 \def\pairbox#1#2#3#4#5#6{%
692 \let\iftrial=\iftrue
693 \fontshrink=0 \loop
694 \hsize=#3
695 \setbox2=\hbox{#5}%
696 \setbox3=\hbox{#6}%
697 \dimenA=\wd2 \dimenB=\wd3
698 \advance\dimenA by \dimenB
699 \ifdim\dimenA<\hsize \let\iftrial=\iffalse \fi
700 \setbox1=\hbox to #3{\unhbox2\hfil\unhbox3}%
701 \ifnum\badness>#4 \let\iftrial=\iftrue \fi
702 \ifnum\fontshrink=\maxfontshrink \let\iftrial=\iffalse \fi
703 \iftrial \advance\fontshrink by 1 \repeat
704 \positionbase{#1}{#2}{\box1}%
708 % Now, you might have text that changes size in a group, relative to the
709 % current font size. For example, typing \.{\\textsize+2} makes the text
710 % two sizes larger than normal. This command should be entered inside of a
711 % group, since it affects the group.
714 \def\textsize{\begingroup\afterassignment\textsize_\countA}
715 \def\textsize_{%
716 \kern\countA sp\endgroup
717 \advance\fontshrink by -\lastkern \unkern
718 \ifnum\fontshrink<0 \fontshrink=0 \fi
719 \ifnum\fontshrink>\maxfontshrink \fontshrink=\maxfontshrink \fi
722 % --- Card symbols ---
725 % A symbol on the card might consist of a symbol from the same or a
726 % different font, from two fonts on two layers, or from a picture. In any
727 % case, the symbol must be scaled to the same size as the text.
730 % \symbol{font}{character}
731 \def\symbol#1#2{{#1\char#2}}%
733 % \symbolbg{font}{character}{layer}
734 \def\symbolbg#1#2#3{%
735 \begingroup
736 \layer=#3
737 \h_left{#1\char#2}%
738 \endgroup
739 \layer=\layer_selected
743 % Symbols with pictures (instead of with fonts) are called icons. The top
744 % left corner of the icon is at the top of the height above the baseline.
745 % Specials will be inserted in the paragraph at the baseline of the point
746 % where the icon should appear (and will be discarded if the paragraph is
747 % discarded). The picture size and box dimensions are adjusted by the
748 % \z{fontscale}.
751 % \icon{filename}{size_factor}{width}{height}{depth}
752 \def\icon#1#2#3#4#5{{%
753 \countA=#2 \dimenA=#3 \dimenB=#4 \dimenC=#5
754 \calculate_icon_size
755 \setbox0=\hbox{\special{\number\dimenB``D\the\countA[#1]`jx}}%
756 \wd0=\dimenA
757 \ht0=\dimenB
758 \dp0=\dimenC
759 \box0
762 \def\clear_icons{\special{[]si}}
764 \def\calculate_icon_size#1{%
765 \divide\dimenA by 25 \multiply\dimenA by\fontscale \divide\dimenA by 40
766 \divide\dimenB by 25 \multiply\dimenB by\fontscale \divide\dimenB by 40
767 \divide\dimenC by 25 \multiply\dimenC by\fontscale \divide\dimenC by 40
768 \multiply\countA by\fontscale \divide\countA by 1000
771 \def\paste_icons{\special{li`qx}}
774 % Another thing with symbols is symbols containing numbers. In this case,
775 % it might be necessary to resize the digits depending on how many there
776 % are. They will be centered within the box.
778 % For example, if using the digits `\.0' to `\.9' then you might set the
779 % `offset' parameter to 48 and `multiply' to 10. Now character code 25
780 % will be used to type a `\.5' in a three digit number.
783 % \numsymbol{font}{width}{offset}{multiply}{text}
784 \def\numsymbol#1#2#3#4#5{%
785 \hbox to #2{%
786 \count_tokens\countA={#5}%
787 \advance\countA by -1
788 \multiply\countA by #4
789 \advance\countA by -#3
790 \hss % Center
791 #1% Select font
792 \def\xxx##1{%
793 \ifx\relax##1%
794 \let\xxx\empty
795 \else
796 \countB=`##1%
797 \advance\countB by\countA
798 \char\countB
800 }\xxx#5\relax
801 \hss % Center
806 % Finally, there is the set symbols. You have to list the modes and layers
807 % numbers by spaces. The symbol number is the high nybble and the mode
808 % number is the low nybble of the character code. Both numbers should be
809 % in range 0 to 15.
812 % \setsymbol{font}{symbol_number}{modes}
813 \def\setsymbol#1#2#3{%
814 \begingroup
815 \def\setsymbol_{\afterassignment\setsymbol__\countC}%
816 \def\setsymbol__{%
817 \ifnum\countC=-1
818 \let\setsymbol_=\relax
819 \else
820 \h_left{%
821 \layer=\countC
822 \advance\countA by \countB
823 \char\countA
826 \afterassignment\setsymbol_\countB
829 \countA=#2
830 \multiply\countA by 16
831 \afterassignment\setsymbol_\countB #3 -1 -1 0
832 \layer=0
833 \hbox{\char\countA}
834 \endgroup
835 \layer=\layer_selected
838 % --- Image effects ---
841 % You should redefine these two macros for the directory name, filename
842 % prefix, and filename suffix (extension) that you want. You should also
843 % specify the file type in the prefix and/or suffix.
846 \def\image_filename_prefix{out/}
847 \def\image_filename_suffix{.png}
850 % The \z{operator} and \z{group} macros are common in ImageMagick (this
851 % has nothing to do with groups in \TeX).
854 \def\operator#1{\special{[#1]`qx}}
855 \def\group#1{\operator({#1}\operator)}
858 % This macro is used to write a card image to a file. It is used at the
859 % end of a page, and is expected to appear in outer vertical mode at the
860 % top-left corner of a page. The operators and so on that are pasted onto
861 % the card should be inside the group in the parameter.
864 \def\card_image#1{%
865 \group{%
866 \operator{-size \the\px_card_width x\the\px_card_height}%
867 \operator{xc:\the\backgroundcolor}%
868 {#1}%
869 \operator{-write}%
870 \operator{\image_filename_prefix\the\pageno\image_filename_suffix}%
871 }\operator{+delete}%
875 % The following macro is used to paste a layer picture onto the card. The
876 % first parameter is the layer number and the second parameter is the
877 % color of the text. We also have ones for pasting layers displaced by a
878 % number of pixels or by a dimension size.
881 % \paste_layer{layer}{color}
882 \def\paste_layer#1#2{%
883 \paste_layer_with{#1}{#2}{ }%
886 % \paste_layer_with{layer}{color}{with}
887 \def\paste_layer_with#1#2#3{%
888 \group{%
889 \operator{P\the\pageno L#1.pbm}%
890 \operator{-transparent white}%
891 \operator{-fill #2}%
892 \operator{-opaque black}%
893 \special{#3}%
895 \operator{-compose src-over}%
896 \operator{-composite}%
899 % \paste_layer_px{layer}{color}{x}{y}
900 \def\paste_layer_px#1#2#3#4{%
901 \paste_layer_with{\enumber{#3}rr\enumber{#4}[-roll]`rx}%
905 % Note that DVI units are the same as the scaled points which you will get
906 % when converting a dimension register to a numeric value in \TeX.
909 % \paste_layer_dim{layer}{color}{x}{y}
910 \def\paste_layer_dim#1#2#3#4{%
911 \dimenA=#3\relax
912 \dimenB=#4\relax
913 \paste_layer_with{\enumber{#3}C\enumber{#4}C[-roll]`rx}%
917 % This macro selects which layer to type on. Layer zero means do not
918 % typeset anything into a picture buffer, but it still must keep track of
919 % the current position on the page. Positive numbers 1 to 127 typeset onto
920 % that numbered picture buffer (using OR pen).
922 % The layer number must be set to the highest layer number used on a card
923 % before you end the page.
926 \def\layer{\afterassignment\layer_\layer_selected}
927 \def\layer_{\special{\the\layer_selected sL}}
929 % --- Meta page ---
931 \def\metapage#1#2#3{
932 \pageno=0 \resolution=#1 \px_card_width=#2 \px_card_height=#3
935 % This makes the \.q register which adds a operator or parameter to the
936 % end of the ImageMagick list.
939 \special{[lQdZ0[][ ]i+r+sQ]sq}
942 % This part is used to make optional parameters to ImageMagick with
943 % positive and negative coordinates. Such parameters might be \.{-roll}
944 % and so on.
947 \special{[d[0r-[-]][[+]]dixrB+]sn}
948 \special{[`qx`nxr`nx+`qx]sr}
951 % There is \.y like \.q but for icon list. And \.j then calls it.
954 \special{[lidZ0[][ ]i+r+si]sy}
955 \special{[% Parameters: ( height size_factor filename -- )
956 [(]`yx%
957 `yx% Filename
958 [-scale]`yx% Scale (resize)
959 d10\%B[.]r+% One tenths of a percent
960 r10/Br+% Units of a percent
961 [\%]+`yx% Percentage sign
962 [)]`yx%
963 lYrC-lX[-geometry]`yx`nxr`nx+`yx% Position of icon
964 [-compose src-over -composite +geometry]`yx% Paste and reset position
965 ]sj}%
968 % And now the end of the meta page.
971 \endpage
974 % --- End of file ---
976 \dump