4 tools/2793: calc extensions
7 Add commands \widthof etc.
12 \documentclass{article}
14 \AUTHOR{Donald Arseneau}
15 \PACKAGE{1998/07/07 v4.1b Infix arithmetic (KKT,FJ)}
23 \newcommand\testsetlength[2]{\setlength#1{#2}\typeout{\the#1}}
24 \newcommand\testaddtolength[2]{\addtolength#1{#2}\typeout{\the#1}}
25 \newcommand\testsetcounter[2]{\setcounter{#1}{#2}\typeout{\the\value{#1}}}
26 \newcommand\testaddtocounter[2]{\addtocounter{#1}{#2}\typeout{\the\value{#1}}}
30 \testsetlength\lengthA{ 5pt }
32 % subtraction and addition
33 \testsetlength\lengthB{ 5pt - 2pt }
35 \testsetlength\lengthA{ 5pt + - \lengthB }
37 % multiplication and division
38 \testsetlength\lengthA{ 5pt * 7 }
40 \testsetlength\lengthA{ 5pt / 7 }
42 \testsetlength\lengthA{ 5pt + 5pt * 7 }
45 \testsetlength\lengthA{ ( 5pt - 1pt ) * 7 }
48 \testsetlength\lengthA{
49 5pt + 5pt * \ratio{ 1.0pt * \real{1.0} }{ 5pt }
53 \testsetlength\lengthA{ 5pt + 5pt * \real{.2} }
55 % a few hidden expressions
56 \def\hiddenexpr{ 5pt + 5pt * 7 }
57 \testsetlength\lengthA{ \hiddenexpr }
59 \def\hiddenexpr{ \widthof{\rule{10pt}{10pt}} * 7 }
60 \testsetlength\lengthA{\hiddenexpr}
62 \def\hiddenexpr{\widthof{%
63 \rule{10pt/\ratio{2000pt}{1000pt}*2}{10pt*\ratio{1pt}{2pt}}}* 7 }
64 \testsetlength\lengthA{\hiddenexpr}
68 \testsetlength\lengthA{4pt \hiddenplus (\hiddenminus 5pt)}
72 \testsetlength\lengthA{\widthof{\rule[-4pt]{10pt}{10pt}}}
74 \testsetlength\lengthA{\heightof{\rule[-4pt]{10pt}{10pt}}}
76 \testsetlength\lengthA{\depthof{\rule[-4pt]{10pt}{10pt}}}
78 \testsetlength\lengthA{\widthof{\rule[-4pt]{10pt}{10pt}}
79 -\heightof{\rule[-4pt]{10pt}{10pt}}
80 -\depthof{\rule[-4pt]{10pt}{10pt}}}
82 \testsetlength\lengthA{\widthof{\rule{\heightof{\rule{11pt}{2pt}}}{10pt}}}
84 \testaddtolength\lengthA{\widthof{\rule{\heightof{\rule{11pt}{2pt}}}{10pt}}}
87 \testsetlength\lengthA{4pt+2ptt}
91 \testsetcounter{countA}{4}
93 \testsetcounter{countB}{-4+8}
95 \testsetcounter{countB}{(-4+8)*-2}
98 \testsetcounter{countA}{\value{countB}/-3}
100 \testsetcounter{countA}{\value{countB}/\real{.2}}
102 \testsetcounter{countA}{\value{countA}*\real{-.5}}
104 \testaddtocounter{countA}{\value{countA}*\real{-.5}}