Debian Codegraph @

texmf-dist/tex/generic/ean/ean13.tex

raw
1 %%%%%%%%%%%% The macro EAN generates EAN-13 barcodes. %%%%%%%%%%%%%%%%%
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %% May 8, 1995 Petr Olsak (Ol\v{s}\'ak)
4
5 % Don't change the (C) message.
6 % You can use the macro on your own risk.
7 % There is no warranty that the macro works OK.
8 % For more detail about algorithm see the article in TUGboat.
9
10 % Usage: For example \EAN 978-80-901950-0-4 generates the \vbox with barcodes
11 % in TeX hight accuracy using \rule primitive.
12 % The EAN number is appended downwards in OCR-b font (9pt).
13
14 % If the macro \ISBN is used before the \EAN macro call, the ISBN is
15 % appended upwards in OCR-b font (7pt) and the hight of barcodes is reduced.
16 % Example: \ISBN 80-901950-0-8 \EAN 978-80-901950-0-4
17 % Don't use brackets in parameters!
18 % The macro checks the checkdigit in EAN; it does not in ISBN.
19
20 % The bar correction is defined by \bcorr.
21 % Each bar width will be reduced by \bcorr amount and
22 % each space between bars will be enlarged by the same amount.
23 % Recommendation: If you plan the print by offset process, use the barcode
24 % correction 20 for your phototypesetter. This is the implicit value of
25 % \bcorr=.020mm (see bellow).
26
27 % You can overwrite some parameters at user level. For example:
28 % \input ean13
29 % \X=0.396mm % the module size is 120% of standard
30 % \font\ocrb=ocrb9 scaled 1200 % re-load font to the new size
31 % \font\ocrbsmall=ocrb7 scaled 1200 % re-load font to the new size
32 % \bcorr=0.015mm % new bar correction
33 % \ISBN 80-901950-0-8
34 % \barheight=1.5cm % this must be after \ISBN call
35 % \EAN 978-80-901950-0-8 % produces barcode with ISBN
36 % \end % at 120% with height of bars 1.5cm
37
38 % The tolerance of dimensions for basic size (100%, module size .33mm)
39 % is 0.101 mm, 0.049 mm and 0.096 mm for various parameters.
40 % You can compare: The TeX accuracy is 0.0000054 mm.
41 % If you use the phototypesetter 2400 dpi then the accuracy is 0.01 mm.
42
43
44 \message{The EAN-13 barcodes macro. Copyright (C) Petr Olsak, 1995}
45 \font\ocrb=ocrb9 % for EAN in ``number form''
46 \font\ocrbsmall=ocrb7 % for ISBN
47 \newcount\numlines \newcount\nummodules % number of bars and of modules.
48 \newcount\numdigit \newcount\evensum \newcount\oddsum % internal variables
49 \newdimen\X % the module size X,
50 \newdimen\bcorr % the bar correction (see bellow).
51 \newdimen\workdimen \newdimen\barheight % internal variables
52 \def\internalcode{0111} % Begin mark at start
53 \def\frontdigits{} % 12--7 digit of EAN
54 \def\EAN{\begingroup\EANscan}
55 \def\EANscan#1{\if#1-\let\next=\EANscan \else
56 \advance\numdigit by1
57 \ifnum\numdigit<13
58 \ifodd\numdigit \advance\oddsum by #1 \else \advance\evensum by #1 \fi
59 \let\next=\EANscan
60 \ifnum\numdigit=1 \settables#1\def\firstdigit{#1}\else
61 \ifnum\numdigit<8 \usetabAB#1\edef\frontdigits{\frontdigits#1}\else
62 \ifnum\numdigit=8 \insertseparator \A \usetabC #1\def\enddigits{#1}%
63 \else \usetabC#1\edef\enddigits{\enddigits#1}%
64 \fi\fi\fi
65 \else \testchecksum#1\usetabC#1\edef\enddigits{\enddigits#1}%
66 \let\next=\EANclose
67 \fi\fi \next}
68 \def\testchecksum#1{\multiply\evensum by3 \advance\evensum by\oddsum
69 \oddsum=\evensum
70 \divide\oddsum by10 \multiply\oddsum by10 \advance\oddsum by10
71 \advance\oddsum by-\evensum \ifnum\oddsum=10 \oddsum=0 \fi
72 \ifnum#1=\oddsum \else
73 \errmessage{The checksum digit has to be \the\oddsum, no #1 !}\fi}
74 \def\EANclose{\insertendmark
75 \wlog{EAN: \firstdigit\space\frontdigits\space\enddigits}%
76 \wlog{EANinternal: \internalcode}%
77 \expandafter\EANbox\internalcode..\endgroup}
78 \def\A{\def\0{3211}\def\1{2221}\def\2{2122}\def\3{1411}\def\4{1132}%
79 \def\5{1231}\def\6{1114}\def\7{1312}\def\8{1213}\def\9{3112}}
80 \def\B{\def\0{1123}\def\1{1222}\def\2{2212}\def\3{1141}\def\4{2311}%
81 \def\5{1321}\def\6{4111}\def\7{2131}\def\8{3121}\def\9{2113}}
82 \def\settables#1{\ifnum#1=0 \def\tabs{\A\A\A\A\A\A}\fi
83 \ifnum#1=1 \def\tabs{\A\A\B\A\B\B}\fi
84 \ifnum#1=2 \def\tabs{\A\A\B\B\A\B}\fi
85 \ifnum#1=3 \def\tabs{\A\A\B\B\B\A}\fi
86 \ifnum#1=4 \def\tabs{\A\B\A\A\B\B}\fi
87 \ifnum#1=5 \def\tabs{\A\B\B\A\A\B}\fi
88 \ifnum#1=6 \def\tabs{\A\B\B\B\A\A}\fi
89 \ifnum#1=7 \def\tabs{\A\B\A\B\A\B}\fi
90 \ifnum#1=8 \def\tabs{\A\B\A\B\B\A}\fi
91 \ifnum#1=9 \def\tabs{\A\B\B\A\B\A}\fi}
92 \def\usetabAB#1{\expandafter\scantab\tabs\end \usetabC #1}
93 \def\scantab#1#2\end{#1\def\tabs{#2}} % The tab #1 is activated and removed
94 \def\usetabC#1{\edef\internalcode{\internalcode\csname#1\endcsname}}
95 \def\insertseparator{\edef\internalcode{\internalcode 11111}}
96 \def\insertendmark{\edef\internalcode{\internalcode 111}}
97 \def\EANbox{\vbox\bgroup\offinterlineskip
98 \setbox0=\hbox\bgroup \kern11\X\EANrepeat}
99 \def\EANrepeat#1#2{\if#1.\let\next=\EANfinal \else\let\next=\EANrepeat
100 \advance\numlines by1
101 \advance\nummodules by#1 \advance\nummodules by#2
102 \workdimen=#1\X \advance\workdimen by \bcorr \kern\workdimen
103 \workdimen=#2\X \advance\workdimen by-\bcorr \vrule width\workdimen
104 \ifdim\barheight=0pt height 69.24242424\X \else height\barheight \fi
105 \ifnum\numlines=1 depth5\X\else % the start mark
106 \ifnum\numlines=2 depth5\X\else
107 \ifnum\numlines=15 depth5\X\else % the separator mark
108 \ifnum\numlines=16 depth5\X\else
109 \ifnum\numlines=29 depth5\X\else % the end mark
110 \ifnum\numlines=30 depth5\X\else depth0pt \fi\fi\fi\fi\fi\fi
111 \fi\next}
112 \def\EANfinal{\testconsistence
113 \kern7\X\egroup
114 \hbox{\ocrbsmall \kern10\X \ISBNnum}\kern1\X
115 \dp0=0pt \box0 \kern-1\X
116 \hbox{\ocrb\kern2\X\firstdigit\kern5\X \frontdigits\kern5\X \enddigits}
117 \egroup \global\barheight=0pt \gdef\ISBNnum{}}
118 \def\testconsistence{\ifnum\numlines=30\else\internalerr\fi
119 \ifnum\nummodules=95\else\internalerr\fi}
120 \def\internalerr{\errmassage{Sorry, my internal tables are wrong, may be.}}
121 \barheight=0pt
122 \def\ISBNnum{}
123 \def\ISBN #1 {\def\ISBNnum{ISBN #1}\barheight=45.151515\X\relax}
124 \X=.33mm % Basic size 100%, SC2 code
125 \bcorr=.020mm % Bar-correction for offset process
126 \endinput
127
128
129
130