64

For some problem for textbook I need the digits 0...9 like in zip-codes on the Soviet-Union postal envelopes,

like this

an example of USSR envelope

Does anybody know the possible font or package for getting them in LaTeX? Thanks

  • 7
    It occurs to me that this font is a great opportunity to use METAFONT. Anyone? :-) – ShreevatsaR Oct 5 '17 at 5:01
  • 2
    Are Soviet Union postal codes from this point of view any different than Russian Federation postal codes? – gerrit Oct 5 '17 at 10:21
  • 1
    could you provide a complete set how the numbers should look like? Especially the number 3 could have different solutions. – Jonas Stein Oct 5 '17 at 21:02
  • 1
    >DP_ Oct 10 at 11:20 May I ask you what you need these characters for? -- I comment a child problem how to shift match in order to change "matches" equality, but from algebraic viewpoint. The original equation is given as a picture, but in the text I need the corresponding characters. For this case I need 0,2,3,4,5,6,8 and 9 like in the 1st answer here, 1 as Latin I and 7 as (right) I + upper bar. – torcli Oct 14 '17 at 18:25
  • 1
    >Jonas Stein Oct 5 at 21:02 could you provide a complete set how the numbers should look like? Especially the number 3 could have different solutions. -- Yes, I need these characters with no diagonals, by the reason I mentioned above. So 1, 3 and 7 I need, are different from the zip-code. But I'll try to organize them also – torcli Oct 14 '17 at 18:32
57

enter image description here

No fonts or packages but...

\documentclass{article}

\def\zz#1{%
\begin{picture}(10,20)\thicklines
\ifx7#1\else\ifx4#1\else\ifx1#1\else
  \put(0,0){\line(1,0){10}}%
\fi\fi\fi
\ifx7#1\else\ifx1#1\else\ifx0#1\else
  \put(0,10){\line(1,0){10}}%
\fi\fi\fi
\ifx4#1\else\ifx1#1\else
  \put(0,20){\line(1,0){10}}%
\fi\fi
%
\ifx9#1\else\ifx8#1\else\ifx7#1\else\ifx6#1\else\ifx5#1\else\ifx4#1\else\ifx3#1\else\ifx2#1\else\ifx1#1\else\ifx0#1\else
  \put(0,0){\line(1,1){10}}%
\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
\ifx9#1\else\ifx8#1\else\ifx6#1\else\ifx5#1\else\ifx4#1\else\ifx3#1\else\ifx2#1\else\ifx0#1\else
  \put(0,10){\line(1,1){10}}%
\fi\fi\fi\fi\fi\fi\fi\fi
%
\ifx9#1\else\ifx5#1\else\ifx4#1\else\ifx3#1\else\ifx1#1\else
  \put(0,0){\line(0,1){10}}%
\fi\fi\fi\fi\fi
\ifx7#1\else\ifx3#1\else\ifx2#1\else\ifx1#1\else
  \put(0,10){\line(0,1){10}}%
\fi\fi\fi\fi
\ifx7#1\else\ifx2#1\else
  \put(10,0){\line(0,1){10}}%
\fi\fi
\ifx7#1\else\ifx6#1\else\ifx5#1\else
  \put(10,10){\line(0,1){10}}%
\fi\fi\fi
\end{picture}}

\begin{document}

\zz0 \zz1 \zz2 \zz3 \zz4 \zz5 \zz6 \zz7 \zz8 \zz9


\end{document}
  • 4
    Haha so cool! Using picture mode rather than a font seems absurd at first sight but after looking carefully at the Soviet Union Postal-code-style digits, such mechanical pictures is exactly what they are. – ShreevatsaR Oct 5 '17 at 3:02
  • 21
    But I think you need some tweaks to your 2, 3, 6, 9 (those digits are even weirder than expected). – ShreevatsaR Oct 5 '17 at 3:22
  • 1
    @ShreevatsaR possibly, I am more used to the old "calculator LED" displays that did not have the diagonals, so I just guessed where the diagonals where used, but anyway it's only a matter of moving \ifx3#1 and \fi from one line to another to turn a line off or on for 3 – David Carlisle Oct 5 '17 at 6:37
  • 1
    @ShreevatsaR - in a font, each letter is a picture. So, IMHO he just defined a mini-font. – Omnifarious Oct 8 '17 at 20:01
