TeX - LaTeX Asked by Svend Tveskæg on February 8, 2021
Inspired by Paulo Cereda’s question here, I would like to draw tally marks using PSTricks (or TikZ, if no one can help with PSTricks).
I have no idea how to start, so I cannot even present a try myself. :(
(This is not good, I know!)
What I would like to have, is a command like tallymarks
;
tallymarks{1}
tallymarks{2}
...
tallymarks{10}
and get an output like the following:
without the table and the arabic numerals, i.e., only the tally marks themselves.
Update 1
Inspired by Herbert’s idea, here is an attempt to use PSTricks.
documentclass{article}
usepackage{pstricks-add}
newcommand*{tallymarksOne}{
pslineByHand(0,0)(0,1)
}
newcommand*{tallymarksTwo}{
pslineByHand(0,0)(0,1)
pslineByHand(0.25,0)(0.25,1)
}
newcommand*{tallymarksThree}{
pslineByHand(0,0)(0,1)
pslineByHand(0.25,0)(0.25,1)
pslineByHand(0.5,0)(0.5,1)
}
newcommand*{tallymarksFour}{
pslineByHand(0,0)(0,1)
pslineByHand(0.25,0)(0.25,1)
pslineByHand(0.5,0)(0.5,1)
pslineByHand(0.75,0)(0.75,1)
}
newcommand*{tallymarksFive}{
pslineByHand(0,0)(0,1)
pslineByHand(0.25,0)(0.25,1)
pslineByHand(0.5,0)(0.5,1)
pslineByHand(0.75,0)(0.75,1)
pslineByHand(-0.75,0)(1,1)
}
newcounter{TallyTemp}
deftallymark#1{%
setcounter{TallyTemp}{#1}%
ifnum#1>5
{Tally E}addtocounter{TallyTemp}{-5}%
else{Tally%
ifcase#1or
tallymarksOneaddtocounter{TallyTemp}{-1}or
tallymarksTwoaddtocounter{TallyTemp}{-2}or
tallymarksThreeaddtocounter{TallyTemp}{-3}or
tallymarksFouraddtocounter{TallyTemp}{-4}or
tallymarksFiveaddtocounter{TallyTemp}{-5}%
fi}%
fi%
ifnumtheTallyTemp>0 expandaftertallymarkexpandafter{theTallyTemp}fi
}
begin{document}
tallymark{0}
tallymark{1}
tallymark{2}
tallymark{3}
tallymark{4}
tallymark{5}
tallymark{14}
end{document}
When compiling, I get an error:
! Undefined control sequence.
tallymark ...ounter {TallyTemp}{-5}else {Tally
ifcase #1or tallymarksO...
l.50 tallymark{0}
Update 2
Garbage Coloector’s hinted me to the following in the PSTricks manual, but the code won’t compile:
documentclass{article}
usepackage{pstricks-add}
defPstLineFuzzy[#1](#2,#3)(#4,#5)(#6,#7)(#8,#9){%
pscurve[#1](! #2 rand 101 mod 1000 div sub
#3 rand 101 mod 1000 div sub)
(! #4 rand 101 mod 1000 div sub
#5 rand 101 mod 1000 div sub)
(! #6 rand 101 mod 1000 div sub
#7 rand 101 mod 1000 div sub)
(! #8 rand 101 mod 1000 div sub
#9 rand 101 mod 1000 div sub)}
defPstSticks#1{%
multido{iStick=0+1,nXA=0.1+0.1,nXB=-0.5+0.1,
nXC=-0.35+0.10,nXD=-0.15+0.10}{#1}{%
pst@cnta=iStick
pst@cnth=iStick
dividepst@cnth by 5
multiplypst@cnth by 5
ifnumiStick>0relax
ifnumpst@cnta=pst@cnth
PstLineFuzzy[linecolor=red]%
(nXB,0.2)(nXC,0.4)(nXD,0.6)(nXA,0.8)
hbox to 0.2psxunit{}
fi
fi
PstLineFuzzy[](nXA,0.1)(nXA,0.4)(nXA,0.7)(nXA,1)}}
begin{document}
psset{xunit=0.8,yunit=0.3}%
begin{tabular}{|l|r|p{5.5cm}|}
hline
Linux
& 27 & PstSticks{27} \ hline
Mac OS X
& 14 & PstSticks{14} \ hline
Windows XP & 43 & PstSticks{43} \ hline
end{tabular}
end{document}
The error is
! Undefined control sequence.
<inserted text> pst
@cnta=iStick pst @cnth=iStick divide pst @cnth by ...
l.38 & 27 & PstSticks{27}
\ hline
Simplest way I found was to use usepackage[misc]{ifsym}
and then use commands StrokeFive
, StrokeFour
, StrokeOne
, etc. accordingly
Answered by Avirup Das on February 8, 2021
You mentioned that a TikZ solution might be acceptable (if Herbert's excellent answer wasn't present). Also, I prefer the "box method" (I din't know if it has a proper name) for such counting tasks, so I did this here. I don't know if the lines ought to be jittery, it could be added, but so far I did not. The command does not break across lines.
documentclass[12pt]{article}
usepackage{tikz}
usepackage{xifthen}
begin{document}
newcommand{tally}[1]
{ begin{tikzpicture}[scale=0.5]
pgfmathtruncatemacro{Rest}{#1}
xdefGlobalRest{Rest}
coordinate (temp);
whiledo {GlobalRest > 9}
{ fill (temp) ++ (0.2,0) circle (0.04) ++ (0.5,0) circle (0.04) ++ (0,0.5) circle (0.04) ++ (-0.5,0) circle (0.04);
draw[line cap=round] (temp) ++ (0.2,0) rectangle ++ (0.5,0.5) -- ++ (-0.5,-0.5) ++ (0.5,0) coordinate (temp) -- ++ (-0.5,0.5);
pgfmathtruncatemacro{Rest}{GlobalRest-10}
%node[below] at (temp) {Rest};
xdefGlobalRest{Rest}
}
ifthenelse{GlobalRest > 0}
{ fill (temp) ++ (0.2,0) circle (0.04);}{}
ifthenelse{GlobalRest > 1}
{ fill (temp) ++ (0.7,0) circle (0.04);}{}
ifthenelse{GlobalRest > 2}
{ fill (temp) ++ (0.7,0.5) circle (0.04);}{}
ifthenelse{GlobalRest > 3}
{ fill (temp) ++ (0.2,0.5) circle (0.04);}{}
ifthenelse{GlobalRest > 4}
{ draw (temp) ++ (0.2,0) -- ++ (0.5,0);}{}
ifthenelse{GlobalRest > 5}
{ draw (temp) ++ (0.7,0) -- ++ (0,0.5);}{}
ifthenelse{GlobalRest > 6}
{ draw (temp) ++ (0.7,0.5) -- ++ (-0.5,0);}{}
ifthenelse{GlobalRest > 7}
{ draw (temp) ++ (0.2,0.5) -- ++ (0,-0.5);}{}
ifthenelse{GlobalRest > 8}
{ draw (temp) ++ (0.2,0) -- ++ (0.5,0.5);}{}
end{tikzpicture}
}
foreach T in {11,...,20,37,49,54,62,89,243}
{ Lorem ipsum: tally{T}
}
end{document}
Answered by Tom Bombadil on February 8, 2021
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}
Answered by Henri Menke on February 8, 2021
You need not any special font, any PSTricks, only pdfliteral
:
newcounttmpnum
deftallymarks#1{leavevmode lower1bpvbox to9bp{}%
tmpnum=#1
loop ifnumtmpnum<5 kern1bp tallynumtmpnum else tallyV fi
advancetmpnum by-5
ifnumtmpnum>0 repeat
}
deftallynum#1{bgrouptmpnum=#1relax
loop ifnumtmpnum>0
kern1bp tallyI kern1bp
advancetmpnum by-1
repeat
egroup
}
deftallyI{pdfliteral{q .5 w 0 -1 m 0 8 l S Q}}
deftallyV{kern1bppdfliteral{q .5 w -1 0 m 9 7 l S Q}tallynum4kern1bp }
test1: tallymarks{3}
test2: tallymarks{17}
bye
Answered by wipet on February 8, 2021
with xelatex
or lualatex
. The font TallyMark is available from http://www.fonts2u.com/tally-mark.font
documentclass{article}
usepackage{fontspec}
newfontfaceTally{TallyMark}
newcounter{TallyTemp}
deftallymark#1{%
setcounter{TallyTemp}{#1}%
ifnum#1>5
{Tally E}addtocounter{TallyTemp}{-5}%
else{Tally%
ifcase#1or
Aaddtocounter{TallyTemp}{-1}or
Baddtocounter{TallyTemp}{-2}or
Caddtocounter{TallyTemp}{-3}or
Daddtocounter{TallyTemp}{-4}or
Eaddtocounter{TallyTemp}{-5}%
fi}%
fi%
ifnumtheTallyTemp>0 expandaftertallymarkexpandafter{theTallyTemp}fi
}
begin{document}
tallymark{0}
tallymark{1}
tallymark{2}
tallymark{3}
tallymark{4}
tallymark{5}
tallymark{14}
end{document}
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{tallymarksOnepslineByHand(2pt,0)(2pt,1)}
newcommand*tallymarksThree{tallymarksTwopslineByHand(4pt,0)(4pt,1)}
newcommand*tallymarksFour{tallymarksThreepslineByHand(6pt,0)(6pt,1)}
newcommand*tallymarksFive{tallymarksFourpslineByHand(-17pt,0)(8pt,1)}
newcounter{TallyTemp}
deftallymark#1{%
setcounter{TallyTemp}{#1}%
ifnum#1>5
tallymarksFivekern14pt addtocounter{TallyTemp}{-5}%
else%
ifcase#1or
tallymarksOnekern3pt addtocounter{TallyTemp}{-1}or
tallymarksTwokern6pt addtocounter{TallyTemp}{-2}or
tallymarksThreekern9pt addtocounter{TallyTemp}{-3}or
tallymarksFourkern12pt addtocounter{TallyTemp}{-4}or
tallymarksFivekern14pt addtocounter{TallyTemp}{-5}%
fi%
fi%
ifnumtheTallyTemp>0 expandaftertallymarkexpandafter{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}
Answered by user2478 on February 8, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP