Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!julius.cs.uiuc.edu!ux1.cso.uiuc.edu!news.iastate.edu!sharkey!applga!dsmith From: dsmith@applga.aa.cad.slb.com (J. Daniel Smith) Newsgroups: comp.text.tex Subject: Re: Printing Zipcode bars using tex/latex Message-ID: <1991Feb11.141820.5857@applga.aa.cad.slb.com> Date: 11 Feb 91 14:18:20 GMT References: <1991Feb7.175608.5783@portia.Stanford.EDU> Organization: Schlumberger CAD/CAM ; Ann Arbor, MI Lines: 116 In article <1991Feb7.175608.5783@portia.Stanford.EDU> rsingh@elaine0.stanford.edu (Rajesh Kumar Singh) writes: >Hello, > >Has anyone tried writing a command in tex or latex >that would print the Zipcode bars? Something like >\zipcode{12345}{1234} that prints the long and short >vertical bars as mass mailing companies and postoffice I played around with this about a year or so ago... (Someone posted PostScript code to do this in comp.lang.postscript, and I wanted to show it could be done in TeX, too). The following macro file is what I finally ended up with. If I remember correctly, some of the code was snarfed from another .STY file, but like a total idiot, I forgot to mention that in the STY file at the time.... I've also hacked together a few TeX macros for using printing the ZIP code exactly where the USPS wants it on an envelope, along with typesetting the address in USPS preferred style. Its been a while since I've done much with them, but if anybody want to take a look, let me know... Dan --- % % J. Daniel Smith % 24 May 1990 % % Modified from a STY file snarfed from someplace else. But I don't % remember where the original code came from... OOPS!!! % % Make a barcode for a ZIP code! % % Example usage is below. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \catcode`@=11 % letter % % Dimensions of bars to be used in the barcode \newdimen\b@rwidth \newdimen\b@rlong \newdimen\b@rshort \newdimen\b@rsep \b@rwidth=0.02true in \b@rlong=0.125true in \b@rshort=0.05true in \b@rsep=0.0275true in \def\sb@r{\vrule height\b@rshort width\b@rwidth depth0pt \kern\b@rsep} \def\lb@r{\vrule height\b@rlong width\b@rwidth depth0pt \kern\b@rsep} % The barcodes for each digit \def\zerob@r{\lb@r\lb@r\sb@r\sb@r\sb@r} \def\oneb@r{\sb@r\sb@r\sb@r\lb@r\lb@r} \def\twob@r{\sb@r\sb@r\lb@r\sb@r\lb@r} \def\threeb@r{\sb@r\sb@r\lb@r\lb@r\sb@r} \def\fourb@r{\sb@r\lb@r\sb@r\sb@r\lb@r} \def\fiveb@r{\sb@r\lb@r\sb@r\lb@r\sb@r} \def\sixb@r{\sb@r\lb@r\lb@r\sb@r\sb@r} \def\sevenb@r{\lb@r\sb@r\sb@r\sb@r\lb@r} \def\eightb@r{\lb@r\sb@r\sb@r\lb@r\sb@r} \def\nineb@r{\lb@r\sb@r\lb@r\sb@r\sb@r} \newcount\zipb@rm \newcount\zipb@rn \chardef\ten=10 %Almost like using \ifcase... except `-' is ignored. \def\zipb@r@@@#1#2{\expandafter\def\csname zipb@r@@#1\endcsname% {#2\advance\zipb@rn#1\relax}} \newbox\zipbarcode \zipb@r@@@0{\global\setbox\zipbarcode\hbox{\box\zipbarcode\zerob@r}} \zipb@r@@@1{\global\setbox\zipbarcode\hbox{\box\zipbarcode\oneb@r}} \zipb@r@@@2{\global\setbox\zipbarcode\hbox{\box\zipbarcode\twob@r}} \zipb@r@@@3{\global\setbox\zipbarcode\hbox{\box\zipbarcode\threeb@r}} \zipb@r@@@4{\global\setbox\zipbarcode\hbox{\box\zipbarcode\fourb@r}} \zipb@r@@@5{\global\setbox\zipbarcode\hbox{\box\zipbarcode\fiveb@r}} \zipb@r@@@6{\global\setbox\zipbarcode\hbox{\box\zipbarcode\sixb@r}} \zipb@r@@@7{\global\setbox\zipbarcode\hbox{\box\zipbarcode\sevenb@r}} \zipb@r@@@8{\global\setbox\zipbarcode\hbox{\box\zipbarcode\eightb@r}} \zipb@r@@@9{\global\setbox\zipbarcode\hbox{\box\zipbarcode\nineb@r}} \def\zipb@r@@#1{\csname zipb@r@@#1\endcsname} \def\zipb@r@#1{\ifx#1\null \let\next\relax \else \zipb@r@@{#1}#1% \let\next\zipb@r@ \fi \next} \def\zipbar#1{\setbox\zipbarcode=\null \hbox{ % put numbers in an \hbox \global\setbox\zipbarcode\hbox{\box\zipbarcode\lb@r} % start with long bar \zipb@rn\z@\zipb@r@#1\null \zipb@rm\zipb@rn \divide\zipb@rm\ten \multiply\zipb@rm\ten \advance\zipb@rm-\zipb@rn \ifnum\zipb@rm<0 \advance\zipb@rm\ten \fi \zipb@r@@{\the\zipb@rm} % last digit, so that the sum is divisible by ten \global\setbox\zipbarcode\hbox{\box\zipbarcode\lb@r}% end with a long bar } % end of \hbox } \catcode`@=12 % disable private sequences %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %\zipbar{1234567890} % %\zipbar{48837} % %\zipbar{78653--0102} %\bye \endinput -- =========================================================================== J. Daniel Smith Internet: dsmith@applga.aa.cad.slb.com Schlumberger CAD/CAM BITNET: smithdan@msuegr Ann Arbor, Michigan Usenet: uunet!sharkey!applga!dsmith