49

Here is solution using primitive \pdfliteral. It is format independent. You can use scaling before usage if you need another size than 10 pt.

\def\bA{0 0 }\def\bB{5 0 }\def\bC{0 5 }\def\bD{5 5 }\def\bE{0 10 }\def\bF{5 10 }
\def\SUdigit#1{\leavevmode\kern1pt\hbox to5pt{\vbox to 10pt{}%
   \pdfliteral{q 0.9963 0 0 0.9963 0 0 cm 1 j 1 J 
      \ifcase#1 \bA m \bB l \bF l \bE l h S \or               % 0
                \bC m \bF l \bB l S \or                       % 1
                \bE m \bF l \bD l \bA l \bB l S \or           % 2
                \bE m \bF l \bC l \bD l \bA l S \or           % 3
                \bE m \bC l \bD l S \bF m \bB l S \or         % 4
                \bF m \bE l \bC l \bD l \bB l \bA l S \or     % 5
                \bF m \bC l \bA l \bB l \bD l \bC l S \or     % 6             
                \bE m \bF l \bC l \bA l S \or                 % 7
                \bA m \bB l \bF l \bE l h S \bC m \bD l S \or % 8
                \bA m \bD l \bF l \bE l \bC l \bD l S \fi     % 9
      Q}\hss}\kern1pt
}

\SUdigit 0 \SUdigit 1 \SUdigit 2 \SUdigit 3 \SUdigit 4
\SUdigit 5 \SUdigit 6 \SUdigit 7 \SUdigit 8 \SUdigit 9

\bye

USpostal

46

Pechkin, ZipCode or PostIndex fonts will do the job.

Pechkin font

43

Using TikZ for this is a slight overkill...

\documentclass[varwidth,border=5]{standalone}
\usepackage{tikz}
\def\zipdigit#1{\tikz[x=1ex, y=1ex, line join=round, line cap=round]{%
\draw [line width=0.05ex, dash pattern=on 0ex off .2ex, gray!50] 
  (0,0) rectangle (1,2) (0,0) -- (1,1) -- (0,1) -- (1,2);
\useasboundingbox (-1/4,0)(1/4,2);
\draw [line width=0.1ex]\ifcase#1
      (0,0) rectangle (1,2)
  \or (0,1) -- (1,2) -- (1,0)
  \or (0,2) -| (1,1) -- (0,0) -- (1,0)
  \or (0,2) -- (1,2) -- (0,1) -- (1,1) -- (0,0)
  \or (0,2) |- (1,1) (1,0) -- (1,2)
  \or (1,2) -| (0,1) -| (1,0) -- (0,0)
  \or (1,2) -- (0,1) -| (1,0) -| (0,1)
  \or (0,2) -- (1,2) -- (0,1) -- (0,0)
  \or (0,0) rectangle (1,2) (0,1) -- (1,1)
  \or (1,1) -| (0,2) -| (1,1) -- (0,0) \fi;
}}
\def\zipcode#1{\Zipcode#1;}
\def\Zipcode#1{\ifx#1;\else\zipdigit{#1}\expandafter\Zipcode\fi}
\begin{document}
\zipcode{0123456789}
\foreach \fs in {\tiny, \small, \normalsize, \large, \huge}{%
\\\fs Zip: \zipcode{107014}}
\end{document}

enter image description here

So, instead lets try metafont. I have no real experience of metafont so this is just teensy proof of concept and I am also probably doing loads of things wrong. First the metafont file:

