Draw tally marks using PSTricks

with xelatex or lualatex. The font TallyMark is available from http://www.fonts2u.com/tally-mark.font

\documentclass{article}
\usepackage{fontspec}
\newfontface\Tally{TallyMark}
\newcounter{TallyTemp}
\def\tallymark#1{%
  \setcounter{TallyTemp}{#1}%
  \ifnum#1>5
    {\Tally E}\addtocounter{TallyTemp}{-5}%
  \else{\Tally%   
    \ifcase#1\or
    A\addtocounter{TallyTemp}{-1}\or
    B\addtocounter{TallyTemp}{-2}\or
    C\addtocounter{TallyTemp}{-3}\or
    D\addtocounter{TallyTemp}{-4}\or
    E\addtocounter{TallyTemp}{-5}%
    \fi}%
  \fi%
  \ifnum\theTallyTemp>0 \expandafter\tallymark\expandafter{\theTallyTemp}\fi
}

\begin{document}

\tallymark{0}
\tallymark{1}
\tallymark{2}
\tallymark{3}
\tallymark{4}
\tallymark{5}
\tallymark{14}

\end{document}

enter image description here

If you want to use PSTricks then define the commands \ONE, \TWO, ... and draw the lines. Really simple:

\documentclass{article}    
\usepackage{pstricks-add}    
\newcommand*\tallymarksOne{\pslineByHand(0,0)(0,1)}
\newcommand*\tallymarksTwo{\tallymarksOne\pslineByHand(2pt,0)(2pt,1)}
\newcommand*\tallymarksThree{\tallymarksTwo\pslineByHand(4pt,0)(4pt,1)}
\newcommand*\tallymarksFour{\tallymarksThree\pslineByHand(6pt,0)(6pt,1)}
\newcommand*\tallymarksFive{\tallymarksFour\pslineByHand(-17pt,0)(8pt,1)}

\newcounter{TallyTemp}
\def\tallymark#1{%
  \setcounter{TallyTemp}{#1}%
  \ifnum#1>5
    \tallymarksFive\kern14pt \addtocounter{TallyTemp}{-5}%
  \else%   
    \ifcase#1\or
    \tallymarksOne\kern3pt \addtocounter{TallyTemp}{-1}\or
    \tallymarksTwo\kern6pt \addtocounter{TallyTemp}{-2}\or
    \tallymarksThree\kern9pt \addtocounter{TallyTemp}{-3}\or
    \tallymarksFour\kern12pt \addtocounter{TallyTemp}{-4}\or
    \tallymarksFive\kern14pt \addtocounter{TallyTemp}{-5}%
    \fi%
  \fi%
  \ifnum\theTallyTemp>0 \expandafter\tallymark\expandafter{\theTallyTemp}\fi
  \vspace{1cm}
}

\begin{document}

\tallymark{0}\par
\tallymark{1}\par
\tallymark{2}\par
\tallymark{3}\par
\tallymark{4}\par
\tallymark{5}\par
\tallymark{14}

\end{document}

enter image description here


You need not any special font, any PSTricks, only \pdfliteral:

\newcount\tmpnum
\def\tallymarks#1{\leavevmode \lower1bp\vbox to9bp{}%
   \tmpnum=#1
   \loop \ifnum\tmpnum<5 \kern1bp \tallynum\tmpnum \else \tallyV \fi
         \advance\tmpnum by-5
         \ifnum\tmpnum>0 \repeat
}
\def\tallynum#1{\bgroup\tmpnum=#1\relax
   \loop \ifnum\tmpnum>0
         \kern1bp \tallyI \kern1bp
         \advance\tmpnum by-1
         \repeat
   \egroup
}
\def\tallyI{\pdfliteral{q .5 w 0 -1 m 0 8 l S Q}}
\def\tallyV{\kern1bp\pdfliteral{q .5 w -1 0 m 9 7 l S Q}\tallynum4\kern1bp }

test1: \tallymarks{3}

test2: \tallymarks{17}

\bye

tally


Here is an expl3 approach:

\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn

\int_new:N \snehal_tally_full_int
\int_new:N \snehal_tally_partial_int
\box_new:N \snehal_tally_slash_box

\cs_generate_variant:Nn \int_step_inline:nnnn { nnVn }

\cs_new_protected:Npn \snehal_tally_mark:n #1
 {
  \int_set:Nn \snehal_tally_full_int { \int_div_truncate:nn { #1 } { 5 } }
  \int_set:Nn \snehal_tally_partial_int { \int_mod:nn { #1 } { 5 } }

  \int_step_inline:nnVn { 1 } { 1 } \snehal_tally_full_int
   {
    \hbox_set:Nn \snehal_tally_slash_box { $\big|$ }
    \box_rotate:Nn \snehal_tally_slash_box { -70 }
    \ensuremath
     {
      \ooalign
       {
        $||||$ \tex_cr:D
        \hidewidth \tex_raise:D .7ex \box_use:N \snehal_tally_slash_box \hidewidth
       }
     }~
   }
  \ensuremath
   {
    \int_step_inline:nnVn { 1 } { 1 } \snehal_tally_partial_int { | }
   }
 }

\NewDocumentCommand \tallymark { m }
 {
  \snehal_tally_mark:n { #1 }
 }

\ExplSyntaxOff
\begin{document}

\tallymark{1001}

\end{document}

enter image description here

Tags:

Pstricks