beginchar("0",7pt#,11pt#,0);
  y1=0;
  x1=1pt;
  y2=0.75*h/2;
  x2=x1+0.75*h/2;
  y3=0.75*h;
  pickup pencircle xscaled 0.1h yscaled 0.1h;
  draw (x1,y1)--(x1,y3)--(x2,y3)--(x2,y1)--cycle;
endchar;
beginchar("1",7pt#,11pt#,0);
  y1=0;
  x1=1pt;
  y2=0.75*h/2;
  x2=x1+0.75*h/2;
  y3=0.75*h;
  pickup pencircle xscaled 0.1h yscaled 0.1h;
  draw (x1,y2)--(x2,y3)--(x2,y1);
endchar;
beginchar("2",7pt#,11pt#,0);
  y1=0;
  x1=1pt;
  y2=0.75*h/2;
  x2=x1+0.75*h/2;
  y3=0.75*h;
  pickup pencircle xscaled 0.1h yscaled 0.1h;
  draw (x1,y3)--(x2,y3)--(x2,y2)--(x1,y1)--(x2,y1);
endchar;
beginchar("3",8pt#,11pt#,0);
  y1=0;
  x1=1pt;
  y2=0.75*h/2;
  x2=x1+0.75*h/2;
  y3=0.75*h;
  pickup pencircle xscaled 0.1h yscaled 0.1h;
  draw (x1,y3)--(x2,y3)--(x1,y2)--(x2,y2)--(x1,y1);
endchar;
beginchar("4",8pt#,11pt#,0);
  y1=0;
  x1=1pt;
  y2=0.75*h/2;
  x2=x1+0.75*h/2;
  y3=0.75*h;
  pickup pencircle xscaled 0.1h yscaled 0.1h;
  draw (x1,y3)--(x1,y2)--(x2,y2);
  draw (x2,y3)--(x2,y1);
endchar;
beginchar("5",8pt#,11pt#,0);
  y1=0;
  x1=1pt;
  y2=0.75*h/2;
  x2=x1+0.75*h/2;
  y3=0.75*h;
  pickup pencircle xscaled 0.1h yscaled 0.1h;
  draw (x2,y3)--(x1,y3)--(x1,y2)--(x2,y2)--(x2,y1)--(x1,y1);
endchar;
beginchar("6",8pt#,11pt#,0);
  y1=0;
  x1=1pt;
  y2=0.75*h/2;
  x2=x1+0.75*h/2;
  y3=0.75*h;
  pickup pencircle xscaled 0.1h yscaled 0.1h;
  draw (x2,y3)--(x1,y2)--(x2,y2)--(x2,y1)--(x1,y1)--(x1,y2);
endchar;
beginchar("7",8pt#,11pt#,0);
  y1=0;
  x1=1pt;
  y2=0.75*h/2;
  x2=x1+0.75*h/2;
  y3=0.75*h;
  pickup pencircle xscaled 0.1h yscaled 0.1h;
  draw (x1,y3)--(x2,y3)--(x1,y2)--(x1,y1);
endchar;
beginchar("8",8pt#,11pt#,0);
  y1=0;
  x1=1pt;
  y2=0.75*h/2;
  x2=x1+0.75*h/2;
  y3=0.75*h;
  pickup pencircle xscaled 0.1h yscaled 0.1h;
  draw (x1,y1)--(x1,y3)--(x2,y3)--(x2,y1)--cycle;
  draw (x1,y2)--(x2,y2);
endchar;
beginchar("9",8pt#,11pt#,0);
  y1=0;
  x1=1pt;
  y2=0.75*h/2;
  x2=x1+0.75*h/2;
  y3=0.75*h;
  pickup pencircle xscaled 0.1h yscaled 0.1h;
  draw (x2,y2)--(x2,y3)--(x1,y3)--(x1,y2)--(x2,y2)--(x1,y1);
endchar;
end

Save in a file called zpru.mf and compile this with:

mf '\mode=ljfour; mode_setup; input zpru.mf'; gftopk zpru.600gf zpru.600pk

In the same directory create the following TeX file:

\documentclass[varwidth,border=5]{standalone}
\newfont{\zpru}{zpru}
\begin{document} 
\zpru 0123456789
\end{document} 

Et voilà:

enter image description here

  • 11
    with tikz, one would expect at least that you reproduce the whole postcard ;-) – user4686 Oct 5 '17 at 14:44
  • 1
    Could you please explain the useasboundingbox values? I expected something like (-1/4,0) (5/4, 0)... can't understand why it's working with your numbers ;-) – Rmano Oct 5 '17 at 15:57
  • @Rmano those numbers are a mistake. Probably should be (-1/8,0) (9/8,0) – Mark Wibrow Oct 5 '17 at 17:54
34

When Knuth designed TeX in 1977, he designed a companion system called METAFONT (and this was actually his primary motivation at that time: to define his own fonts). This is a declarative language in which one explains how to draw characters, which is both its strength and weakness. It directly generates the pixel representation at a particular resolution, while the rest of the world since then has ended up going in the other direction, so for most applications (such as rendering on screen) it does not work well today. So this one is an answer more for interest/curiosity rather than (alas) practical utility, but nevertheless this question is an opportunity for a simple demonstration of METAFONT. (Note this is my first time using METAFONT, so it may not illustrate good practice.)

For these postal code digits, if you imagine the grid on which they are drawn, you can specify the coordinates of the interesting points and give them names 1 to 6 (w and h are the width and height of the character):

m := 0.5*h;
z1=(0,h); z2=(w,h);
z3=(0,m); z4=(w,m);
z5=(0,0); z6=(w,0);

Then each character can be given a simple definition: for example, the character 1 can be defined as drawing a line from point 3 to point 2 to (point 4 to) point 6. And this is what you can tell METAFONT:

draw z3--z2--z6;

digit 1

METAFONT has macros (like TeX), so with a macro begincchar for defining the points z1 to z6, the definitions of the 10 digits can simply be:

begincchar("0"); draw z2--z1--z5--z6--cycle; endchar;
begincchar("1"); draw z3--z2--z6; endchar;
begincchar("2"); draw z1--z2--z4--z5--z6; endchar;
begincchar("3"); draw z1--z2--z3--z4--z5; endchar;
begincchar("4"); draw z1--z3--z4; draw z2--z6; endchar;
begincchar("5"); draw z2--z1--z3--z4--z6--z5; endchar;
begincchar("6"); draw z2--z3--z5--z6--z4--z3; endchar;
begincchar("7"); draw z1--z2--z3--z5; endchar;
begincchar("8"); draw z2--z1--z5--z6--cycle; draw z3--z4; endchar;
begincchar("9"); draw z4--z3--z1--z2--z4--z5; endchar;

digits generated with METAFONT

You can programmatically parametrize various things, like the widths and heights, the left and right “gaps” (sidebearings), the height of the middle line, the thickness of the font, etc., to generate different fonts. Put the following in postaldefault.mf:

leftgap := 0.1;
rightgap := 0.1;
penthickness := 0.08;
midlineheight := 0.5;
toplineheight := 1;
width# := 9pt#;
height# := 10pt#;
input postal

and the following in postalbizarre.mf

leftgap := 0.4;
rightgap := 0.1;
penthickness := 0.12;
midlineheight := 0.3;
toplineheight := 0.9;
width# := 5pt#;
height# := 8pt#;
input postal

both of which are parameter files wrapping the common character definitions, in postal.mf:

mode_setup;
def begincchar(expr c) =
  beginchar(c, width#, height#, 0);
    t := toplineheight * h;
    m := midlineheight * h;
    a := leftgap * w;  b := w - rightgap * w;
    z1=(a,t); z2=(b,t);
    z3=(a,m); z4=(b,m);
    z5=(a,0); z6=(b,0);
    pickup pencircle scaled (penthickness * w);
    penlabels(1,2,3,4,5,6);
enddef;
begincchar("0"); draw z2--z1--z5--z6--cycle; endchar;
begincchar("1"); draw z3--z2--z6; endchar;
begincchar("2"); draw z1--z2--z4--z5--z6; endchar;
begincchar("3"); draw z1--z2--z3--z4--z5; endchar;
begincchar("4"); draw z1--z3--z4; draw z2--z6; endchar;
begincchar("5"); draw z2--z1--z3--z4--z6--z5; endchar;
begincchar("6"); draw z2--z3--z5--z6--z4--z3; endchar;
begincchar("7"); draw z1--z2--z3--z5; endchar;
begincchar("8"); draw z2--z1--z5--z6--cycle; draw z3--z4; endchar;
begincchar("9"); draw z4--z3--z1--z2--z4--z5; endchar;
end

Now you can use these fonts in TeX/LaTeX:

\documentclass{article}  
\begin{document}
\font\postaldefault=postaldefault
\font\postalbizarre=postalbizarre
\pagestyle{empty}
These digits {\postaldefault 0123456789} are postal.

These digits {\postalbizarre 0123456789} are postal.
\end{document}

(Note: For best results, don't compile the above with pdflatex, but with latex and then something like dvipng -D 1200 on the DVI file. I told you this answer was not for practical utility!)

output

23

We can get various customizations by using pict2e and expl3. The keys are

  • width (default 0.5cm) for the side of the base square
  • space (default 0.25cm) for the space between digits
  • thickness (default 0.8pt) for the thickness of the strokes
  • cap (default round) for the shape of the stroke ends
  • join (default round) for the shape of the joins.

The possible values for cap are round, butt and square; the possible values for join are round, miter or bevel.

\documentclass{article}
\usepackage{pict2e}
\usepackage{xparse}

\ExplSyntaxOn
% define the digits
\prop_new:N \g_torcli_sovietdigits_prop
\prop_gput:Nnn \g_torcli_sovietdigits_prop { 0 }
 {
  \moveto(0,0)\lineto(1,0)\lineto(1,2)\lineto(0,2)\closepath
  \strokepath
 }
\prop_gput:Nnn \g_torcli_sovietdigits_prop { 1 }
 {
  \moveto(0,1)\lineto(1,2)\lineto(1,0)
  \strokepath
 }
\prop_gput:Nnn \g_torcli_sovietdigits_prop { 2 }
 {
  \moveto(0,2)\lineto(1,2)\lineto(1,1)
  \lineto(0,0)\lineto(1,0)
  \strokepath
 }
\prop_gput:Nnn \g_torcli_sovietdigits_prop { 3 }
 {
  \moveto(0,2)\lineto(1,2)\lineto(0,1)
  \lineto(1,1)\lineto(0,0)
  \strokepath
 }
\prop_gput:Nnn \g_torcli_sovietdigits_prop { 4 }
 {
  \moveto(0,2)\lineto(0,1)\lineto(1,1)\strokepath
  \moveto(1,2)\lineto(1,0)\strokepath
 }
\prop_gput:Nnn \g_torcli_sovietdigits_prop { 5 }
 {
  \moveto(1,2)\lineto(0,2)\lineto(0,1)\lineto(1,1)
  \lineto(1,0)\lineto(0,0)
  \strokepath
 }
\prop_gput:Nnn \g_torcli_sovietdigits_prop { 6 }
 {
  \moveto(1,2)\lineto(0,1)\lineto(0,0)\lineto(1,0)
  \lineto(1,1)\lineto(0,1)
  \strokepath
 }
\prop_gput:Nnn \g_torcli_sovietdigits_prop { 7 }
 {
  \moveto(0,2)\lineto(1,2)\lineto(0,1)\lineto(0,0)
  \strokepath
 }
\prop_gput:Nnn \g_torcli_sovietdigits_prop { 8 }
 {
  \moveto(0,0)\lineto(1,0)\lineto(1,2)\lineto(0,2)\closepath
  \strokepath
  \moveto(0,1)\lineto(1,1)
  \strokepath
 }  
\prop_gput:Nnn \g_torcli_sovietdigits_prop { 9 }
 {
  \moveto(0,0)\lineto(1,1)\lineto(1,2)\lineto(0,2)
  \lineto(0,1)\lineto(1,1)
  \strokepath
 }

\NewDocumentCommand{\postalcode}{O{}m}
 {
  \mbox
   {
    \keys_set:nn { torcli/sovietdigits } { #1 }
    \torcli_sovietdigits_print:n { #2 }
   }
 }

\keys_define:nn { torcli/sovietdigits }
 {
  width     .dim_set:N = \l_torcli_sovietdigits_width_dim,
  thickness .dim_set:N = \l_torcli_sovietdigits_thickness_dim,
  space     .dim_set:N = \l_torcli_sovietdigits_space_dim,
  cap       .tl_set:N  = \l_torcli_sovietdigits_cap_tl,
  join      .tl_set:N  = \l_torcli_sovietdigits_join_tl,
  width     .initial:n = 0.5cm,
  thickness .initial:n = 0.8pt,
  space     .initial:n = 0.25cm,
  cap       .initial:n = round,
  join      .initial:n = round,
 }

\seq_new:N \l__torcli_sovietdigits_number_seq

\cs_new_protected:Nn \torcli_sovietdigits_print:n
 {
  \dim_set_eq:NN \unitlength \l_torcli_sovietdigits_width_dim
  \linethickness{\l_torcli_sovietdigits_thickness_dim}
  \tl_map_inline:nn { #1 }
   {
    \seq_put_right:Nx \l__torcli_sovietdigits_number_seq
     {
      \__torcli_sovietdigits_digit:n { \prop_item:Nn \g_torcli_sovietdigits_prop { ##1 } }
     }
   }
  \seq_use:Nn \l__torcli_sovietdigits_number_seq { \hspace{\l_torcli_sovietdigits_space_dim} }
 }

\cs_new_protected:Nn \__torcli_sovietdigits_digit:n
 {
  \begin{picture}(1,2)
  \use:c { \l_torcli_sovietdigits_join_tl join }
  \use:c { \l_torcli_sovietdigits_cap_tl cap }
  #1
  \end{picture}
 }

\ExplSyntaxOff

\begin{document}

\postalcode{0123456789}

\bigskip

\postalcode{107714}

\bigskip

\postalcode[space=1cm]{107714}

\bigskip

\postalcode[thickness=3pt]{107714}\quad
\postalcode[thickness=3pt,join=miter,cap=square]{107714}

\bigskip

\postalcode[width=0.2cm]{107714}

\end{document}

enter image description here

A new version, without pict2e, but using the experimental drawing facilities of expl3; an addition is the possibility of asking width=font so that the digits will be adapted to the size of capitals in the current text font.

\documentclass[varwidth,border=4]{standalone}
\usepackage{xparse}

\ExplSyntaxOn
% define the digits
\prop_new:N \g_sovietdigits_prop
\prop_gput:Nnn \g_sovietdigits_prop { 0 }
 {
  \__sovietdigits_moveto:nn {0}{0}
  \__sovietdigits_lineto:nn {1}{0}
  \__sovietdigits_lineto:nn {1}{2}
  \__sovietdigits_lineto:nn {0}{2}
  \driver_draw_closestroke:
 }
\prop_gput:Nnn \g_sovietdigits_prop { 1 }
 {
  \__sovietdigits_moveto:nn {0}{1}
  \__sovietdigits_lineto:nn {1}{2}
  \__sovietdigits_lineto:nn {1}{0}
  \driver_draw_stroke:
 }
\prop_gput:Nnn \g_sovietdigits_prop { 2 }
 {
  \__sovietdigits_moveto:nn {0}{2}
  \__sovietdigits_lineto:nn {1}{2}
  \__sovietdigits_lineto:nn {1}{1}
  \__sovietdigits_lineto:nn {0}{0}
  \__sovietdigits_lineto:nn {1}{0}
  \driver_draw_stroke:
 }
\prop_gput:Nnn \g_sovietdigits_prop { 3 }
 {
  \__sovietdigits_moveto:nn {0}{2}
  \__sovietdigits_lineto:nn {1}{2}
  \__sovietdigits_lineto:nn {0}{1}
  \__sovietdigits_lineto:nn {1}{1}
  \__sovietdigits_lineto:nn {0}{0}
  \driver_draw_stroke:
 }
\prop_gput:Nnn \g_sovietdigits_prop { 4 }
 {
  \__sovietdigits_moveto:nn {0}{2}
  \__sovietdigits_lineto:nn {0}{1}
  \__sovietdigits_lineto:nn {1}{1}
  \driver_draw_stroke:
  \__sovietdigits_moveto:nn {1}{2}
  \__sovietdigits_lineto:nn {1}{0}
  \driver_draw_stroke:
 }
\prop_gput:Nnn \g_sovietdigits_prop { 5 }
 {
  \__sovietdigits_moveto:nn {1}{2}
  \__sovietdigits_lineto:nn {0}{2}
  \__sovietdigits_lineto:nn {0}{1}
  \__sovietdigits_lineto:nn {1}{1}
  \__sovietdigits_lineto:nn {1}{0}
  \__sovietdigits_lineto:nn {0}{0}
  \driver_draw_stroke:
 }
\prop_gput:Nnn \g_sovietdigits_prop { 6 }
 {
  \__sovietdigits_moveto:nn {1}{2}
  \__sovietdigits_lineto:nn {0}{1}
  \__sovietdigits_lineto:nn {0}{0}
  \__sovietdigits_lineto:nn {1}{0}
  \__sovietdigits_lineto:nn {1}{1}
  \__sovietdigits_lineto:nn {0}{1}
  \driver_draw_stroke:
 }
\prop_gput:Nnn \g_sovietdigits_prop { 7 }
 {
  \__sovietdigits_moveto:nn {0}{2}
  \__sovietdigits_lineto:nn {1}{2}
  \__sovietdigits_lineto:nn {0}{1}
  \__sovietdigits_lineto:nn {0}{0}
  \driver_draw_stroke:
 }
\prop_gput:Nnn \g_sovietdigits_prop { 8 }
 {
  \__sovietdigits_moveto:nn {0}{0}
  \__sovietdigits_lineto:nn {1}{0}
  \__sovietdigits_lineto:nn {1}{2}
  \__sovietdigits_lineto:nn {0}{2}
  \driver_draw_closestroke:
  \__sovietdigits_moveto:nn {0}{1}
  \__sovietdigits_lineto:nn {1}{1}
  \driver_draw_stroke:
 }  
\prop_gput:Nnn \g_sovietdigits_prop { 9 }
 {
  \__sovietdigits_moveto:nn {0}{0}
  \__sovietdigits_lineto:nn {1}{1}
  \__sovietdigits_lineto:nn {1}{2}
  \__sovietdigits_lineto:nn {0}{2}
  \__sovietdigits_lineto:nn {0}{1}
  \__sovietdigits_lineto:nn {1}{1}
  \driver_draw_stroke:
 }

\NewDocumentCommand{\postalcode}{O{}m}
 {
  \mbox
   {
    \keys_set:nn { sovietdigits } { #1 }
    \sovietdigits_print:n { #2 }
   }
 }

\dim_new:N \l_sovietdigits_width_dim
\seq_new:N \l__sovietdigits_number_seq
\box_new:N \l__sovietdigits_digit_box

\keys_define:nn { sovietdigits }
 {
  width .code:n =
   \str_case:nnF { #1 }
    {
      { font }
      {
       \hbox_set:Nn \l_tmpa_box { T }
       \dim_set:Nn \l_sovietdigits_width_dim { 0.5 \box_ht:N \l_tmpa_box }
      }
    }
    {
     \dim_set:Nn \l_sovietdigits_width_dim { #1 }
    },
  thickness .dim_set:N = \l_sovietdigits_thickness_dim,
  space     .dim_set:N = \l_sovietdigits_space_dim,
  cap       .tl_set:N  = \l_sovietdigits_cap_tl,
  join      .tl_set:N  = \l_sovietdigits_join_tl,
  width     .initial:n = 0.5cm,
  thickness .initial:n = 0.8pt,
  space     .initial:n = 0.25cm,
  cap       .initial:n = round,
  join      .initial:n = round,
 }

\cs_new_protected:Nn \sovietdigits_print:n
 {
  \dim_set_eq:NN \unitlength \l_sovietdigits_width_dim
  \driver_draw_linewidth:n { \l_sovietdigits_thickness_dim }
  \tl_map_inline:nn { #1 }
   {
    \seq_put_right:Nx \l__sovietdigits_number_seq
     {
      \__sovietdigits_digit:n { \prop_item:Nn \g_sovietdigits_prop { ##1 } }
     }
   }
  \seq_use:Nn \l__sovietdigits_number_seq { \hspace{\l_sovietdigits_space_dim} }
 }

\cs_new_protected:Nn \__sovietdigits_digit:n
 {
  \hbox_set:Nn \l__sovietdigits_digit_box
   {
    \use:c { driver_draw_join_ \l_sovietdigits_join_tl : }
    \use:c { driver_draw_cap_ \l_sovietdigits_cap_tl : }
    #1
   }
   \box_set_wd:Nn \l__sovietdigits_digit_box { \l_sovietdigits_width_dim }
   \box_set_ht:Nn \l__sovietdigits_digit_box { 2\l_sovietdigits_width_dim }
   \box_use:N \l__sovietdigits_digit_box
 }
% Syntactic sugar
\cs_new_protected:Nn \__sovietdigits_moveto:nn
 {
  \driver_draw_moveto:nn { #1 \l_sovietdigits_width_dim } { #2 \l_sovietdigits_width_dim }
 }
\cs_new_protected:Nn \__sovietdigits_lineto:nn
 {
  \driver_draw_lineto:nn { #1 \l_sovietdigits_width_dim } { #2 \l_sovietdigits_width_dim }
 }
\ExplSyntaxOff

\linespread{3}

\begin{document}

\postalcode{0123456789}

\postalcode{107714}

\postalcode[space=1cm]{107714}

\postalcode[thickness=1.5pt,width=0.25cm]{107714}

\postalcode[thickness=3pt,join=miter,cap=square]{107714}

\postalcode[thickness=3pt,join=bevel,cap=rectangle]{107714}

CODE: \postalcode[width=font]{107714}

\end{document}

enter image description here

19
  1. Look at the wikipedia file

  2. Upload the relevant part of the file (i.e., where the digits are, cf. below) at What Font Is, and identify the characters.

    enter image description here

  3. Browse the list of fonts proposed. AF ZIP code, pictured below, seems to be (almost) exactly what you're looking for:

    enter image description here

    but it is costly, so let's try with Stick Light (free for personal use) instead.

  4. Download the font, extract the Stick_V.2.ttf file, and create a tex document with the following in the folder where you extracted that file:

    \documentclass{article}
    \usepackage{fontspec}
    \setmainfont{Stick_V.2.ttf}
    
    \begin{document}
    0123456789 % No Math mode!!!
    \end{document} 
    

    Compile with XeLaTex, and you'll get enter image description here

Ok, 4 out of 10 matching exactly isn't exaclty a perfect score, but if the zip code you want to represent uses only 1, 2, 3 and 7, then you should be good ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.